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