-
Notifications
You must be signed in to change notification settings - Fork 28.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Phi-3-mini-128k-instruct] Difference of encodings for Slow and Fast Tokenizer #35973
Comments
Hey @GKIBMNY try using the following script, Try setting legacy=True when loading the tokenizer: from transformers import AutoTokenizer
model_name = "microsoft/Phi-3-mini-128k-instruct"
text = "<|user|>\n I am good <|end|>\n<|endoftext|>"
# Using Fast Tokenizer
fast_tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
fast_ids = fast_tokenizer(text).input_ids
print("🔵 Fast Tokenizer IDs:", fast_ids)
print("🔵 Fast Tokenizer Tokens:", fast_tokenizer.convert_ids_to_tokens(fast_ids))
print("🔵 Fast Tokenizer Encoded:", fast_tokenizer.encode(text))
# Using Slow Tokenizer without legacy=True
slow_tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False, legacy=False)
slow_ids = slow_tokenizer(text).input_ids
print("🟢 Slow Tokenizer (legacy=False) IDs:", slow_ids)
print("🟢 Slow Tokenizer (legacy=False) Tokens:", slow_tokenizer.convert_ids_to_tokens(slow_ids))
print("🟢 Slow Tokenizer (legacy=False) Encoded:", slow_tokenizer.encode(text))
# Using Slow Tokenizer with legacy=True
slow_tokenizer_legacy = AutoTokenizer.from_pretrained(model_name, use_fast=False, legacy=True)
slow_legacy_ids = slow_tokenizer_legacy(text).input_ids
print("🟠 Slow Tokenizer (legacy=True) IDs:", slow_legacy_ids)
print("🟠 Slow Tokenizer (legacy=True) Tokens:", slow_tokenizer_legacy.convert_ids_to_tokens(slow_legacy_ids))
print("🟠 Slow Tokenizer (legacy=True) Encoded:", slow_tokenizer_legacy.encode(text)) Output: |
Yep! |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
System Info
transformers
version: 4.46.2Who can help?
@ArthurZucker
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('microsoft/Phi-3-mini-128k-instruct', use_fast=True)
text = '<|user|>\n I am good <|end|>\n<|endoftext|>'
ids=tokenizer(text).input_ids
print(ids)
print(tokenizer.convert_ids_to_tokens(ids))
print(tokenizer.encode(text))
tokenizer = AutoTokenizer.from_pretrained('microsoft/Phi-3-mini-128k-instruct', use_fast=False)
ids = tokenizer(text).input_ids
print(ids)
print(tokenizer.convert_ids_to_tokens(ids))
print(tokenizer.encode(text))
Expected behavior
In expected case, both slow and fast tokenizer should return the same IDs
The text was updated successfully, but these errors were encountered: