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
9 changes: 9 additions & 0 deletions nemo_text_processing/text_normalization/en/taggers/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
convert_space,
)
from nemo_text_processing.text_normalization.en.utils import get_abs_path, load_labels
from nemo_text_processing.text_normalization.en.verbalizers.ordinal import OrdinalFst as OrdinalVerbalizer


def _leading_zero_graph(cardinal: GraphFst) -> "pynini.FstLike":
Expand Down Expand Up @@ -183,6 +184,14 @@ def __init__(self, cardinal: GraphFst, ordinal: GraphFst, deterministic: bool =
serial_graph |= pynini.compose(graph_with_space, serial_graph_alnum.optimize()).optimize()
serial_graph = pynini.compose(pynini.closure(NEMO_NOT_SPACE, 2), serial_graph).optimize()

# ordinal followed by hyphenated words, e.g. "3rd-party" -> "third-party"
ordinal_num = pynini.compose(
pynutil.insert('integer: "') + ordinal.graph + pynutil.insert('"'),
OrdinalVerbalizer(deterministic=deterministic).graph,
)
ordinal_compound = ordinal_num + pynini.closure(pynini.accep("-") + alphas, 1)
serial_graph |= pynutil.add_weight(ordinal_compound, MIN_NEG_WEIGHT).optimize()

# this is not to verbolize "/" as "slash" in cases like "import/export"
serial_graph = pynini.compose(
pynini.difference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ 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
3rd-party~third-party
a 21st-century novel~a twenty first-century novel
19th-century art~nineteenth-century art
the 2nd-largest city~the second-largest city
1st-class-mail~first-class-mail