Skip to content

De itn cardinal decouple - #484

Open
adelina23dunina wants to merge 14 commits into
NVIDIA:staging/de_tn_itn_v2from
adelina23dunina:de_itn_cardinal_decouple
Open

De itn cardinal decouple#484
adelina23dunina wants to merge 14 commits into
NVIDIA:staging/de_tn_itn_v2from
adelina23dunina:de_itn_cardinal_decouple

Conversation

@adelina23dunina

Copy link
Copy Markdown

What does this PR do ?

Replace coupled German ITN Cardinal in de/ with the independent grammar from ger/ (own graphs, no invert of TN Cardinal).

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')). - Yes
    2. Sparrowhawk tests bash tools/text_processing_deployment/export_grammars.sh --MODE=test ... - No
  • 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?
  • 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.. See an example here.
  • Remove import guards (try import: ... except: ...) if not already done.
  • If you added a new language or a new feature please update the NeMo documentation (lives in different repo).
  • Have you added your language support to tools/text_processing_deployment/pynini_export.py.

Notes:

  • Cardinal pytest only (this PR is Cardinal-only): pytest tests/nemo_text_processing/de/test_cardinal.py --cpu --cache-clear → 120 passed (ITN + TN). Full de/ suite not required for this class PR.
  • Updated tests/nemo_text_processing/de/data_inverse_text_normalization/test_cases_cardinal.txt (same format Sparrowhawk uses).
  • Sparrowhawk: FAR export succeeded; Docker image build fails (fst/fst.h). Still working on this. Opening as Draft if needed.
  • Not a new language: production de Cardinal is replaced. pynini_export.py already supports de. Docs not updated.
  • ger/ is left in place as the draft for later classes.
  • Copied graph_utils.py from ger into de (includes Google copyright line where applicable).
  • Will address CodeQL on the PR if it flags anything.

PR Type:

  • New Feature
  • Bugfix
  • Documentation
  • Test

Signed-off-by: Adelina Dunina <adunina@nvidia.com>
@adelina23dunina
adelina23dunina force-pushed the de_itn_cardinal_decouple branch from 0d2d230 to 36d900d Compare September 4, 2026 19:02
@adelina23dunina
adelina23dunina changed the base branch from main to staging/de_tn_itn_v2 September 4, 2026 19:03
@@ -0,0 +1,17 @@
null 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have 0 be a standalone file, 1-9 from this file be replaced by the digits file, and 10-12 be a separate irregular teens file

@@ -0,0 +1,72 @@
12 21

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have this be a function in the script instead of a file

@@ -0,0 +1,9 @@
eins 01

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this file for now. when we get to date, we can create rules to build it from digits instead

@@ -0,0 +1,8 @@
zwanzig 20

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use the tens file + delete 0 to replace this file

@@ -0,0 +1,102 @@
Nummer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this from this PR and we can review in the context of measure instead

@@ -1,4 +1,4 @@
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not change copyright date from files that already existed before. always good to make sure that the copyright overall matches the standard

Args:
tn_cardinal_verbalizer: TN cardinal verbalizer
Finite state transducer for verbalizing cardinal numbers. Note that the verbalizer retains period-separated formatting.
e.g. 'cardinal { negative: "-" integer: "1.234.512.102" }' -> -1.234.512.102

@mgrafu mgrafu Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention is 'negative: true' comes from the tagger, then verbalizer turns that into the minus sign

)

# handles all elements of a cardinal integer
integer_chars = NEMO_DIGIT | pynini.accep(".")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can look at English. accepting NEMO_NOT_QUOTE might be enough


# Handles noun + number combinations, where the noun forces full denormalization
# The nouns are implemented as a .tsv list
nouns_forcing_denormalization = pynini.string_file(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather change this to measure too


class CardinalFst(GraphFst):
"""
Finite state transducer for classifying cardinals. Numbers below ten are not converted.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep the original definition and add examples as needed

self.graph_single_and_double_digits = graph_single_and_double_digits.optimize()

hundert = pynini.accep("hundert") | pynini.accep("ein hundert")
hundreds = (pynini.cross(hundert, "100")) | (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not hardcode any terms and use tsv's instead

adelina23dunina and others added 12 commits September 4, 2026 17:01
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
Signed-off-by: Adelina Dunina <adunina@nvidia.com>
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.

2 participants