Skip to content
Merged
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
1 change: 0 additions & 1 deletion tn/english/data/measure/unit_alternatives.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ bq becquerel
cd candela
da dalton
eb exabyte
f degree Fahrenheit
gb gigabyte
g gram
gl gigaliter
Expand Down
47 changes: 27 additions & 20 deletions tn/english/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pynini
from importlib_resources import files
from pynini.lib.pynutil import add_weight, delete
from pynini.lib import pynutil

from tn.english.rules.cardinal import Cardinal
from tn.english.rules.date import Date
Expand Down Expand Up @@ -59,24 +60,30 @@ def build_tagger_and_verbalizer(self):
whitelist = WhiteList()
rang = Range(date=date, time=time)

tagger = (
add_weight(cardinal.tagger, 1.0)
| add_weight(ordinal.tagger, 1.0)
| add_weight(word.tagger, 100)
| add_weight(date.tagger, 0.99)
| add_weight(decimal.tagger, 1.0)
| add_weight(fraction.tagger, 1.0)
| add_weight(time.tagger, 1.00)
| add_weight(measure.tagger, 1.00)
| add_weight(money.tagger, 1.00)
| add_weight(telephone.tagger, 1.00)
| add_weight(electronic.tagger, 1.00)
| add_weight(serial.tagger, 1.01)
| add_weight(whitelist.tagger, 1.00)
| add_weight(rang.tagger, 1.01)
| add_weight(punctuation.tagger, 2.00)
).optimize() + (add_weight(punctuation.tagger, 2.00).plus | self.DELETE_SPACE)
self.tagger = (delete(" ").star + tagger.star) @ self.build_rule(delete(" "), r="[EOS]")
classify = (
pynutil.add_weight(cardinal.tagger, 1.0)
| pynutil.add_weight(ordinal.tagger, 1.0)
| pynutil.add_weight(word.tagger, 100)
| pynutil.add_weight(date.tagger, 0.99)
| pynutil.add_weight(decimal.tagger, 1.0)
| pynutil.add_weight(fraction.tagger, 0.99)
| pynutil.add_weight(time.tagger, 1.00)
| pynutil.add_weight(measure.tagger, 1.00)
| pynutil.add_weight(money.tagger, 1.00)
| pynutil.add_weight(telephone.tagger, 1.00)
| pynutil.add_weight(electronic.tagger, 1.00)
| pynutil.add_weight(serial.tagger, 1.01)
| pynutil.add_weight(whitelist.tagger, 1.00)
| pynutil.add_weight(rang.tagger, 1.0)
).optimize()

punct = pynutil.add_weight(punctuation.tagger, 2.00)
token = pynini.closure(punct) + classify + pynini.closure(punct)
separator = pynutil.delete(self.SPACE) | punct
graph = (
self.DELETE_SPACE + token + pynini.closure(separator + token) + self.DELETE_SPACE
) | punct
self.tagger = graph.optimize() @ self.build_rule(pynutil.delete(" "), r="[EOS]")

classify = (
cardinal.verbalizer
Expand All @@ -103,4 +110,4 @@ def build_tagger_and_verbalizer(self):
classify + (punct.plus | self.INSERT_SPACE)
| punct + (punct.plus | self.DELETE_SPACE)
).star
self.verbalizer = verbalizer @ self.build_rule(delete(" "), r="[EOS]")
self.verbalizer = verbalizer @ self.build_rule(pynutil.delete(" "), r="[EOS]")
2 changes: 1 addition & 1 deletion tn/english/test/data/normalizer.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
this is 12th game, number 256, 2024-05-06, 2021-03-07 31.990 billion. ¾ people like chattts, let's eat at 03:43 p.m. run 10 km, give me $12.345 please, call 123-123-5678-1 Mt Hill "HAHAHA" billion 4 March => this is twelfth game, number two hundred and fifty six, the sixth of may twenty twenty four, the seventh of march twenty twenty one thirty one point nine nine oh billion. three quarters people like chattts, let's eat at three forty three PM run ten kilometers, give me twelve point three four five dollars please, call one two three, one two three, five six seven eight, one Mt Hill "HAHAHA" billion the fourth of march
The National Map, accessed April 1, 2011" Site Description of Koppers Co. From the quartet's recording" Jefferson Friedman: Quartets,"" String Quartet no, Riots again broke out, Atassi resigned, and Syrian independence was deferred until after World War II. 1988 (1988) ( 1988) ( 1988). Starling, Arthur E.( 1988 ). this is 12th game, number 256, 2024-05-06, 2021-03-07 31.990 billion. 3/4 people like chattts Retrieved December 2011. Information on Album" Thepodule.com"" Biography by Amy Hanson". => The National Map, accessed the first of april, twenty eleven" Site Description of Koppers company From the quartet's recording" Jefferson Friedman: Quartets,"" String Quartet no, Riots again broke out, Atassi resigned, and Syrian independence was deferred until after World War two nineteen eighty eight (nineteen eighty eight) ( nineteen eighty eight) ( nineteen eighty eight). Starling, Arthur E.( nineteen eighty eight ). this is twelfth game, number two fifty six, the sixth of may twenty twenty four, the seventh of march twenty twenty one thirty one point nine nine oh billion. three quarters people like chattts Retrieved december twenty eleven. Information on Album" Thepodule dot com"" Biography by Amy Hanson".
The National Map, accessed April 1, 2011" Site Description of Koppers Co. From the quartet's recording" Jefferson Friedman: Quartets,"" String Quartet no, Riots again broke out, Atassi resigned, and Syrian independence was deferred until after World War II. 1988 (1988) ( 1988) ( 1988). Starling, Arthur E.( 1988 ). this is 12th game, number 256, 2024-05-06, 2021-03-07 31.990 billion. 3/4 people like chattts Retrieved December 2011. Information on Album" Thepodule.com"" Biography by Amy Hanson". => The National Map, accessed the first of april, twenty eleven" Site Description of Koppers company From the quartet's recording" Jefferson Friedman: Quartets,"" String Quartet no, Riots again broke out, Atassi resigned, and Syrian independence was deferred until after World War two nineteen eighty eight (nineteen eighty eight) ( nineteen eighty eight) ( nineteen eighty eight). Starling, Arthur E.( nineteen eighty eight ). this is twelfth game, number two hundred fifty six, the sixth of may twenty twenty four, the seventh of march twenty twenty one thirty one point nine nine oh billion. three quarters people like chattts Retrieved december twenty eleven. Information on Album" Thepodule dot com"" Biography by Amy Hanson".
.345" and ".456" "9.456" or 6.7890" => point three four five" and ".four hundred and fifty six" "nine point four five six" or six point seven eight nine oh"
The museum is open Mon.-Sun. children of 3-4 years 123 The plan will help you lose 3-4 pounds the first week, and 1-2 pounds the weeks thereafter. => The museum is open Monday to Sunday children of three to four years one hundred and twenty three The plan will help you lose three to four pounds the first week, and one to two pounds the weeks thereafter.
Try searching for 'Toyota' or 'Investment' => Try searching for 'Toyota' or 'Investment'
Expand Down
Loading