Romanized Nepali to Devanagari (Transformer)

A character-level Transformer that converts romanized Nepali words (for example namaste, kasto, cha) into Devanagari (नमस्ते, कस्तो, छ). It is meant for search and text normalization over informal Nepali, where people type in Latin letters.

It is a 3-layer encoder and 3-layer decoder model (d_model 256, 4 heads, feed-forward 512, about 4 M parameters). It was trained in two stages:

  1. Stage 1: about 1.9 M word pairs from the Aksharantar Nepali corpus and the NepaliFlow word pairs.
  2. Stage 2: fine-tuned on romanized spelling variants that real users type.

Usage

from huggingface_hub import snapshot_download
import sys

path = snapshot_download("Aananda-giri/romanized-nepali-devanagari")
sys.path.insert(0, path)
from romanized_nepali import Transliterator

t = Transliterator.from_pretrained(path)
words = ["namaste", "kasto", "cha", "dherai", "ramro"]
for w, out in zip(words, t.translate(words)):
    print(w, "->", out)

Decoding uses beam search (beam size 5, length penalty 0.6), the same setting as the evaluation below.

Results

Exact match and character error rate (CER, lower is better) on the test sets in this repository's evaluation:

Test set Rows This model NepaliXlit (our port of the published checkpoint)
NepaliFlow 4,033 66.08% exact, 6.12% CER 65.34% exact, 6.30% CER
Aksharantar 4,101 58.47% exact, 10.73% CER 63.98% exact, 8.39% CER

On NepaliFlow this model is slightly ahead of NepaliXlit. On Aksharantar it is behind. The NepaliXlit numbers come from our reimplementation of the published checkpoint, not from the authors' own code, so they are only an approximate baseline. This model was not compared against the paper's own held-out test set, so the paper's reported gain does not carry over to these numbers.

Romanized Nepali is ambiguous at the single-word level (vowel length is not written, and s, sh and chha/cha collapse together). Some errors are therefore not avoidable without sentence context.

Limitations

  • Works on single words, not sentences.
  • Trained on formal and dictionary-sourced spellings, plus a smaller set of informal variants. Unusual spellings can fail.
  • Output uses only the characters seen in training.

Files

  • model.pt: model weights (PyTorch state dict).
  • vocab.json: character vocabularies for source and target.
  • romanized_nepali.py: model definition and beam-search decoder.
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