nkya_base: any-to-any translation between 6 languages (pretrained base)

nkya_base is a 242M-parameter encoder-decoder Transformer that translates directly between any two of: English (eng), Luganda (lug), Runyankole (nyn), Acholi (ach), Lugbara (lgg), Ateso (teo). That is 30 directions with one model. The direction is set by a prefix token on the source naming the target language <2eng>, <2lug>, <2nyn>, <2ach>, <2lgg>, <2teo>.

This is a pretrained base, not a finished translator. It was trained only on machine-translated pairs (see Training) and has not been fine-tuned on human-translated data. A fine-tuned version is published separately as amDANIEL2024/nkya_finetuned.

Quick start

pip install torch sentencepiece safetensors huggingface_hub
import sys
from huggingface_hub import snapshot_download

folder = snapshot_download("amDANIEL2024/nkya_base")   # add token="hf_..." if the repo is still private
sys.path.insert(0, folder)
from nkya import Translator

t = Translator(folder)                                   # uses the GPU if there is one
print(t.translate("<a Runyankole sentence>", "nyn2lgg"))        # Runyankole -> Lugbara
print(t.translate(["<an English sentence>"], "eng2teo"))        # English -> Ateso

Language codes: eng, lug, nyn, ach, lgg, teo. A direction is "<source>2<target>" for any two different codes. translate takes a string or a list and accepts beam (default 4). This is a custom PyTorch model, not a transformers model, so AutoModel will not load it.

Model

Architecture pre-LN Transformer encoder-decoder, 6 + 6 layers, d_model 1024, 16 heads, FFN 4096, GELU
Parameters 242M (input embedding, decoder embedding and output projection are tied)
Tokenizer one shared SentencePiece model, 64,000 pieces, trained on all 6 languages with an equal share of text each (spm.model)
Context 256 positions (sinusoidal); training texts were limited to 128 pieces
Weights model.safetensors (float32)

Training

  • Data: the rows of tulati; each row is the same sentence in every language, so every row is used in many directions (a few randomly chosen directions per row per epoch, a new choice every epoch). In tulati the English column is the source text and every other language column is a machine translation of it, made by Sunbird/translate-nllb-1.3b-salt; so every non-English side is machine output and no human-written non-English text is in it. This card does not report how good that translator is for these languages.
  • Filtering (counts from this run): tulati had 1,534,699 rows. A language flagged by tulati's quality flags (empty, degenerate, looks-like-English, length-outlier; not applied to English) was excluded from that row only (flagged per language: {'eng': 0, 'lug': 34011, 'nyn': 35277, 'ach': 61272, 'lgg': 104472, 'teo': 104732}). Rows with fewer than two usable languages, and 14 exact duplicate rows, were removed, leaving 1,532,808 rows. Pairs whose two sides are identical are never trained on. Decontamination against SALT dev/test removed 4 row(s); 1,531,304 rows were used for training and 1,500 held out for validation.
  • Tokenizer: trained on tulati plus the text of the SALT train split, an equal number of sentences per language.
  • Pretraining: stopped early at step 15,133 (1 full epoch(s) plus part of the next) of the 8 epochs that were planned; the schedule was not run to the end. More pretraining could change the scores. About 18k target tokens per step, fp16 on one Kaggle T4, label smoothing 0.1, AdamW, linear warmup then inverse-sqrt decay (peak LR 2e-4). Trained on tulati only.

Evaluation

Full SALT dev/test scores: not run for this base yet. SALT test has not been used for anything.

End of pretraining (step 15,133), loss averaged over directions:

Set Loss Perplexity
tulati validation (held-out machine-translated rows, 8 directions per row) 1.725 5.6
SALT dev (human translations, all directions) 3.273 26.4

Per-direction losses are in the training logs. Loss is not comparable between the two sets (machine vs human text).

SALT's sentences in different languages are independent human translations of the same English sentence, so a reference in one language is not a translation of the reference in another.

Limitations

  • Training pairs are machine output (see Training), so the model inherits that translator's errors and style; real human-written text (dialect, spelling, code-switching) may be handled worse than benchmark numbers suggest.
  • Quality will differ a lot between directions; check the per-direction tables before relying on any one of them.
  • Meaning can be dropped or changed, especially for numbers, names and rare words. Do not use it for medical, legal or other high-stakes content without human review.
  • Sentence-level model: inputs longer than about 128 pieces are truncated or degrade.
  • Outputs have not been reviewed by native speakers of the non-English languages.

Files

model.safetensors weights · config.json architecture and training summary · spm.model tokenizer · nkya.py standalone inference code · eval_results.json full evaluation (when available) · README.md this card.

License

Released under the MIT License (as are tulati, the translation model that generated the training data, and SALT).

Author

Amanyire Daniel (amDANIEL2024) · domusdeiug@gmail.com · https://domusdeiug.com

Downloads last month
-
Safetensors
Model size
0.2B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train amDANIEL2024/nkya_base