-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [tn] support punct * [tn] support punct
- Loading branch information
1 parent
a7d4529
commit c632358
Showing
7 changed files
with
116 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
from unicodedata import category | ||
|
||
from pynini.examples import plurals | ||
from pynini import cross, union, closure, accep | ||
from pynini.lib.pynutil import delete, insert | ||
|
||
from tn.processor import Processor | ||
from tn.utils import get_abs_path, load_labels | ||
|
||
|
||
class Punctuation(Processor): | ||
|
||
def __init__(self, deterministic: bool = False): | ||
""" | ||
Args: | ||
deterministic: if True will provide a single transduction option, | ||
for False multiple transduction are generated (used for audio-based normalization) | ||
""" | ||
super().__init__('p', ordertype="en_tn") | ||
self.deterministic = deterministic | ||
self.build_tagger() | ||
self.build_verbalizer() | ||
|
||
def build_tagger(self): | ||
""" | ||
Finite state transducer for classifying punctuation | ||
e.g. a, -> w { v: "a" } p { v: "," } | ||
""" | ||
s = "!#%&\'()*+,-./:;<=>?@^_`{|}~" | ||
|
||
punct_symbols_to_exclude = ["[", "]", "\"", "\\"] | ||
punct_unicode = [ | ||
chr(i) for i in range(sys.maxunicode) | ||
if category(chr(i)).startswith("P") | ||
and chr(i) not in punct_symbols_to_exclude | ||
] | ||
|
||
whitelist_symbols = load_labels( | ||
get_abs_path("english/data/whitelist/symbol.tsv")) | ||
whitelist_symbols = [x[0] for x in whitelist_symbols] | ||
self.punct_marks = [ | ||
p for p in punct_unicode + list(s) if p not in whitelist_symbols | ||
] | ||
|
||
self.punct = union(*self.punct_marks) | ||
punct = closure(self.punct | cross('\\', '\\\\\\') | cross('"', '\\"'), | ||
1) | ||
|
||
emphasis = ( | ||
accep("<") + | ||
(( | ||
closure(self.NOT_SPACE - union("<", ">"), 1) + # noqa | ||
closure(accep("/"), 0, 1)) # noqa | ||
| (accep("/") + closure(self.NOT_SPACE - union("<", ">"), 1))) + | ||
accep(">")) # noqa | ||
punct = plurals._priority_union(emphasis, punct, closure(self.VCHAR)) | ||
|
||
self.graph = punct | ||
final_graph = insert("v: \"") + punct + insert("\"") | ||
self.tagger = self.add_tokens(final_graph) | ||
|
||
def build_verbalizer(self): | ||
punct = closure(self.punct | cross('\\\\\\', '\\') | cross('\\"', '"'), | ||
1) | ||
verbalizer = delete('v: "') + punct + delete('"') | ||
self.verbalizer = self.delete_tokens(verbalizer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
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 256, 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 256, 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.com"" Biography by Amy Hanson". | ||
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". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,3 @@ smile => smile | |
国 => 国 | ||
A => A | ||
a => a | ||
"HAHAH" => "HAHAH" | ||
"HAHAH," => "HAHAH," |