Views
No views yet
facebook/nllb-200-3.3B converted to CTranslate2 with int8 quantization
for fast CPU inference.model.bin — quantized weights (~3.3 GB)config.json — CT2 model configshared_vocabulary.json — shared NLLB vocabularytokenizer.json — fast tokenizer1import ctranslate2
2from tokenizers import Tokenizer
3from huggingface_hub import snapshot_download
4
5model_dir = snapshot_download("Napron/nllb-200-3.3B-ct2-int8")
6translator = ctranslate2.Translator(model_dir, device="cpu", compute_type="int8")
7tokenizer = Tokenizer.from_file(f"{model_dir}/tokenizer.json")
8
9src_lang, tgt_lang = "eng_Latn", "fra_Latn"
10text = "Hello, how are you?"
11source_tokens = tokenizer.encode(f"{src_lang} {text}").tokens
12result = translator.translate_batch(
13 [source_tokens],
14 target_prefix=[[tgt_lang]],
15 beam_size=4,
16)
17out_tokens = result[0].hypotheses[0][1:] # drop the tgt_lang prefix token
18print(tokenizer.decode(tokenizer.token_to_id_batch(out_tokens) if False else
19 [tokenizer.token_to_id(t) for t in out_tokens],
20 skip_special_tokens=True))