Skip to content
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

incompatibility issue #7

Open
sancelot opened this issue Nov 21, 2023 · 1 comment
Open

incompatibility issue #7

sancelot opened this issue Nov 21, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sancelot
Copy link

Hi !

I have compatibility issues either with transformers or pytorch I think.

I Installed it with pip

from nmtscore import NMTScorer
scorer = NMTScorer()
scorer.score("This is a sentence.", "This is another sentence.")

The tokenizer class you load from this checkpoint is not the same type as the class this function is called from. It may result in unexpected tokenization.
The tokenizer class you load from this checkpoint is 'M2M100Tokenizer'.
The class this function is called from is 'SMALL100Tokenizer'.
Traceback (most recent call last):
File "/home/retd/ia/traductions/nmtscore_test.py", line 3, in
scorer = NMTScorer()
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/scorer.py", line 21, in init
self.model = load_translation_model(model, **model_kwargs)
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/init.py", line 231, in load_translation_model
translation_model = SMALL100Model(**kwargs)
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/small100.py", line 15, in init
super().init(model_name_or_path, device)
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/m2m100.py", line 30, in init
self.tokenizer = self._load_tokenizer()
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/small100.py", line 23, in _load_tokenizer
return SMALL100Tokenizer.from_pretrained(self.model_name_or_path)
File "/home/retd/scoring/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2024, in from_pretrained
return cls._from_pretrained(
File "/home/retd/scoring/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2256, in _from_pretrained
tokenizer = cls(*init_inputs, **init_kwargs)
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/tokenization_small100.py", line 148, in init
super().init(
File "/home/retd/scoring/lib/python3.10/site-packages/transformers/tokenization_utils.py", line 367, in init
self._add_tokens(
File "/home/retd/scoring/lib/python3.10/site-packages/transformers/tokenization_utils.py", line 467, in _add_tokens
current_vocab = self.get_vocab().copy()
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/tokenization_small100.py", line 270, in get_vocab
vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
File "/home/retd/scoring/lib/python3.10/site-packages/nmtscore/models/tokenization_small100.py", line 183, in vocab_size
return len(self.encoder) + len(self.lang_token_to_id) + self.num_madeup_words
AttributeError: 'SMALL100Tokenizer' object has no attribute 'encoder'. Did you mean: 'encode'?

@jvamvas jvamvas self-assigned this Nov 21, 2023
@jvamvas jvamvas added the bug Something isn't working label Nov 21, 2023
@jvamvas
Copy link
Member

jvamvas commented Nov 21, 2023

Thanks for reporting.
This is caused by https://huggingface.co/alirezamsh/small100/discussions/7

A workaround is to use an older version of transformers:

The issue seems to arise due to the transformers library update for version 4.34, which heavily influences the tokenizer workflow. Hence, tokenization_small100.py only functions with transformer < 4.34 at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants