Views
No views yet
facebook/nllb-200-distilled-600M for Swahili → Kalenjin translation. Kalenjin is a Nilotic language with ~5M speakers across the Kenyan Rift Valley, parts of Tanzania, Uganda, and the diaspora; NLLB-200 ships no Kalenjin code, so this adapter decodes into the unused luo_Latn token slot.1import torch
2from transformers import AutoModelForSeq2SeqLM, NllbTokenizerFast
3from peft import PeftModel
4
5base = AutoModelForSeq2SeqLM.from_pretrained(
6 "facebook/nllb-200-distilled-600M", torch_dtype=torch.float32
7)
8model = PeftModel.from_pretrained(base, "Tonykip/swahili-kalenjin-mt-lora")
9model.eval()
10
11tok = NllbTokenizerFast.from_pretrained("facebook/nllb-200-distilled-600M")
12tok.src_lang = "swh_Latn"
13inputs = tok("Habari ya asubuhi, rafiki.", return_tensors="pt", truncation=True)
14
15# Decode into Kalenjin via the luo_Latn token slot
16luo_id = tok.convert_tokens_to_ids("luo_Latn")
17out = model.generate(
18 **inputs,
19 forced_bos_token_id=luo_id,
20 max_length=256,
21 num_beams=5,
22 early_stopping=True,
23)
24print(tok.batch_decode(out, skip_special_tokens=True)[0])1# Leg 1: EN -> SW (base NLLB, adapter disabled)
2with model.disable_adapter():
3 tok.src_lang = "eng_Latn"
4 inputs = tok("Tell my brother I'll visit next week.", return_tensors="pt")
5 swh = model.generate(
6 **inputs,
7 forced_bos_token_id=tok.convert_tokens_to_ids("swh_Latn"),
8 max_length=256, num_beams=5, early_stopping=True,
9 )
10 swahili = tok.batch_decode(swh, skip_special_tokens=True)[0]
11
12# Leg 2: SW -> KL (adapter active, decoding to luo_Latn slot)
13tok.src_lang = "swh_Latn"
14inputs = tok(swahili, return_tensors="pt")
15kln = model.generate(
16 **inputs,
17 forced_bos_token_id=tok.convert_tokens_to_ids("luo_Latn"),
18 max_length=256, num_beams=5, early_stopping=True,
19)
20kalenjin = tok.batch_decode(kln, skip_special_tokens=True)[0]facebook/nllb-200-distilled-600Mq_proj, k_proj, v_proj, out_proj, fc1, fc2warmup_ratio=0.05 · optim=adamw_8bitluo_Latn slot, the closest Nilotic neighbor NLLB ships withthinkKenya/kenyan-low-resource-language-data (kln_swa config, test split):| Metric | Score |
|---|---|
| chrF++ | 58.79 |
| BLEU | ~6 |
num_beams=5, max_length=256, early_stopping=True, forced_bos_token_id=luo_Latn.1@misc{kipkemboi2026kalenjincascade,
2 title = {A Two-Leg Cascade for English → Kalenjin Machine Translation},
3 author = {Tony Kipkemboi},
4 year = {2026},
5 note = {chamgei.labs working notes},
6 url = {https://chamgei.com}
7}