Downloads · 30 days
22
13% of all-time downloads
Grushashunyalabsai/nllb-v4-multilang-ct2-int8
nllb-v4-multilang-ct2-int8 is a translation model from Grushashunyalabsai. Use it when you need text moved from one language to another. It is set up for ctranslate2.
CTranslate2 INT8 quantized NLLB model for fast multilingual translation across 17 languages. Optimized for production deployment with low memory footprint and high throughput.
Downloads · 30 days
22
13% of all-time downloads
All-time downloads
176
Public
Repo size
1.4 GB
Likes
0
Public
Click a slice to open those files.
.bin1.4 GB · 97%
From the Hugging Face model README
CTranslate2 INT8 quantized NLLB model for fast multilingual translation across 17 languages. Optimized for production deployment with low memory footprint and high throughput.
| Language | ISO Code | NLLB Code |
|---|---|---|
| English | en | eng_Latn |
| Chinese (Simplified) | zh | zho_Hans |
| French | fr | fra_Latn |
| Portuguese | pt | por_Latn |
| Korean | ko | kor_Hang |
| Vietnamese | vi | vie_Latn |
| Hindi | hi | hin_Deva |
| Thai | th | tha_Thai |
| Indonesian | id | ind_Latn |
| Tamil | ta | tam_Taml |
| Urdu | ur | urd_Arab |
| Nepali | ne | npi_Deva |
| Uzbek | uz | uzn_Latn |
| Mongolian | mn | khk_Cyrl |
| Sinhalese | si | sin_Sinh |
| Burmese | my | mya_Mymr |
| Japanese | ja | jpn_Jpan |
pip install ctranslate2 transformers sentencepiece
import ctranslate2
from transformers import AutoTokenizer
MODEL_PATH = "Grushashunyalabsai/nllb-v4-multilang-ct2-int8"
# Load model and tokenizer
translator = ctranslate2.Translator(MODEL_PATH, device="cuda", compute_type="int8")
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
def translate(text, src_lang, tgt_lang):
"""Translate text between any of the 17 supported languages."""
tokenizer.src_lang = src_lang
input_ids = tokenizer.encode(text)
source_tokens = tokenizer.convert_ids_to_tokens(input_ids)
results = translator.translate_batch(
[source_tokens],
target_prefix=[[tgt_lang]],
beam_size=2,
repetition_penalty=1.1,
max_decoding_length=512,
)
target_tokens = results[0].hypotheses[0]
output_text = tokenizer.decode(
tokenizer.convert_tokens_to_ids(target_tokens),
skip_special_tokens=True,
)
return output_text
# Examples
print(translate("Hello, how are you?", "eng_Latn", "jpn_Jpan"))
# → こんにちは、お元気ですか?
print(translate("こんにちは、今日はお元気ですか?", "jpn_Jpan", "eng_Latn"))
# → Hello, are you feeling well today?
print(translate("नमस्ते, आज आप कैसे हैं?", "hin_Deva", "eng_Latn"))
# → Hello, how are you today?
print(translate("안녕하세요, 오늘 기분이 어떠세요?", "kor_Hang", "eng_Latn"))
# → Hello, how are you feeling today?
texts = ["Bonjour le monde", "Olá, como vai?", "สวัสดีครับ"]
src_langs = ["fra_Latn", "por_Latn", "tha_Thai"]
tgt_lang = "eng_Latn"
tokenizer.src_lang = src_langs[0] # Set for first; re-set per text if different
all_tokens = []
for text, src in zip(texts, src_langs):
tokenizer.src_lang = src
ids = tokenizer.encode(text)
all_tokens.append(tokenizer.convert_ids_to_tokens(ids))
results = translator.translate_batch(
all_tokens,
target_prefix=[[tgt_lang]] * len(texts),
beam_size=2,
max_decoding_length=512,
)
for r in results:
tokens = r.hypotheses[0]
print(tokenizer.decode(tokenizer.convert_tokens_to_ids(tokens), skip_special_tokens=True))
model.bin — CTranslate2 INT8 model weightssentencepiece.bpe.model — SentencePiece BPE tokenizershared_vocabulary.json — Shared vocabularytokenizer.json — Fast tokenizertokenizer_config.json — Tokenizer configurationconfig.json — Model configuration