Views
No views yet
1import ctranslate2
2from huggingface_hub import snapshot_download
3from transformers import AutoTokenizer
4
5path = snapshot_download("olob0/madlad400-3b-mt-ct2-int8_float16")
6tokenizer = AutoTokenizer.from_pretrained(path)
7translator = ctranslate2.Translator(path, device="cuda", compute_type="int8_float16")
8
9tokens = tokenizer.convert_ids_to_tokens(tokenizer("<2en> Bom dia.").input_ids)
10result = translator.translate_batch([tokens])
11print(tokenizer.decode(tokenizer.convert_tokens_to_ids(result[0].hypotheses[0])))<2xx> token at the front of the source text. Put it in the
string and let the tokenizer handle it. Prepending the bare token to the token list instead loses
the word boundary piece in front of it, and the translation comes back mangled with no error.ct2-transformers-converter --model google/madlad400-3b-mt \
--quantization int8_float16 --output_dir madlad400-3b-mt-ct2-int8_float16 \
--copy_files tokenizer.json tokenizer_config.json special_tokens_map.json spiece.model added_tokens.json