Instructions to use Ming224/nllb-600m-cantonese with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ming224/nllb-600m-cantonese with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "translation" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("translation", model="Ming224/nllb-600m-cantonese")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("Ming224/nllb-600m-cantonese") model = AutoModelForSeq2SeqLM.from_pretrained("Ming224/nllb-600m-cantonese", device_map="auto") - Notebooks
- Google Colab
- Kaggle
NLLB-200 600M fine-tuned for Cantonese โ written Chinese
facebook/nllb-200-distilled-600M fine-tuned to translate
colloquial Hong Kong Cantonese (yue_Hant) into standard written Chinese (zho_Hant), e.g.
ใไฝขๅบๆบ่งๅ้
้ผ็ฃไน้่ฟๅทฅ๏ผๅไฟๅฅฝๆนไพฟใ โ ใไปๅจๆบ่งๅ้
้ผ็ฃไน้ไธ็ญ๏ผไธๆฏๅพๆนไพฟใ.
It is the translation stage of a Cantonese subtitle generator (speech recognition with
Ming224/whisper-small-cantonese-ct2, then this model).
็ฒค่ฏญ โ ไนฆ้ขไธญๆ็ฟป่ฏๆจกๅ๏ผๅจ็ฒค่ฏญ-ไนฆ้ขไธญๆๅนณ่ก่ฏญๆไธๅพฎ่ฐ็ NLLB-200 600M๏ผๅนถ็ป่ฏ่กจ่กฅไธไบ 2,629 ไธชๅๆจกๅ็ผบๅฐ็ๅธธ็จๆฑๅญ ๏ผ็ใ็ฒฅใ่ใ้ผใ็ญฒใไฝฌโฆโฆ๏ผใ
Hugging Face transformers format (fp16). A CTranslate2 int8 conversion for fast CPU inference is at Ming224/nllb-600m-cantonese-ct2.
Built as a course project for IERG4320 / IEMS5726A Data Science in Practice (CUHK, 2026โ27 Term 1).
Usage
Use src_lang="yue_Hant" and force the target language token zho_Hant (traditional written Chinese; convert to
simplified with OpenCC t2s if needed). The model can still translate into English with eng_Latn โ in our
subtitle app this works better than the original NLLB, although English was not part of the fine-tuning data.
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
repo = "Ming224/nllb-600m-cantonese"
tok = AutoTokenizer.from_pretrained(repo, src_lang="yue_Hant") # must be THIS repo's tokenizer (extended vocabulary)
model = AutoModelForSeq2SeqLM.from_pretrained(repo)
enc = tok("ๆๅ่ฝๆฅๅป่็ฃ้ฃ็็ฒฅๅฆ", return_tensors="pt")
out = model.generate(**enc, forced_bos_token_id=tok.convert_tokens_to_ids("zho_Hant"), num_beams=4)
print(tok.decode(out[0], skip_special_tokens=True)) # ๆๅๆๅคฉๅป่็ฃๅซ็็ฒฅๅง
Extended vocabulary
The original NLLB-200 vocabulary has no entry for many common Hong Kong characters, so they become <unk>
(38% of our speech-recognition outputs contained at least one). We added 2,629 characters
(vocabulary 256,204 โ 258,833), written directly into the BPE
vocabulary with consecutive ids so that segmentation of existing text is unchanged.
New embeddings (shared by the encoder, decoder and output layer):
- 184 characters copied from a traditional/simplified variant already in the vocabulary
- the rest initialised from data: for each new character, the mean final decoder state at the positions where it is the training target, minus the mean decoder state over all positions (otherwise the shared component makes new characters win everywhere), scaled to 0.4 ร the typical spread of Han-character embeddings, added to the mean Han embedding
- original embedding rows were frozen (gradients zeroed, no weight decay); the new rows used a 10ร learning rate
A first version (v1) initialised new characters with the mean embedding. After training, these new embeddings were still short (median norm 1.56 vs 4.69 for existing single Han characters) and nearly identical to each other (mean pairwise cosine similarity 0.93 vs 0.14 among existing Han characters). With tied input/output embeddings the model could read the new characters but rarely wrote them (e.g. ็ญฒ็ฎ็ฃ โ ๅซ็ฃ). With the decoder-state initialisation (v2) the new embeddings are well separated (mean pairwise cosine 0.31, median norm 2.67) and are generated much more often.
Training data
- raptorkwok/cantonese-traditional-chinese-parallel-corpus (CC0),
trainsplit only - The corpus' own validation/test splits were not used: 65% of the test pairs are near-copies (source โ reference)
- Cleaning: removed over-long and length-mismatched pairs, pairs whose "written Chinese" side still contains Cantonese colloquial characters, duplicates, and two thirds of near-copy pairs
- 100,751 training pairs; punctuation removed from half of the sources (speech-recognition output has none)
- Validation and test sets (1,000 pairs each) held out from the training split: real translations only (character similarity < 0.85), and every pair sharing a source sentence with them removed from training
Training procedure
| Setting | Value |
|---|---|
| Base model | facebook/nllb-200-distilled-600M (all layers trained except original embedding rows) |
| Steps | 1 epoch, 3,149 steps; best checkpoint at step 3,000 |
| Batch size | 16 ร 2 gradient accumulation = 32 |
| Optimizer | Adafactor, learning rate 1e-4 (new embedding rows 1e-3), 500 warm-up steps, linear decay |
| Precision | fp16, one NVIDIA T4 (Google Colab), 62 min |
| Best validation chrF | 32.7 |
Results
Held-out test set, 1,000 pairs; CTranslate2 int8, beam size 4. Before scoring, both sides are converted to
half-width characters (NFKC) and simplified Chinese (OpenCC t2s); BLEU uses sacrebleu's zh tokenizer.
"No punct." = punctuation removed from the source, as in speech-recognition output.
| Model | BLEU | chrF | BLEU (no punct.) | chrF (no punct.) |
|---|---|---|---|---|
| facebook/nllb-200-distilled-600M (original) | 14.6 | 14.5 | 13.7 | 13.6 |
| fine-tuned v1 (new characters initialised with the mean embedding) | 36.2 | 32.3 | 33.7 | 30.0 |
| this model (v2, decoder-state initialisation) | 37.2 | 33.1 | 34.8 | 30.9 |
- Sentence-level chrF: v2 is better than the original model on 83.4% of sentences and worse on 13.2% (Wilcoxon signed-rank p โ 7e-111); better than v1 on 29.5%, worse on 20.3% (p = 3e-5)
- Truncated translations (shorter than 60% of the reference): 24.2% โ 5.0%
- Recall of the newly added characters in the references: 22.7% (original) โ 43.6% (v1) โ 56.1% (v2)
Limitations
- Fine-tuned only for Cantonese โ written Chinese. English output is usable but place names are often wrong (e.g. ่ตๆถ โ "Guangzhou"); in the app we block Chinese characters in English output and retry looping outputs.
- The parallel corpus is mostly short conversational sentences; long or formal text is less covered.
- New characters that are rare in the training targets are still not reliably generated.
- Non-commercial license (inherited from NLLB-200).
- Downloads last month
- 26
Model tree for Ming224/nllb-600m-cantonese
Base model
facebook/nllb-200-distilled-600M