Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pipeline {
HY_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/03-12-24-0'
MR_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/03-12-24-1'
JA_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/10-17-24-1'
KO_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/04-23-26-0'
HI_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/04-23-26-0'
TE_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/07-21-26-0'
HI_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/06-04-26-5'
KO_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/06-04-25-6'
DEFAULT_TN_CACHE='/home/jenkins/TestData/text_norm/ci/grammars/06-08-23-0'
Expand Down Expand Up @@ -112,6 +115,30 @@ pipeline {
}
}
}
stage('L0: Create TE TN/ITN Grammars') {
when {
anyOf {
branch 'main'
branch 'staging/**'
branch 'staging_*'
changeRequest target: 'main'
}
}
failFast true
parallel {
stage('L0: TE TN grammars') {
steps {
sh 'CUDA_VISIBLE_DEVICES="" python nemo_text_processing/text_normalization/normalize.py --lang=te --text="౧" --cache_dir ${TE_TN_CACHE}'
}
}
// stage('L0: TE ITN grammars') {
// steps {
// sh 'CUDA_VISIBLE_DEVICES="" python nemo_text_processing/inverse_text_normalization/inverse_normalize.py --lang=te --text="ఒకటి" --cache_dir ${TE_TN_CACHE}'
// }
// }

}
}

stage('L0: Create DE/ES TN/ITN Grammars') {
when {
Expand Down Expand Up @@ -407,6 +434,11 @@ pipeline {
steps {
sh 'CUDA_VISIBLE_DEVICES="" pytest tests/nemo_text_processing/hi/ -m "not pleasefixme" --cpu --tn_cache_dir ${HI_TN_CACHE}'
}
}
stage('L1: Run all TE TN/ITN tests (restore grammars from cache)') {
steps {
sh 'CUDA_VISIBLE_DEVICES="" pytest tests/nemo_text_processing/te/ -m "not pleasefixme" --cpu --tn_cache_dir ${TE_TN_CACHE}'
}
}
stage('L1: Run all Codeswitched ES/EN TN/ITN tests (restore grammars from cache)') {
steps {
Expand Down
16 changes: 14 additions & 2 deletions nemo_text_processing/text_normalization/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(

if post_process:
self.post_processor = PostProcessingFst(cache_dir=cache_dir, overwrite_cache=overwrite_cache)

elif lang == 'it':
from nemo_text_processing.text_normalization.it.taggers.tokenize_and_classify import ClassifyFst
from nemo_text_processing.text_normalization.it.verbalizers.verbalize_final import VerbalizeFinalFst
Expand All @@ -191,6 +192,13 @@ def __init__(
elif lang == 'ko':
from nemo_text_processing.text_normalization.ko.taggers.tokenize_and_classify import ClassifyFst
from nemo_text_processing.text_normalization.ko.verbalizers.verbalize_final import VerbalizeFinalFst
elif lang == 'te':
from nemo_text_processing.text_normalization.te.taggers.tokenize_and_classify import ClassifyFst
from nemo_text_processing.text_normalization.te.verbalizers.post_processing import PostProcessingFst
from nemo_text_processing.text_normalization.te.verbalizers.verbalize_final import VerbalizeFinalFst

if post_process:
self.post_processor = PostProcessingFst(cache_dir=cache_dir, overwrite_cache=overwrite_cache)
else:
raise NotImplementedError(f"Language {lang} has not been supported yet.")

Expand Down Expand Up @@ -391,7 +399,11 @@ def normalize(
return text
output = SPACE_DUP.sub(' ', output[1:])

if self.lang in ["en", "hi", "vi"] and hasattr(self, 'post_processor') and self.post_processor is not None:
if (
self.lang in ["en", "hi", "te", "vi"]
and hasattr(self, 'post_processor')
and self.post_processor is not None
):
output = self.post_process(output)

if punct_post_process:
Expand Down Expand Up @@ -737,7 +749,7 @@ def parse_args():
parser.add_argument(
"--language",
help="language",
choices=["en", "de", "es", "fr", "hu", "sv", "zh", "ar", "it", "hy", "ja", "hi", "ko", "vi", "pt"],
choices=["en", "de", "es", "fr", "hu", "sv", "zh", "ar", "it", "hy", "ja", "hi", "te", "ko", "vi", "pt"],
default="en",
type=str,
)
Expand Down
2 changes: 1 addition & 1 deletion nemo_text_processing/text_normalization/run_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_args():
parser.add_argument(
"--lang",
help="language",
choices=['ar', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ru', 'sv', 'zh', 'hy', 'hi', 'ko', 'vi', 'pt'],
choices=['ar', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ru', 'sv', 'zh', 'hy', 'hi', 'te', 'ko', 'vi', 'pt'],
default="en",
type=str,
)
Expand Down
13 changes: 13 additions & 0 deletions nemo_text_processing/text_normalization/te/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2026, NVIDIA CORPORATION. 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2026, NVIDIA CORPORATION. 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.
18 changes: 18 additions & 0 deletions nemo_text_processing/text_normalization/te/data/numbers/digit.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
1 ఒకటి
2 రెండు
3 మూడు
4 నాలుగు
5 ఐదు
6 ఆరు
7 ఏడు
8 ఎనిమిది
9 తొమ్మిది
౧ ఒకటి
౨ రెండు
౩ మూడు
౪ నాలుగు
౫ ఐదు
౬ ఆరు
౭ ఏడు
౮ ఎనిమిది
౯ తొమ్మిది
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
hundred వంద
hundred_prefix నూట
hundreds_plural వందలు
hundreds_before వందల
thousand వెయ్యి
thousands_plural వేలు
thousands_before వేల
lakh లక్ష
lakh_before_digit లక్షా
lakhs_plural లక్షలు
lakhs_before లక్షల
crore కోటి
crores_plural కోట్లు
crores_before కోట్ల
one ఒక
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
౧౦ పది
౧౧ పదకొండు
౧౨ పన్నెండు
౧౩ పదమూడు
౧౪ పద్నాలుగు
౧౫ పదిహేను
౧౬ పదహారు
౧౭ పదిహేడు
౧౮ పధ్ధెనిమిది
౧౯ పంతొమ్మిది
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
10 పది
11 పదకొండు
12 పన్నెండు
13 పదమూడు
14 పద్నాలుగు
15 పదిహేను
16 పదహారు
17 పదిహేడు
18 పధ్ధెనిమిది
19 పంతొమ్మిది
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
21 ఇరవై ఒక
31 ముప్పై ఒక
41 నలభై ఒక
51 యాభై ఒక
61 అరవై ఒక
71 డెబ్బై ఒక
81 ఎనభై ఒక
91 తొంభై ఒక
౨౧ ఇరవై ఒక
౩౧ ముప్పై ఒక
౪౧ నలభై ఒక
౫౧ యాభై ఒక
౬౧ అరవై ఒక
౭౧ డెబ్బై ఒక
౮౧ ఎనభై ఒక
౯౧ తొంభై ఒక
16 changes: 16 additions & 0 deletions nemo_text_processing/text_normalization/te/data/numbers/ties.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
2 ఇరవై
3 ముప్పై
4 నలభై
5 యాభై
6 అరవై
7 డెబ్బై
8 ఎనభై
9 తొంభై
౨ ఇరవై
౩ ముప్పై
౪ నలభై
౫ యాభై
౬ అరవై
౭ డెబ్బై
౮ ఎనభై
౯ తొంభై
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 సున్నా
౦ సున్నా
145 changes: 145 additions & 0 deletions nemo_text_processing/text_normalization/te/graph_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
# Copyright 2015 and onwards Google, Inc.
#
# 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
from pathlib import Path
from typing import Dict

import pynini
from pynini import Far
from pynini.export import export
from pynini.lib import byte, pynutil, utf8

NEMO_CHAR = utf8.VALID_UTF8_CHAR
NEMO_DIGIT = byte.DIGIT

# Telugu native digits (౦, ౧, ౨, ౩, ౪, ౫, ౬, ౭, ౮, ౯)
NEMO_TE_DIGIT = pynini.union("౦", "౧", "౨", "౩", "౪", "౫", "౬", "౭", "౮", "౯").optimize()

# Combined Telugu and Arabic digits for graphs that need to accept both
NEMO_ALL_DIGIT = pynini.union(NEMO_TE_DIGIT, NEMO_DIGIT).optimize()
NEMO_ALL_ZERO = pynini.union("౦", "0").optimize()

NEMO_NON_BREAKING_SPACE = u"\u00a0"
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_SIGMA = pynini.closure(NEMO_CHAR)

delete_space = pynutil.delete(pynini.closure(NEMO_WHITE_SPACE))
insert_space = pynutil.insert(" ")
delete_extra_space = pynini.cross(pynini.closure(NEMO_WHITE_SPACE, 1), " ")

MIN_NEG_WEIGHT = -0.0001


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)


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 nemo_text_processing/text_normalization/te/taggers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2026, NVIDIA CORPORATION. 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.
Loading