Netra Lab


GitHub | Docker Image | PyPI

Netra NMT

English or Khmer text in, the other language out. Netra NMT is a 77M-parameter English↔Khmer translation model: one encoder-decoder transformer for both directions, trained from scratch on 220 million tokens of parallel text. It runs on ONNX Runtime with the netra-nmt package, on a CPU, without PyTorch.

Results

ALT test split (mutiyama/alt, 1,018 pairs), greedy decoding; spBLEU with the FLORES-200 tokenizer, higher is better.

Model Params EN → KM KM → EN
NLLB-350M (EN-KM) 350M 18.89 0.26
NLLB-200 distilled 600M 600M 9.24 31.28
NLLB-200 distilled 1.3B 1.3B 16.62 35.15
MADLAD-400 3B 16.19 36.13
Google Translate — 28.93 34.86
Netra NMT 77M 25.83 19.47
  • Where it wins: English→Khmer, the best spBLEU after Google Translate and the best TER of all systems (60.47), and on CPU 65.6 ms per sentence greedy against 550.8 for NLLB-350M.
  • Where it loses: Khmer→English, 15.7 spBLEU behind NLLB-200 1.3B.

spBLEU, chrF++, TER, COMET and BERTScore on ALT

spBLEU, chrF++, TER, COMET (wmt22-comet-da) and BERTScore F1 (xlm-roberta-base) on ALT, both directions.

Speed against NLLB on CPU and GPU

English→Khmer, median ms per sentence over 20 sentences, Intel i7-13700KF (16 threads) and RTX 3060, PyTorch.

Architecture

Netra-NMT translating I love my country into Khmer: a 12-layer encoder and a 2-layer decoder, one layer of each opened up

  • Shape: 12 encoder layers, 2 decoder layers (deep encoder, shallow decoder), d_model 512, 8 heads, FFN 2048, vocabulary 32K.
  • Components: rotary position embeddings, RMSNorm (pre-norm), SwiGLU, one embedding table shared by the encoder, the decoder and the tied output head, a KV cache.
  • Input: a target-language marker (<2km> or <2en>) then the source. English sources are NFC-normalised and lowercased; Khmer is word-segmented with khmercut. The package does this for you.

Decoding

The encoder runs once per sentence; the 2-layer decoder then runs one step per token, reusing its self-attention keys and values from a KV cache. Beam search stops as soon as no live beam can still beat the best finished one. Scores only fall as a beam grows, so this gives exactly the output of full-length beam search (1,018 of 1,018 ALT pairs identical, both directions), far sooner.

English→Khmer, i7-13700KF CPU Greedy ms/sent ↓ Beam-5 ms/sent ↓
netra-nmt 0.1.0 (PyTorch, full-length beam) 62.6 701.1
netra-nmt 1.0.0 (ONNX Runtime, early stop) 39.1 63.5

Median over 20 sentences. The package generates the same tokens as the PyTorch model on the ALT test set, greedy and beam-5, both directions.

Try the app

The Docker image bundles the model with a web app and a REST API (POST /api/translate), and runs offline. A demo Space runs the same model.

docker run --rm -p 8000:8000 ghcr.io/netra-ai-lab/netra-nmt:latest
# then open http://localhost:8000

The Netra NMT web app translating two English sentences about a scholarship program into Khmer with beam search

English→Khmer with beam search, in version 1.0.0 of the Docker image on the CPU.

Usage

pip install "netra-nmt[cpu]"        # or [gpu]
from netra_nmt import translate

translate("Hello, how are you?")                         # English -> Khmer
translate("ខ្ញុំស្រលាញ់ប្រទេសកម្ពុជា។", direction="km2en")    # -> "I love Cambodia."
netra-nmt --text "Hello, how are you?" --mode beam
netra-nmt serve                       # web app + REST API (extra: server)

The package downloads model/ from this repo once, at the commit it was tested with. Translate one sentence at a time: sources are cut at 256 tokens.

Files

File Contents
model/netra-model.json settings: graphs, decoder shape, special ids, language markers, sha256 of every file
model/encoder.onnx tokens → cross-attention keys/values for every decoder layer (136 MB)
model/decoder_step.onnx one decoding step with the self-attention KV cache (52 MB)
model/spm_32k.model the SentencePiece tokenizer
pytorch/model.safetensors fp16 weights for fine-tuning (lm_head tied to the embeddings, not stored)
pytorch/config.json, pytorch/spm_32k.model architecture and tokenizer for the PyTorch model
assets/ the figures on this card

To fine-tune from pytorch/: bash training/finetune.sh my_pairs.tsv in the GitHub repo.

Training data and test set

About 2.4M unique pairs after deduplication and length filtering, used in both directions (4.2M examples), from four sources:

The cleaned, combined set is Netra-Lab/bilingual-en-km. The model was tested on the test split of mutiyama/alt (Wikinews), and was not fine-tuned on it.

Learn more

README The project overview: data, architecture, evaluation, install, usage and limitations
Results Every measured number: quality, speed (PyTorch and ONNX Runtime), the parity check
Architecture The package, the two ONNX graphs and the model folder format
Training Fine-tuning on your own pairs, the full recipe, evaluation and export
Issues Bug reports and questions

License and attribution

  • Weights: MIT, trained from scratch (no pretrained weights).
  • Training data: see the dataset card and its sources; check their terms before commercial use.
  • Evaluation data: ALT (NICT), CC BY 4.0.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Datasets used to train Netra-Lab/Netra-NMT

Space using Netra-Lab/Netra-NMT 1