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
8 changes: 6 additions & 2 deletions nemo_text_processing/text_normalization/en/taggers/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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