Spaces:
Running
Running
anyantudre
commited on
Commit
•
ffa8d95
1
Parent(s):
db3d44a
Solving the issue "AttributeError: 'NllbTokenizerFast' object has no attribute 'lang_code_to_id'"
Browse filesWhen trying to do a simple translation from french to Mooré, I encountered this error.
![Capture d’écran (9).png](https://cdn-uploads.huggingface.co/production/uploads/65fb92d68d815d64d9b04d58/qhdNMJ9r7CBBt0KYLryFf.png)
This seems to be related to an recent update from transformers library. To be more precise they removed the "lang_code_to_id" attribute from NllbTokenize and NllbTokenizerFast classes.
To solve the issue, I just replaced the "lang_code_to_id" attribute by "convert_tokens_to_ids()" method.
Hope this help to keep your great space updated.
- src/translation.py +1 -1
src/translation.py
CHANGED
@@ -94,7 +94,7 @@ def translate_facebook(s:str, src_iso:str, dest_iso:str)-> str:
|
|
94 |
|
95 |
# Inference
|
96 |
encoded = tokenizer(s, return_tensors="pt")
|
97 |
-
translated_tokens = model.generate(**encoded, forced_bos_token_id=tokenizer.
|
98 |
translation = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
99 |
|
100 |
return translation
|
|
|
94 |
|
95 |
# Inference
|
96 |
encoded = tokenizer(s, return_tensors="pt")
|
97 |
+
translated_tokens = model.generate(**encoded, forced_bos_token_id=tokenizer.convert_tokens_to_ids(f"{dest_iso}_Latn"), max_length=30)
|
98 |
translation = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
99 |
|
100 |
return translation
|