NyayaLM Tokenizer (64k v2)

SentencePiece-BPE tokenizer (exact vocabulary size 64,000) designed for NyayaLM-200M, a bilingual (Nepali + English) legal-domain language model.

It is optimized for:

  • Native Nepali (Devanagari)
  • Romanized Nepali (Latin script)
  • English
  • Mixed code-switched legal / everyday text
  • ChatML-style conversation formatting (Qwen3)

Key Features

Feature Value
Vocabulary size 64,000
Algorithm SentencePiece BPE + byte fallback
Character coverage 0.9995
Special tokens ChatML (`<
Pre-tokenizer Metaspace ()
Normalization Identity (no aggressive NFKC)
Split digits / numbers Yes
Split by Unicode script Yes
Byte fallback Enabled

The tokenizer was trained without any hardcoded seed symbols — the entire alphabet (Devanagari + Latin + digits + punctuation) is learned purely from the bilingual legal + general corpus.


Training Data Summary

A carefully balanced bilingual corpus was constructed from the following sources (streaming + deduplication via BLAKE2b):

Nepali (Devanagari)

  • Wikipedia Nepali dump
  • Himalaya-AI Nepali tokenizer corpus
  • Nepali Supreme Court judgement text corpus
  • Sangraha Nepali
  • Nepal Legal Acts corpus (Nepali)

≈ 885k documents · ~1.33 billion characters

English + Romanized Nepali

  • GPT-2 style English pre-train corpus
  • High-quality English sentences
  • Nepal Legal Acts corpus (English)
  • WikiText-103 (raw)
  • Roman-Nepali Alpaca
  • Roman-Nepali e-commerce QA (ShareGPT format)

≈ 2.40 million documents · ~1.22 billion characters

Final training corpus after balancing & interleaving:

  • 3.28 million lines
  • ~3.9 GB of clean text
  • Strong coverage of both Devanagari and Latin scripts (verified by character statistics)

Intended Use

  • Pre-training / continued pre-training of small–medium LLMs focused on Nepali legal text
  • Instruction tuning and chat with ChatML format
  • Any application that needs efficient tokenization of Nepali + English + Romanized Nepali mixtures

Evaluation Metrics

We evaluated the tokenizer against strong baselines on four language categories:

  • Pure English
  • Pure Nepali (Devanagari)
  • Romanized Nepali
  • Mixed / code-switched

Primary metrics (lower fertility & higher STRR are better):

Metric Description Direction
Fertility Tokens per whitespace-delimited word ↓ better
Characters per token Compression efficiency ↑ better
STRR Single-Token Retention Rate (% of words kept intact) ↑ better

Overall Mean Metrics (all languages combined)

Tokenizer Fertility ↓ Chars/Token ↑ STRR ↑
Custom (nyayalm-64k) 1.483 4.294 0.709
Gemma-4 1.536 4.102 0.495
GPT-OSS-20B (o200k_harmony) 1.600 3.962 0.448
GPT-5 (o200k) 1.600 3.962 0.448
Llama-3.2 2.102 3.265 0.414
Qwen3.5 2.329 3.126 0.408
Claude (approx) 3.252 2.779 0.393

Per-Language Fertility (lower = better)

Tokenizer English Mixed Nepali Roman_Nepali
Custom (nyayalm-64k) 1.131 1.135 1.252 2.417
Gemma-4 1.131 1.099 1.769 2.147
GPT-5 (o200k) 1.147 1.157 1.823 2.272
GPT-OSS-20B (o200k_harmony) 1.147 1.157 1.823 2.272
Llama-3.2 1.189 1.471 3.311 2.437
Qwen3.5 1.189 1.587 4.179 2.362
Claude (approx) 1.172 1.984 7.277 2.573

Per-Language STRR (higher = better)

Tokenizer English Mixed Nepali Roman_Nepali
Custom (nyayalm-64k) 0.869 0.865 0.816 0.283
Gemma-4 0.756 0.768 0.243 0.213
GPT-5 (o200k) 0.675 0.712 0.218 0.188
GPT-OSS-20B (o200k_harmony) 0.675 0.712 0.218 0.188
Llama-3.2 0.675 0.708 0.084 0.188
Qwen3.5 0.675 0.708 0.059 0.188
Claude (approx) 0.656 0.688 0.040 0.188

Key takeaways:

  • Best overall fertility (1.483) and highest STRR (0.709) among all compared tokenizers.
  • Dramatically lower fertility on pure Nepali (1.252 vs 1.77–7.28 for others).
  • Highest single-token retention on Nepali (81.6%) — most words stay intact.
  • Competitive or best on English and Mixed text.
  • Strong advantage on legal-domain and code-switched Nepali–English sentences.

Usage

from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained("chhatramani/nyayalm-tokenizer-64k_v2")

# Simple encode / decode
text = "नेपालको संविधान २०७२ ले नागरिकलाई मौलिक हक प्रदान गरेको छ।"
ids = tok.encode(text, add_special_tokens=False)
print(len(ids), tok.decode(ids))

# ChatML conversation
messages = [
    {"role": "system", "content": "You are a helpful Nepali legal assistant."},
    {"role": "user", "content": "मेरो मौलिक हक के के हुन्?"},
]
prompt = tok.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
)
print(prompt)

Special token IDs (example)

Pythonprint(tok.convert_tokens_to_ids("<|endoftext|>"))  # 63982
print(tok.convert_tokens_to_ids("<|im_start|>"))   # 63983
print(tok.convert_tokens_to_ids("<|im_end|>"))     # 63984
print(len(tok))

Citation

If you use this tokenizer in your research or product, please cite:

bibtex@misc{nyayalm-tokenizer-64k-v2,
  title  = {NyayaLM 64k SentencePiece-BPE Tokenizer},
  author = {Chhatramani},
  year   = {2026},
  url    = {https://huggingface.co/chhatramani/nyayalm-tokenizer-64k_v2}
}

License

Apache License 2.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