Created
May 16, 2024 14:37
-
-
Save Norod/eb91f888e3e11644d10f67740a159948 to your computer and use it in GitHub Desktop.
Prompt length: 374 (Hebrew: Current wikipedia abstract for the term "Cat") across several tokenizers
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 AutoTokenizer | |
from transformers import LlamaTokenizerFast | |
tokenizer_grok = LlamaTokenizerFast.from_pretrained('Xenova/grok-1-tokenizer') | |
tokenizer_gemma = AutoTokenizer.from_pretrained("google/gemma-7b-it") | |
tokenizer_aya101 = AutoTokenizer.from_pretrained("CohereForAI/aya-101") | |
tokenizer_gpt2 = AutoTokenizer.from_pretrained("gpt2") | |
# prompt_text='''מודל ראשון בגודל 6-מיליארד פרמטרים מתאמן כרגע על חלק מהדאטסטים שהגבתם, עכשיו כשהמודל על האש אני אתפנה לענות לכולם. מתנצל על העיכוב, קיבלתי המון הודעות ולא ציפיתי לכזו הענות, אתם אדירים! | |
# שלב הבא: להרכיב דאטהסט אחד ענק מכל הרעיונות והלינקים שצירפתם בשביל האימון המרכזי.''' | |
prompt_text = '''חתול הבית (שם מדעי: Felis silvestris catus) הוא יונק טורף מבוית, מהסוג חתול ממשפחת החתוליים. החתול נפוץ בכל יבשות העולם מלבד אנטארקטיקה. משערים כי מוצאו מחתול הבר. החתול הוא טורף לילי הצד מכרסמים, ציפורים ודגים. נכון ל-2009, החתול הוא חיית המחמד הנפוצה ביותר בעולם, ומספר החתולים הביתיים נאמד בכ-600 מיליון.[1] החתול חי בדרך כלל בבדידות, למעט אינטראקציה מזדמנת עם בני מינו. ''' | |
def test_tokenizer(tokenizer, prompt_text): | |
encoded_prompt = tokenizer.encode(prompt_text, add_special_tokens=False, return_tensors="pt") | |
num_of_tokenz = encoded_prompt.size()[-1] | |
return num_of_tokenz | |
prompt_length = len(prompt_text) | |
print(f'\nPrompt length: {prompt_length} \n') | |
print(f'Grok tokenizer: {test_tokenizer(tokenizer_grok, prompt_text)}') | |
print(f'Gemma tokenizer: {test_tokenizer(tokenizer_gemma, prompt_text)}') | |
print(f'Aya-101 tokenizer: {test_tokenizer(tokenizer_aya101, prompt_text)}') | |
print(f'GPT-2 tokenizer: {test_tokenizer(tokenizer_gpt2, prompt_text)}') | |
####################### | |
# Prompt length: 374 | |
# Grok tokenizer: 376 | |
# Gemma tokenizer: 167 | |
# Aya-101 tokenizer: 140 | |
# GPT-2 tokenizer: 415 | |
####################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment