Skip to content

Commit bfa8eef

Browse files
folivoramanhpre-commit-ci[bot]
authored andcommitted
Add Vietnamese measure text normalization support (#307)
* Add Vietnamese measure text normalization support - Added measure tagger and verbalizer for Vietnamese TN - Updated money tagger and verbalizer to handle per-unit measurements - Added test cases for measure normalization - Updated fraction handling for better integration - Added data files for measurements, prefixes, and per-unit bases Signed-off-by: folivoramanh <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: folivoramanh <[email protected]> * add test case for range measure Signed-off-by: folivoramanh <[email protected]> * additional support for cardinal and remove duplicate test case Signed-off-by: folivoramanh <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refractor cardinal and add test cases Signed-off-by: folivoramanh <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove duplicate lines in run_eval file Signed-off-by: folivoramanh <[email protected]> * refractor minor code Signed-off-by: folivoramanh <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add measure support for unit per unit cases Signed-off-by: folivoramanh <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: folivoramanh <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Mariana Graterol Fuenmayor <[email protected]>
1 parent af2082d commit bfa8eef

31 files changed

+756
-163
lines changed

nemo_text_processing/text_normalization/data_loader_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def evaluate(preds: List[str], labels: List[str], input: Optional[List[str]] = N
140140
acc = acc + 1
141141
else:
142142
if input:
143-
print(f"inpu: {json.dumps(input[i])}")
144-
print(f"gold: {json.dumps(label_norm)}")
145-
print(f"pred: {json.dumps(pred_norm)}")
143+
print(f"input: {json.dumps(input[i], ensure_ascii=True)}")
144+
print(f"gold: {json.dumps(label_norm, ensure_ascii=True)}")
145+
print(f"pred: {json.dumps(pred_norm, ensure_ascii=True)}")
146146
return acc / nums
147147

148148

nemo_text_processing/text_normalization/normalize.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ def __init__(
176176
from nemo_text_processing.text_normalization.ja.verbalizers.verbalize_final import VerbalizeFinalFst
177177
elif lang == 'vi':
178178
from nemo_text_processing.text_normalization.vi.taggers.tokenize_and_classify import ClassifyFst
179+
from nemo_text_processing.text_normalization.vi.verbalizers.post_processing import PostProcessingFst
179180
from nemo_text_processing.text_normalization.vi.verbalizers.verbalize_final import VerbalizeFinalFst
181+
182+
if post_process:
183+
self.post_processor = PostProcessingFst(cache_dir=cache_dir, overwrite_cache=overwrite_cache)
180184
else:
181185
raise NotImplementedError(f"Language {lang} has not been supported yet.")
182186

@@ -377,7 +381,7 @@ def normalize(
377381
return text
378382
output = SPACE_DUP.sub(' ', output[1:])
379383

380-
if self.lang == "en" and hasattr(self, 'post_processor'):
384+
if self.lang in ["en", "vi"] and hasattr(self, 'post_processor'):
381385
output = self.post_process(output)
382386

383387
if punct_post_process:

nemo_text_processing/text_normalization/run_evaluate.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse_args():
3535
parser.add_argument(
3636
"--lang",
3737
help="language",
38-
choices=['ar', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ru', 'sv', 'zh', 'hy', 'hi'],
38+
choices=['ar', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ru', 'sv', 'zh', 'hy', 'hi', 'vi'],
3939
default="en",
4040
type=str,
4141
)
@@ -104,8 +104,6 @@ def parse_args():
104104
print("- Accuracy: " + str(sum(token_weighted_accuracy) / sum(token_count_per_type.values())))
105105
print(" - Total: " + str(sum(token_count_per_type.values())), '\n')
106106

107-
print(" - Total: " + str(sum(token_count_per_type.values())), '\n')
108-
109107
for token_type in token_accuracy:
110108
if token_type not in known_types:
111109
raise ValueError("Unexpected token type: " + token_type)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
m mét
2+
m2 mét vuông
3+
m3 mét khối
4+
mét vuông
5+
mét khối
6+
g gam
7+
l lít
8+
s giây
9+
v vôn
10+
w oát
11+
hz hẹc
12+
A am pe
13+
b bai
14+
B byte
15+
pa pascal
16+
ω ohm
17+
Ω ôm
18+
h giờ
19+
min phút
20+
hr giờ
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
°f độ f
2+
°c độ c
3+
°k độ k
4+
ha héc ta
5+
mi mile
6+
ft foot
7+
inch inch
8+
yd yard
9+
% phần trăm
10+
hp mã lực
11+
rad radian
12+
kwh ki lô oát giờ
13+
kbps kilobit trên giây
14+
mbps megabit trên giây
15+
ghz gi ga hẹc
16+
mhz mê ga hẹc
17+
tw tê ra oát
18+
kcal ki lô calo
19+
gb gi ga bai
20+
mb mê ga bai
21+
mV mi li vôn
22+
MV mê ga vôn
23+
tb terabyte
24+
pb petabyte
25+
g gam
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
k ki lô
2+
M mê ga
3+
G gi ga
4+
T tê ra
5+
P pê ta
6+
E ex xa
7+
h hếc tô
8+
da đề ca
9+
d đề xi
10+
c xăng ti
11+
m mi li
12+
µ mi crô
13+
μ mi cờ rô
14+
n na nô
15+
p pi cô
16+
f fem tô
17+
a át tô
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
g gam
2+
m mét
3+
mét vuông
4+
m2 mét vuông
5+
mét khối
6+
m3 mét khối
7+
l lít
8+
B bai

nemo_text_processing/text_normalization/vi/data/money/per_unit.tsv renamed to nemo_text_processing/text_normalization/vi/data/money/per_unit_non_metric.tsv

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/giờ trên giờ
2-
/g trên giờ
32
/h trên giờ
43
/ngày trên ngày
54
/d trên ngày
@@ -13,33 +12,17 @@
1312
/lần một lần
1413
/cái một cái
1514
/chiếc một chiếc
16-
/kg một ki lô gam
17-
/g một gam
18-
/cm một xăng ti mét
19-
/m một mét
20-
/km một ki lô mét
21-
/cm² một xăng ti mét vuông
22-
/m² một mét vuông
23-
/m2 một mét vuông
24-
/m³ một mét khối
25-
/m3 một mét khối
26-
/l một lít
27-
/ml một mi li lít
2815
/người một người
2916
/chỗ một chỗ
3017
/bài một bài
3118
/trang một trang
3219
/từ một từ
3320
/đồng một đồng
34-
/KB một kilobyte
35-
/GB một gigabyte
36-
/MB một megabyte
37-
/TB một terabyte
38-
/tấn một tấn
3921
/đêm một đêm
4022
/buổi một buổi
4123
/ca một ca
4224
/dự án một dự án
4325
/lớp một lớp
4426
/khóa một khóa
45-
/suất một suất
27+
/suất một suất
28+
/tấn một tấn
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
k ki lô
2+
M mê ga
3+
G gi ga
4+
c xăng ti
5+
m mi li
6+
T tê ra

0 commit comments

Comments
 (0)