khof312 anyantudre commited on
Commit
0b61adc
1 Parent(s): db3d44a

Solving the issue "AttributeError: 'NllbTokenizerFast' object has no attribute 'lang_code_to_id'" (#1)

Browse files

- Solving the issue "AttributeError: 'NllbTokenizerFast' object has no attribute 'lang_code_to_id'" (ffa8d951d25853987ad1da075ead6174d7fbd155)


Co-authored-by: Wendyellé Abubakrh Alban NYANTUDRE <[email protected]>

Files changed (1) hide show
  1. 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.lang_code_to_id[f"{dest_iso}_Latn"], max_length=30)
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