Add a Language#
The language key in the extend and init_embeddings configurations resolves to a language profile: one registry entry that supplies the corpus normalizer, the script whose residual tokens Replace prunes, the script used to locate the base model’s existing target rows, the auxiliary encoder for bert_weighted, and the fastText code for focus.
Registering a language is a small source change in src/nemotron/steps/tokenizer_extension/; no step needs editing.
Before You Begin#
Check whether the language is already registered.
The current registry contains hindi, marathi, nepali, sanskrit, bengali, punjabi, gujarati, odia, tamil, telugu, kannada, malayalam, urdu, and vietnamese.
Procedure#
Add Unicode ranges in
script_ranges.pyif the script is not already present inSCRIPT_UNICODE_RANGES.A token belongs to the language when any character of its decoded surface falls in one of the ranges. For a script with its own Unicode block, that block is the range:
"thai": [(0x0E00, 0x0E7F)],
For a Latin-script language, enumerate only the codepoints that the language uses, as the
vietnameseentry does with precomposed vowel-tone letters, horned o and u, and the combining horn. Never include plain ASCII Latin: it is shared with every other Latin-script language, and pruning it undermethod=replacewould remove the byte alphabet that new merges are built from.Add a
LanguageProfileinlanguages.py."thai": LanguageProfile("none", "thai", "th", _XLMR),
The four positional fields are:
Field
Meaning
normalizerKey into
NORMALIZERS;"none"applies NFKC onlyscriptKey into
SCRIPT_UNICODE_RANGESfasttextLanguage code of the
cc.<code>.300fastText vectors used byfocusencoderHugging Face identifier of an encoder that covers the language, used by
bert_weightedChoose the encoder deliberately. MuRIL (
google/muril-base-cased) covers 17 Indian languages and nothing else, so_MURILis correct for the Indic entries and_XLMR(FacebookAI/xlm-roberta-base) is the general fallback. An encoder that does not cover the target language produces abert_weightedinitialization thatLANGUAGES.mddescribes as no better than noise.Add a normalizer only when the script needs more than NFKC.
NFKC is always applied. The
devanagarinormalizer additionally runsDevanagariNormalizerfromindic-nlp-library. New normalizers are registered inlanguages.get_normalizer().Run
extendwith the new value.$ uv run nemotron steps run tokenizer_extension/extend -c default language=thai method=add \ corpus.hf_dataset=<org/dataset> corpus.hf_name=<config> corpus.hf_split=<split>
The step logs the resolved
script_normalizerandremove_scriptat start-up; confirm they match the profile.
Backward Compatibility#
A configuration with no
languagekey keeps the historical Devanagari defaults: Devanagari normalizer, Devanagari prune set, MuRIL, andcc.hi.300.The language-neutral key names have aliases for the earlier Hindi-specific names:
Earlier name
Current name
subword.input_hindi_normsubword.input_target_normsubword.output_hindi_normsubword.output_target_normbaseline.mode: mean_hindibaseline.mode: mean_targetfocus.candidate_pool: hindifocus.candidate_pool: target
Considerations#
focuson a syllable-spaced language: fastText tokenizes on whitespace, so for Vietnamese thecc.vi.300vectors are largely syllable vectors, and tokens that span several syllables fall back to subword composition.method=replaceon a Latin-script language frees far fewer rows than on a language with its own block, because only tokens that carry a diacritic qualify.