Nepali NLP

Building NLP for the Nepali Language: Challenges, Tools and Practical Fixes

Why Nepali is hard for NLP — Unicode, Preeti fonts, Romanized text, postpositions, tokenizers — and practical Python fixes for each.

Key takeaways

  • Most failures in Nepali NLP happen before the model: inconsistent Unicode, legacy font encodings and mixed scripts.
  • Always normalise text (Unicode NFC, invisible characters, digits) as the very first step.
  • Real Nepali users write in Devanagari, Romanized Nepali and English — often in one sentence. Plan for all three.
  • Multilingual models such as XLM-RoBERTa include Nepali, but English-centric tokenizers split Nepali words into many pieces, which costs accuracy, context length and money.

Nepali is spoken by tens of millions of people, yet it remains a low-resource language for natural language processing: there is far less clean, labelled text than for English, and many off-the-shelf tools quietly assume English. While working on BhasaBodh, a Nepali language-understanding project at eSewa, and later on chatbots for Nepali users, I kept running into the same set of problems. This article collects them along with fixes you can apply in Python today.

Problem 1: The same word, different bytes

Devanagari is a complex script. Characters combine: a consonant plus a vowel sign (matra), a halanta (virama, ्) that joins consonants into conjuncts, and modifiers such as chandrabindu (ँ) and anusvara (ं). Unicode allows some of these sequences to be written in more than one way, and different keyboards and websites produce different variants. Two strings can look identical on screen and still fail an equality check.

Invisible characters make it worse. The zero-width joiner (U+200D) and zero-width non-joiner (U+200C) control how conjuncts render, and they often sneak into copied text. Search, deduplication and tokenization all break silently.

import re
import unicodedata

ZERO_WIDTH = re.compile(r"[​‌‍]")
NEPALI_DIGITS = str.maketrans("०१२३४५६७८९", "0123456789")

def normalize_nepali(text: str, ascii_digits: bool = True) -> str:
    text = unicodedata.normalize("NFC", text)
    text = ZERO_WIDTH.sub("", text)
    text = text.replace("।", " । ").replace("॥", " ॥ ")  # danda spacing
    if ascii_digits:
        text = text.translate(NEPALI_DIGITS)
    return re.sub(r"\s+", " ", text).strip()

print(normalize_nepali("मेरो‍ घर   काठमाडौंमा छ। फोन ९८०१२३४५६७"))
# मेरो घर काठमाडौंमा छ । फोन 9801234567

Removing zero-width joiners can change how a small number of conjuncts render. For search and classification that's almost always acceptable; for text you will display back to users, keep the original string and use the normalised version only for processing.

Problem 2: Legacy fonts like Preeti

Before Unicode was common, Nepali text was typed with fonts such as Preeti and Kantipur. These fonts map ordinary ASCII keys to Devanagari glyphs. To a computer the text is just Latin letters and symbols; it only looks Nepali when the font is installed. Large amounts of government documents, old news archives and office files are still stored this way.

If your dataset contains strings like g]kfn where you expected नेपाल, you are looking at Preeti-encoded text. It must be converted with a character-mapping converter before any NLP step. Open-source Preeti-to-Unicode converters exist in Python and JavaScript; pick one, then spot-check its output manually on a few hundred words, because conjunct and half-letter rules vary between implementations.

Detecting legacy-font text automatically

A simple heuristic works surprisingly well: if a document that should be Nepali contains almost no characters in the Devanagari Unicode block (U+0900–U+097F) but lots of punctuation like ], [, ; and { inside words, flag it for conversion.

def devanagari_ratio(text: str) -> float:
    letters = [c for c in text if not c.isspace()]
    if not letters:
        return 0.0
    return sum("ऀ" <= c <= "ॿ" for c in letters) / len(letters)

def looks_like_preeti(text: str) -> bool:
    odd = sum(c in "][{};'" for c in text)
    return devanagari_ratio(text) < 0.2 and odd / max(len(text), 1) > 0.03

Problem 3: Romanized Nepali and code-mixing

Look at comments on any Nepali YouTube video or Facebook page and you'll see sentences like "k cha khabar? malai yo app ko login ma problem bhayo". That's Nepali written in Latin letters, mixed with English words — and it's how a large share of real users type, especially on phones.

There's no single standard spelling: "chha", "cha" and "xa" all mean छ. A chatbot or sentiment model trained only on Devanagari will miss most of this traffic. Practical options:

  • Detect the script first (using the Devanagari ratio above) and route Romanized text differently.
  • Transliterate Romanized Nepali to Devanagari before classification. Rule-based transliteration handles common words; for messy social-media text, a small sequence model trained on paired examples does better.
  • Train on mixed data. If your labelled data includes all three forms (Devanagari, Romanized, English), modern multilingual models learn to handle the mix directly.
  • Normalise common spellings with a lookup table (xa → cha, 6 → cha in chat slang) built from your own data.

Problem 4: Postpositions glued to words

Nepali grammar attaches postpositions directly to nouns: घर (house) becomes घरमा (in the house), घरको (of the house), घरबाट (from the house). Verbs inflect heavily for tense, person, gender and honorifics. For bag-of-words models and keyword search, this means one concept appears as dozens of surface forms, and your vocabulary explodes.

A light suffix-stripping step — removing common postpositions such as ले, लाई, को, का, की, मा, बाट, देखि, सम्म and the plural हरू — often improves search and classical classifiers noticeably. Be conservative: strip only when the remaining stem is at least two characters, and test on your own data.

SUFFIXES = sorted(["हरूलाई", "हरूको", "हरूमा", "हरू", "लाई", "बाट", "देखि", "सम्म",
                   "ले", "को", "का", "की", "मा"], key=len, reverse=True)

def light_stem(word: str) -> str:
    for s in SUFFIXES:
        if word.endswith(s) and len(word) - len(s) >= 2:
            return word[: -len(s)]
    return word

print([light_stem(w) for w in "विद्यार्थीहरूलाई काठमाडौंमा घरबाट".split()])
# ['विद्यार्थी', 'काठमाडौं', 'घर']

For transformer models you usually skip stemming — subword tokenizers handle morphology — but stemming remains valuable for search indexes, keyword features and quick baselines.

Problem 5: Tokenizers that don't speak Nepali

Large language models read tokens, not words. Tokenizers trained mostly on English break Nepali words into many small pieces — sometimes individual characters or bytes. This has three costs: the model sees less meaning per token, long Nepali documents hit context limits sooner, and API bills (charged per token) are higher for the same content.

You can measure this yourself in a few lines:

from transformers import AutoTokenizer

samples = {
    "English": "The bank will remain closed on Saturday.",
    "Nepali":  "बैंक शनिबार बन्द रहनेछ।",
}
for name in ["bert-base-uncased", "xlm-roberta-base"]:
    tok = AutoTokenizer.from_pretrained(name)
    for lang, text in samples.items():
        print(f"{name:20} {lang:8} {len(tok.tokenize(text)):3} tokens")

Run it and compare the token counts per word for each language. Multilingual tokenizers such as XLM-RoBERTa's, which saw Nepali during training, typically produce far fewer pieces for Nepali than English-only ones. When you choose a model for a Nepali task, this "tokens per word" ratio is one of the quickest quality signals available.

Where to find Nepali data and models

Resource typeExamplesGood for
Raw text corporaNepali Wikipedia dumps; multilingual web corpora such as CC-100 and OSCAR (Nepali subsets)Pre-training, embeddings, language modelling
Multilingual modelsXLM-RoBERTa, multilingual BERT, multilingual sentence-embedding modelsFine-tuning for classification, NER, semantic search
Community modelsNepali-specific BERT/GPT-style models shared on the Hugging Face HubTasks where Nepali-only pre-training helps
Your own dataSupport tickets, app reviews, form responses (with permission and anonymisation)The most valuable labelled data you'll ever get

Web corpora are noisy: expect duplicated pages, Hindi or Maithili text mislabelled as Nepali, and leftover Preeti encodings. Deduplicate and filter by script ratio before training on them.

A practical pipeline

For most Nepali text-classification or chatbot projects, this order works well:

  1. Collect real user text from your channel (with consent), not just formal news text.
  2. Detect & convert legacy fonts; detect script for every record.
  3. Normalise Unicode, invisible characters and digits.
  4. Label a few thousand examples covering Devanagari, Romanized and English inputs.
  5. Baseline with TF-IDF plus light stemming and logistic regression — it takes minutes and tells you how hard the task is.
  6. Fine-tune a multilingual transformer and compare against the baseline using macro-F1, not just accuracy.
  7. Monitor production inputs; Romanized spellings and slang drift quickly.

Why this matters

Banks, wallets, telecoms and government services in Nepal increasingly talk to customers through apps and chat. If the software only understands formal Devanagari or English, it fails exactly the people who most need simple, accessible service. Getting the unglamorous preprocessing right is what makes Nepali NLP work in the real world. If you're building something in this space, I'd be glad to hear about it — get in touch, or watch the BhasaBodh overview video.

Spotted an error or have a question about this article? Send me a message — corrections are applied and noted with an updated date. See the editorial policy.

Keep reading

More articles you may find useful.

All articles