From 08a991551f5faba2e8f0ec35a484ed86a6cdde0a Mon Sep 17 00:00:00 2001 From: Udaya Tejas Date: Tue, 17 Nov 2026 11:54:34 -0500 Subject: [PATCH] en TN: verbalize the base of ^2/^3 powers "2^2" was normalized to "2 squared" and "3^2 + 4^2 = 5^2" to "3 squared plus 4 squared equal sign 5 squared": the power rule in the serial grammar copied the base through unchanged, so digits leaked into the spoken output. Verbalize the base with the serial number graph (with an optional decimal part, so "1.5^3" -> "one point five cubed"). Bases without digits such as "x^2" keep the previous behavior. Signed-off-by: Udaya Tejas --- .../text_normalization/en/taggers/serial.py | 8 ++++++-- .../en/data_text_normalization/test_cases_serial.txt | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nemo_text_processing/text_normalization/en/taggers/serial.py b/nemo_text_processing/text_normalization/en/taggers/serial.py index 4a5d6bb9d..55adc6b7a 100644 --- a/nemo_text_processing/text_normalization/en/taggers/serial.py +++ b/nemo_text_processing/text_normalization/en/taggers/serial.py @@ -63,9 +63,13 @@ def _build_serial_graph( ).optimize() serial_graph = pynutil.add_weight(serial_graph, MIN_POS_WEIGHT) - serial_graph |= ( - pynini.closure(NEMO_NOT_SPACE, 1) + (pynini.cross("^2", " squared") | pynini.cross("^3", " cubed")).optimize() + # the base of a power is verbalized too, e.g. "3^2" -> "three squared", "1.5^2" -> "one point five squared" + digit = pynini.compose(NEMO_DIGIT, num_graph) + power_base = num_graph + pynini.closure( + pynini.cross(".", " point ") + digit + pynini.closure(pynutil.insert(" ") + digit), 0, 1 ) + power_base |= pynini.difference(pynini.closure(NEMO_NOT_SPACE, 1), NEMO_SIGMA + NEMO_DIGIT + NEMO_SIGMA) + serial_graph |= (power_base + (pynini.cross("^2", " squared") | pynini.cross("^3", " cubed"))).optimize() serial_graph = ( pynini.closure((serial_graph | num_graph | alphas) + delimiter) diff --git a/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt b/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt index f142ceb7e..3143edf32 100644 --- a/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt +++ b/tests/nemo_text_processing/en/data_text_normalization/test_cases_serial.txt @@ -30,4 +30,8 @@ a 4-kilogram bag~a four-kilogram bag 123/261788/2021~one hundred twenty three/two six one seven eight eight/two thousand twenty one 2*8~two asterisk eight my pnr is t2000~my pnr is t two thousand -your otp is ab9453~your otp is ab nine four five three \ No newline at end of file +your otp is ab9453~your otp is ab nine four five three +2^2~two squared +the area is 5^2~the area is five squared +1.5^3~one point five cubed +x^2~x squared \ No newline at end of file