Last active
July 20, 2023 14:16
-
-
Save y-lan/1d7574ba89f158fc9df36f25117671e8 to your computer and use it in GitHub Desktop.
Count Llama Tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import LlamaTokenizer | |
tokenizer = LlamaTokenizer.from_pretrained('decapoda-research/llama-7b-hf') | |
def count(text): | |
return len(tokenizer(text)['input_ids']) | |
def parallel_count(texts): | |
from joblib import Parallel, delayed | |
results = Parallel(n_jobs=-1)(delayed(count)(text) for text in texts) | |
return sum(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment