From 07128d0c3a13882e06fe2152a8f44a27e4426bc8 Mon Sep 17 00:00:00 2001 From: blackmesataiwan <20988581+blackmesataiwan@users.noreply.github.com> Date: Fri, 19 Jul 2024 21:22:42 +0800 Subject: [PATCH] Fix "'NllbTokenizerFast' object has no attribute 'lang_code_to_id'" issue. https://github.com/huggingface/transformers/issues/31348 --- plugins/plugin_fb_nllb_translate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/plugin_fb_nllb_translate.py b/plugins/plugin_fb_nllb_translate.py index 45da502..bbd11e9 100644 --- a/plugins/plugin_fb_nllb_translate.py +++ b/plugins/plugin_fb_nllb_translate.py @@ -297,7 +297,7 @@ def translate(core:OneRingCore, text:str, from_lang:str = "", to_lang:str = "", inputs = tokenizer_from(text, return_tensors="pt").to(to_device) translated_tokens = model.generate( - **inputs, forced_bos_token_id=tokenizer_from.lang_code_to_id[to_lang_tr], max_length=int(len(text)*5) + **inputs, forced_bos_token_id=tokenizer_from.convert_tokens_to_ids(to_lang_tr), max_length=int(len(text)*5) ) res = tokenizer_from.batch_decode(translated_tokens, skip_special_tokens=True)[0]