mutaician/nllb-swahili-kalenjin-joint-v2
NLLB Swahili–Kalenjin joint adapter (v2)
LoRA adapter for bidirectional Swahili–Kalenjin translation on `facebook/nllb-200-distilled-600M` at revision f8d333a098d19b4fd9a8b18f94170487ad3f821d.
This is the validation-selected epoch-13 joint checkpoint from a deployment-informed redevelopment of a Swahili–Kalenjin translator. One adapter covers both directions. The tokenizer includes a native kln_Latn language token (id 256204).
This repository is the adapter only. It is not a complete model: load the pinned NLLB base, resize embeddings to the adapter tokenizer, then attach these weights.
Intended use
- Research and local serving of Swahili→Kalenjin and Kalenjin→Swahili translation.
- Reproducing the IAAI application-study model-selection result.
Not intended as a certified public-service translator. Automatic metrics do not establish adequacy across Kalenjin varieties.
How to load
The adapter tokenizer is larger than stock NLLB because of kln_Latn. Skipping resize_token_embeddings will fail or silently drop the native token.
import torch
from peft import PeftModel
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
ADAPTER = "mutaician/nllb-swahili-kalenjin-joint-v2"
BASE = "facebook/nllb-200-distilled-600M"
BASE_REVISION = "f8d333a098d19b4fd9a8b18f94170487ad3f821d"
tokenizer = AutoTokenizer.from_pretrained(ADAPTER)
base = AutoModelForSeq2SeqLM.from_pretrained(
BASE,
revision=BASE_REVISION,
torch_dtype=torch.float16,
device_map="auto",
)
base.resize_token_embeddings(len(tokenizer))
model = PeftModel.from_pretrained(base, ADAPTER)
model.eval()
def translate(text: str, src_lang: str, tgt_lang: str) -> str:
tokenizer.src_lang = src_lang
encoded = tokenizer(text, return_tensors="pt").to(model.device)
generated = model.generate(
**encoded,
forced_bos_token_id=tokenizer.convert_tokens_to_ids(tgt_lang),
num_beams=5,
max_length=256,
)
return tokenizer.batch_decode(generated, skip_special_tokens=True)[0]
print(translate("Habari yako?", "swh_Latn", "kln_Latn"))
print(translate("Chamgei?", "kln_Latn", "swh_Latn"))Language tags: swh_Latn (Swahili), kln_Latn (Kalenjin).
Evaluation
Checkpoint selection used macro-average validation chrF across both directions. The clean test set was not used for selection. Scores below are the training-run evaluation on 6,666 exact-pair-disjoint unique test pairs per direction (beam 5, batch 4, max length 256).
SacreBLEU signature: nrefs:1|case:mixed|eff:no|tok:13a|smooth:exp|version:2.6.0.
Under a matched training budget, this joint adapter stayed within 0.15 macro chrF of two independently selected directional adapters while storing one adapter instead of two.
A later epoch-42 checkpoint scored higher on the same test set. That comparison was run after test inspection and is not this release.
Training
Limitations
- BLEU/chrF are automatic corpus scores, not native-speaker adequacy.
- Kalenjin is a cluster of related varieties; a pooled label can hide dialect differences.
- This adapter requires the exact base revision above plus embedding resize.
- License follows NLLB: CC-BY-NC-4.0 (non-commercial).
- Dataset access follows the thinkKenya dataset card; this repo does not redistribute parallel text.
Citation
Adapter selected for the IAAI application study From Benchmark to Pilot: Deployment-Informed Development of Swahili–Kalenjin Machine Translation. Use this repository, not the historical two-adapter Space, as the v2 model artifact.
- Dataset: thinkKenya/kenyan-low-resource-language-data
- Historical pilot Space: mutaician/swahili-kalenjin-translator
