-
Notifications
You must be signed in to change notification settings - Fork 177
Added cardinal semiotic class for te ITN #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaya-TN
wants to merge
3
commits into
NVIDIA:staging/telugu_itn_v1
Choose a base branch
from
jaya-TN:feat-te-itn-cardinal-v2
base: staging/telugu_itn_v1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ def parse_args(): | |
| "fr", | ||
| "hi", | ||
| "hi_en", | ||
| "te", | ||
| "hy", | ||
| "ko", | ||
| "mr", | ||
|
|
||
17 changes: 17 additions & 0 deletions
17
nemo_text_processing/inverse_text_normalization/te/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from nemo_text_processing.inverse_text_normalization.te.taggers.tokenize_and_classify import ClassifyFst | ||
| from nemo_text_processing.inverse_text_normalization.te.verbalizers.verbalize import VerbalizeFst | ||
| from nemo_text_processing.inverse_text_normalization.te.verbalizers.verbalize_final import VerbalizeFinalFst |
13 changes: 13 additions & 0 deletions
13
nemo_text_processing/inverse_text_normalization/te/data/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
13 changes: 13 additions & 0 deletions
13
nemo_text_processing/inverse_text_normalization/te/data/numbers/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
5 changes: 5 additions & 0 deletions
5
nemo_text_processing/inverse_text_normalization/te/data/numbers/case_suffix.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| కి | ||
| కు | ||
| లో | ||
| తో | ||
| కోసం |
3 changes: 3 additions & 0 deletions
3
nemo_text_processing/inverse_text_normalization/te/data/numbers/crore.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| కోట్ల | ||
| కోట్లు | ||
| కోటి ౦౦౦౦౦౦౧ |
9 changes: 9 additions & 0 deletions
9
nemo_text_processing/inverse_text_normalization/te/data/numbers/digit.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ఒకటి ౧ | ||
| రెండు ౨ | ||
| మూడు ౩ | ||
| నాలుగు ౪ | ||
| ఐదు ౫ | ||
| ఆరు ౬ | ||
| ఏడు ౭ | ||
| ఎనిమిది ౮ | ||
| తొమ్మిది ౯ |
9 changes: 9 additions & 0 deletions
9
nemo_text_processing/inverse_text_normalization/te/data/numbers/digit_people.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ఇద్దరు ౨ | ||
| ముగ్గురు ౩ | ||
| నలుగురు ౪ | ||
| ఐదుగురు ౫ | ||
| ఆరుగురు ౬ | ||
| ఏడుగురు ౭ | ||
| ఎనిమిదుగురు ౮ | ||
| తొమ్మిదుగురు ౯ | ||
| పది మంది ౧౦ |
5 changes: 5 additions & 0 deletions
5
nemo_text_processing/inverse_text_normalization/te/data/numbers/hundred.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| వందల | ||
| వందలు | ||
| నూట ౧ | ||
| వంద ౧ | ||
| నూరు ౧ |
4 changes: 4 additions & 0 deletions
4
nemo_text_processing/inverse_text_normalization/te/data/numbers/lakh.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| లక్షల | ||
| లక్షలు | ||
| లక్ష ౦౧ | ||
| లక్షా ౦౧ |
2 changes: 2 additions & 0 deletions
2
nemo_text_processing/inverse_text_normalization/te/data/numbers/special_numbers.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| పంతొమ్మిది ౧౯ | ||
| ఒక ౧ |
18 changes: 18 additions & 0 deletions
18
nemo_text_processing/inverse_text_normalization/te/data/numbers/teens_and_ties.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| పది ౧౦ | ||
| పదకొండు ౧౧ | ||
| పన్నెండు ౧౨ | ||
| పదమూడు ౧౩ | ||
| పద్నాలుగు ౧౪ | ||
| పదిహేను ౧౫ | ||
| పదహారు ౧౬ | ||
| పదిహేడు ౧౭ | ||
| పద్దెనిమిది ౧౮ | ||
| పందొమ్మిది ౧౯ | ||
| ఇరవై ౨౦ | ||
| ముప్పై ౩౦ | ||
| నలభై ౪౦ | ||
| యాభై ౫౦ | ||
| అరవై ౬౦ | ||
| డెబ్బై ౭౦ | ||
| ఎనభై ౮౦ | ||
| తొంభై ౯౦ |
3 changes: 3 additions & 0 deletions
3
nemo_text_processing/inverse_text_normalization/te/data/numbers/thousand.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| వేల | ||
| వేలు | ||
| వెయ్యి ౦౧ |
8 changes: 8 additions & 0 deletions
8
nemo_text_processing/inverse_text_normalization/te/data/numbers/ties_prefix.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ఇరవై ౨ | ||
| ముప్పై ౩ | ||
| నలభై ౪ | ||
| యాభై ౫ | ||
| అరవై ౬ | ||
| డెబ్బై ౭ | ||
| ఎనభై ౮ | ||
| తొంభై ౯ |
1 change: 1 addition & 0 deletions
1
nemo_text_processing/inverse_text_normalization/te/data/numbers/zero.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| సున్నా ౦ |
195 changes: 195 additions & 0 deletions
195
nemo_text_processing/inverse_text_normalization/te/graph_utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import logging | ||
| import os | ||
| import string | ||
| from pathlib import Path | ||
| from typing import Dict | ||
|
|
||
| import pynini | ||
| from pynini import Far | ||
| from pynini.export import export | ||
| from pynini.lib import pynutil, utf8 | ||
|
|
||
| from nemo_text_processing.inverse_text_normalization.te.utils import load_labels | ||
|
|
||
| NEMO_CHAR = utf8.VALID_UTF8_CHAR | ||
|
|
||
| NEMO_TE_DIGIT = pynini.union("౦", "౧", "౨", "౩", "౪", "౫", "౬", "౭", "౮", "౯").optimize() | ||
|
|
||
| NEMO_HEX = pynini.union(*string.hexdigits).optimize() | ||
| NEMO_NON_BREAKING_SPACE = u"\u00a0" | ||
| NEMO_ZWNJ = u"\u200c" | ||
| NEMO_SPACE = " " | ||
| NEMO_WHITE_SPACE = pynini.union(" ", "\t", "\n", "\r", u"\u00a0").optimize() | ||
| NEMO_NOT_SPACE = pynini.difference(NEMO_CHAR, NEMO_WHITE_SPACE).optimize() | ||
| NEMO_NOT_QUOTE = pynini.difference(NEMO_CHAR, r'"').optimize() | ||
|
|
||
| NEMO_PUNCT = pynini.union(*map(pynini.escape, string.punctuation)).optimize() | ||
| NEMO_GRAPH = pynini.union(NEMO_CHAR, NEMO_PUNCT).optimize() | ||
|
|
||
| NEMO_SIGMA = pynini.closure(NEMO_CHAR) | ||
|
|
||
| delete_space = pynutil.delete(pynini.closure(NEMO_WHITE_SPACE)) | ||
| delete_zero_or_one_space = pynutil.delete(pynini.closure(NEMO_WHITE_SPACE, 0, 1)) | ||
| insert_space = pynutil.insert(" ") | ||
| delete_extra_space = pynini.cross(pynini.closure(NEMO_WHITE_SPACE, 1), " ") | ||
| delete_preserve_order = pynini.closure( | ||
| pynutil.delete(" preserve_order: true") | ||
| | (pynutil.delete(" field_order: \"") + NEMO_NOT_QUOTE + pynutil.delete("\"")) | ||
| ) | ||
|
|
||
|
|
||
| MIN_NEG_WEIGHT = -0.0001 | ||
| MIN_POS_WEIGHT = 0.0001 | ||
| INPUT_CASED = "cased" | ||
| INPUT_LOWER_CASED = "lower_cased" | ||
| MINUS = pynini.union("ఋణాత్మక", "మైనస్").optimize() | ||
|
|
||
|
|
||
| def generator_main(file_name: str, graphs: Dict[str, 'pynini.FstLike']): | ||
| """ | ||
| Exports graph as OpenFst finite state archive (FAR) file with given file name and rule name. | ||
|
|
||
| Args: | ||
| file_name: exported file name | ||
| graphs: Mapping of a rule name and Pynini WFST graph to be exported | ||
| """ | ||
| exporter = export.Exporter(file_name) | ||
| for rule, graph in graphs.items(): | ||
| exporter[rule] = graph.optimize() | ||
| exporter.close() | ||
| logging.info(f'Created {file_name}') | ||
|
|
||
|
|
||
| def convert_space(fst) -> 'pynini.FstLike': | ||
| """ | ||
| Converts space to nonbreaking space. | ||
| Used only in tagger grammars for transducing token values within quotes, e.g. name: "hello kitty" | ||
| This is making transducer significantly slower, so only use when there could be potential spaces within quotes, otherwise leave it. | ||
|
|
||
| Args: | ||
| fst: input fst | ||
|
|
||
| Returns output fst where breaking spaces are converted to non breaking spaces | ||
| """ | ||
| return fst @ pynini.cdrewrite(pynini.cross(NEMO_SPACE, NEMO_NON_BREAKING_SPACE), "", "", NEMO_SIGMA) | ||
|
|
||
|
|
||
| def string_map_cased(input_file: str, input_case: str = INPUT_LOWER_CASED): | ||
| labels = load_labels(input_file) | ||
|
|
||
| if input_case == INPUT_CASED: | ||
| additional_labels = [] | ||
| for written, spoken, *weight in labels: | ||
| written_capitalized = written[0].upper() + written[1:] | ||
| additional_labels.extend( | ||
| [ | ||
| [written_capitalized, spoken.capitalize()], | ||
| [ | ||
| written_capitalized, | ||
| spoken.upper().replace(" AND ", " and "), | ||
| ], | ||
| ] | ||
| ) | ||
|
|
||
| spoken_no_space = spoken.replace(" ", "") | ||
|
|
||
| if len(spoken) == (2 * len(spoken_no_space) - 1): | ||
| logging.debug(f"This is weight {weight}") | ||
| if len(weight) == 0: | ||
| additional_labels.extend( | ||
| [[written, spoken_no_space], [written_capitalized, spoken_no_space.upper()]] | ||
| ) | ||
| else: | ||
| additional_labels.extend( | ||
| [ | ||
| [written, spoken_no_space, weight[0]], | ||
| [written_capitalized, spoken_no_space.upper(), weight[0]], | ||
| ] | ||
| ) | ||
| labels += additional_labels | ||
|
|
||
| whitelist = pynini.string_map(labels).invert().optimize() | ||
| return whitelist | ||
|
|
||
|
|
||
| class GraphFst: | ||
| """ | ||
| Base class for all grammar fsts. | ||
|
|
||
| Args: | ||
| name: name of grammar class | ||
| kind: either 'classify' or 'verbalize' | ||
| deterministic: if True will provide a single transduction option, | ||
| for False multiple transduction are generated (used for audio-based normalization) | ||
| """ | ||
|
|
||
| def __init__(self, name: str, kind: str, deterministic: bool = True): | ||
| self.name = name | ||
| self.kind = kind | ||
| self._fst = None | ||
| self.deterministic = deterministic | ||
|
|
||
| self.far_path = Path(os.path.dirname(__file__) + '/grammars/' + kind + '/' + name + '.far') | ||
| if self.far_exist(): | ||
| self._fst = Far(self.far_path, mode="r", arc_type="standard", far_type="default").get_fst() | ||
|
|
||
| def far_exist(self) -> bool: | ||
| """ | ||
| Returns true if FAR can be loaded | ||
| """ | ||
| return self.far_path.exists() | ||
|
|
||
| @property | ||
| def fst(self) -> 'pynini.FstLike': | ||
| return self._fst | ||
|
|
||
| @fst.setter | ||
| def fst(self, fst): | ||
| self._fst = fst | ||
|
|
||
| def add_tokens(self, fst) -> 'pynini.FstLike': | ||
| """ | ||
| Wraps class name around to given fst | ||
|
|
||
| Args: | ||
| fst: input fst | ||
|
|
||
| Returns: | ||
| Fst: fst | ||
| """ | ||
| return pynutil.insert(f"{self.name} {{ ") + fst + pynutil.insert(" }") | ||
|
|
||
| def delete_tokens(self, fst) -> 'pynini.FstLike': | ||
| """ | ||
| Deletes class name wrap around output of given fst | ||
|
|
||
| Args: | ||
| fst: input fst | ||
|
|
||
| Returns: | ||
| Fst: fst | ||
| """ | ||
| res = ( | ||
| pynutil.delete(f"{self.name}") | ||
| + delete_space | ||
| + pynutil.delete("{") | ||
| + delete_space | ||
| + fst | ||
| + delete_space | ||
| + pynutil.delete("}") | ||
| ) | ||
| return res @ pynini.cdrewrite(pynini.cross(u"\u00a0", " "), "", "", NEMO_SIGMA) |
13 changes: 13 additions & 0 deletions
13
nemo_text_processing/inverse_text_normalization/te/taggers/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.