Skip to content

Luganda (lg) ITN on the shared Bantu kernel - #545

Open
cal3bdev wants to merge 3 commits into
NVIDIA:staging/bantu_itnfrom
cal3bdev:lg
Open

cal3bdev wants to merge 3 commits into
NVIDIA:staging/bantu_itnfrom
cal3bdev:lg

Conversation

@cal3bdev

@cal3bdev cal3bdev commented Nov 24, 2026 •

Copy link
Copy Markdown

What does this PR do ?

Adds Luganda (lg) inverse text normalization, built on the shared Bantu kernel from #518.
Luganda is a normal NeMo ITN language: its word lists are in lg/data/*.tsv, its grammar
settings are in lg/settings.py, and the grammar is built by the kernel. The only
Luganda-specific code is one small step that runs before the kernel (splitting the
contracted n', "and", off a scale word; see below). No changes to bantu/.

This is stage 2 of the plan agreed with @tbartley94: kernel (#518), then Luganda, then
Swahili. It also includes the companion tutorial notebook
(tutorials/Luganda_ITN_on_the_Bantu_Kernel.ipynb) walking through Luganda on the kernel;
happy to split it into a separate PR if you'd rather review it on its own.

Depends on #544 (a run of number words never starts with a join word). This branch is
built on it, so its one commit shows here until #544 merges; I'll rebase onto
staging/bantu_itn then. Two of the test sentences need that fix.

Collection: ITN

Examples

Spoken Written
amagi abiri amagi 2
ssiringi za uganda abiri 20 UGX
abantu emitwalo abiri abantu 200,000
yampa emitwalo ebiri yampa 20,000 UGX
ssente emitwalo esatu ssente 30,000 UGX
yampa emmere n'emitwalo ebiri yampa emmere ne 20,000 UGX
amagi kkumi n'abiri amagi 12
omuti guli mu nnimiro omuti guli mu nnimiro
omwana ayagala omunnyo omwana ayagala omunnyo

The first two rows are the reason the kernel exists: abiri is 2 after amagi (eggs) but
20 after a currency phrase. The word before a number decides its value.

Supported classes in this PR: cardinal, money (UGX, KES, TZS, USD) and plain words.

What Luganda supplies

  • Word lists (lg/data/): number words per noun class, places (tens, hundreds,
    thousands, ten-thousands), the scale words mitwalo, bukadde and buwumbi with their
    counts, currency phrases, money cues, and spelling variants. All reviewed by a native
    speaker.
  • Settings (lg/settings.py): noun classes, kkumi (ten), the joins na and mu,
    the counted scales and their switches, the largest value (999,999,999,999). Each
    reviewed decision is a comment next to the setting it controls.
  • Payment defaults: bare ssiringi/siringi and bare scale amounts (mitwalo
    ebiri
    ) mean UGX. The longer forms (emitwalo ebiri) count the word before them
    (embuzi emitwalo ebiri = 20,000 goats) unless a money word comes right before
    (yampa, ssente, the payment verbs in cues.tsv).
  • One Luganda pre-step (lg/taggers/tokenize_and_classify.py): Luganda writes "and"
    before a vowel attached to the next word: n'emitwalo, n'omutwalo, n'akakadde.
    Before the kernel reads the sentence, n' (or n) + an augmented scale word (derived
    from the word lists) may be split into ne + the bare scale word. The split is kept only
    where the kernel then converts the amount right after ne (a filter on the classifier's
    output); anywhere else the original words stand. So yampa emmere n'emitwalo ebiri
    becomes yampa emmere ne 20,000 UGX and n'omutwalo gumu becomes ne 10,000 UGX, while
    n'omutwalo gwange, yampa emmere n'omutwalo and n'obukadde bubiri n'ekitundu (held
    back) are left exactly as written. The step is part of the tagger FST, so the export and
    Sparrowhawk get it unchanged. If another language needs it, it can move into the kernel
    then.

Files

nemo_text_processing/inverse_text_normalization/lg/
  settings.py                       grammar shape; load() fills it from data/
  data/numbers/*.tsv, data/money/*.tsv
  taggers/tokenize_and_classify.py  ClassifyFst: the n' split, then the kernel's classifier
  verbalizers/verbalize.py          VerbalizeFst, for pynini_export
  verbalizers/verbalize_final.py    VerbalizeFinalFst
nemo_text_processing/inverse_text_normalization/inverse_normalize.py   'lg' branch and CLI choice
nemo_text_processing/inverse_text_normalization/run_evaluate.py        'lg' choice
tools/text_processing_deployment/pynini_export.py                      'lg' choice and branch
tests/nemo_text_processing/lg/
  data_inverse_text_normalization/test_cases_{cardinal,money,word}.txt
  test_cardinal.py, test_money.py, test_word.py, test_grammar.py
  test_sparrowhawk_inverse_text_normalization.sh
tutorials/Luganda_ITN_on_the_Bantu_Kernel.ipynb                        companion tutorial notebook
Jenkinsfile                         stage: L1: Run all LG ITN tests

Tests

pytest tests/nemo_text_processing/lg --cpu
bash tools/text_processing_deployment/export_grammars.sh --MODE=test --GRAMMARS=itn_grammars --LANGUAGE=lg
  • 233 spoken/written pairs: 130 cardinal, 89 money, 14 words left unchanged. Each test
    also checks that the input has exactly one best reading, as in toy.
  • They include negative cases: a word that looks like a money verb but isn't (mpaka),
    nouns counted with a scale word (embuzi emitwalo ebiri = 20,000, no currency),
    mu as "in" (omuti guli mu nnimiro), and n' + a scale word where no valid amount
    follows (a possessive, a bare scale word, a held-back "and a half" phrase).
  • test_grammar.py: the FAR cache round trip, cased input, the split after repeated
    spaces, the CLI choice and the export verbalizer.
  • 240 tests in all, 100% line coverage of lg/. bantu and toy tests unchanged and
    passing.
  • Sparrowhawk: test_sparrowhawk_inverse_text_normalization.sh passed on the exported
    grammars (cardinal, money, word), run locally in Docker on Linux x86_64; pynini_export.py
    was re-verified after expanding the n' split to singular scale words and replacing the
    unnatural regression strings with speaker-reviewed pairs. The machine runs rootless Docker,
    so two local changes were needed to build and start the container, neither touching the
    grammars or the test: tar --no-same-owner when unpacking protobuf in the image, and no
    --ulimit memlock=-1. The script's PROJECT_DIR defaults to /workspace/tests (with
    hy's default, /workspace/tests/en, neither the case files nor shUnit2 are found when
    run through export_grammars.sh --MODE=test).
  • black and isort with the pre-commit settings, pyflakes: clean.

Test data

Every pair was written for this project and reviewed by a native Luganda speaker; none
comes from an ASR corpus or other training data. Sources used to check linguistic facts
(not copied): Kizito, Okello and Kagumire (2020) on Luganda text normalization, a 2017
Luganda grammar guide, and Ministry of Education P1 mathematics material.

Known limits

Each one has a test showing the current output.

  • A money word two words back: ssente ziri emitwalo esatu -> ssente ziri 30,000
    (no UGX). The money word has to come right before the amount. Fixing this would be a
    kernel change; we'd rather look at it with Swahili first.
  • Bare singular scale words after n': n'omutwalo, n'akakadde without a count stay
    unchanged (n'omutwalo gumu -> ne 10,000 UGX and n'akakadde kamu -> ne 1,000,000 UGX
    convert).
  • Decimals (katonyeze): not common in Luganda speech, so they are left to a
    follow-up PR. Reviewed cases exist; they need new kernel code (a decimal tagger).
  • Cased input and attached punctuation: input_case='cased' builds the same grammar;
    words with capitals or attached punctuation pass through unchanged.

Questions for the reviewer

  1. CI cache: the lg tests build the grammar in the test run (about a minute), like
    the Bantu kernel stage, so there is no LG_TN_CACHE path. Would you like a cached
    grammar and an L0 stage instead? The path is yours to set.
  2. Language code: lg (ISO 639-1). The profile's internal name matches.

Not in this PR

  • Swahili: its own PR next, with Ernest Omondi's reviewed cases.
  • Luganda decimals: after the kernel gets a decimal tagger.
  • NeMo docs (separate repo): list Luganda once this merges.

Before your PR is "Ready for review"

Pre checks:

  • Have you signed your commits? Use git commit -s to sign.
  • Do all unittests finish successfully before sending PR?
    1. pytest or (if your machine does not have GPU) pytest --cpu from the root folder (given you marked your test cases accordingly @pytest.mark.run_only_on('CPU')).
    2. Sparrowhawk tests bash tools/text_processing_deployment/export_grammars.sh --MODE=test ...
  • If you are adding a new feature: Have you added test cases for both pytest and Sparrowhawk here.
  • Have you added __init__.py for every folder and subfolder, including data folder which has .TSV files?
  • Have you followed codeQL results and removed unused variables and imports (report is at the bottom of the PR in github review box) ?
  • Have you added the correct license header Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. to all newly added Python files? (year 2026, with the Crane AI Labs line)
  • If you copied nemo_text_processing/text_normalization/en/graph_utils.py your header's second line should be Copyright 2015 and onwards Google, Inc.. n/a, imported, not copied
  • Remove import guards (try import: ... except: ...) if not already done. None present
  • If you added a new language or a new feature please update the NeMo documentation (lives in different repo). After this merges
  • Have you added your language support to tools/text_processing_deployment/pynini_export.py.

PR Type:

  • New Feature
  • Bugfix
  • Documentation
  • Test

If you haven't finished some of the above items you can still open "Draft" PR.

A join word such as Luganda "mu" ("in") is also an ordinary word. A run of
number words could start with one, so "kasa vo mina epi" had two equally best
readings: "vo" as a word followed by 20,000 XTS, or "vo mina epi" as one
malformed run left unchanged. The runtime picked one silently.

Runs now start with a number word that is not a join. Joins before the first
run with no ordinary word (or the whole input) are words. On 12,121 generated
inputs the output is unchanged; the one difference is that "koin ke mina
otodeka" now has one best reading instead of two (same text). An input that
starts with a join and then an amount now converts: "vo mina epi" ->
"vo 20,000 XTS" (was left unchanged).

Signed-off-by: Lwanga Caleb <[email protected]>
Adds Luganda as a NeMo ITN language built on the Bantu kernel: word lists
in lg/data/*.tsv, grammar settings in lg/settings.py, and the standard
ClassifyFst / VerbalizeFst / VerbalizeFinalFst wrappers. No changes to bantu/.

The only Luganda-specific step splits contracted "and" off a plural scale
word (n'emitwalo ebiri -> ne 20,000 UGX). The split is kept only where the
kernel converts the amount after it; otherwise the words are left unchanged.

Registered in InverseNormalizer, run_evaluate.py, pynini_export.py and the
Jenkinsfile. Tests: 237 reviewed spoken/written pairs (cardinal, money,
word), each with exactly one best reading; grammar tests for caching, cased
input and the export verbalizer; a Sparrowhawk test script.

Signed-off-by: Lwanga Caleb <[email protected]>
…dd tutorial notebook

- Extend split_contracted_and to singular augmented scale words present in the
  Luganda word lists (omutwalo, akakadde, akawumbi), so n'omutwalo gumu and
  n'akakadde kamu normalize to money while bare forms stay unchanged.
- Replace unnatural n' regression strings with native-speaker-reviewed Luganda
  test cases (233 pairs total: 130 cardinal, 89 money, 14 word).
- Add the companion tutorial notebook tutorials/Luganda_ITN_on_the_Bantu_Kernel.ipynb.

Signed-off-by: Lwanga Caleb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant