-
Notifications
You must be signed in to change notification settings - Fork 1
Added Hindi percentage ITN class #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ITN-KT_Percentage-Class
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
mayuris-00 marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| % प्रतिशत | ||
| % परसेंट | ||
| % फ़ीसदी | ||
| % फीसदी |
|
mayuris-00 marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import pynini | ||
| from pynini.lib import pynutil | ||
|
|
||
| from nemo_text_processing.inverse_text_normalization.hi.graph_utils import ( | ||
| INPUT_LOWER_CASED, | ||
| GraphFst, | ||
| delete_space, | ||
| ) | ||
| from nemo_text_processing.inverse_text_normalization.hi.utils import get_abs_path | ||
|
|
||
|
|
||
| class PercentageFst(GraphFst): | ||
| def __init__(self, cardinal, input_case: str = INPUT_LOWER_CASED): | ||
| super().__init__(name="percentage", kind="classify") | ||
|
|
||
| # load percent words and flip mapping: प्रतिशत → % | ||
| percent_graph = pynini.string_file( | ||
| get_abs_path("data/percentage/percent_symbol.tsv") | ||
| ).invert() | ||
|
|
||
| # reuse number logic (बीस → २०, पाँच सौ → ५००) | ||
| integer_graph = cardinal.graph_no_exception | ||
|
|
||
| # match: <number> + <percent word> | ||
| # and convert into structured format | ||
| final_graph = ( | ||
| pynutil.insert('integer: "') | ||
| + integer_graph | ||
| + pynutil.insert('"') | ||
| + delete_space | ||
| + pynutil.insert(' percent: "') | ||
| + percent_graph | ||
| + pynutil.insert('"') | ||
| ) | ||
|
|
||
| # wrap as: percentage { ... } | ||
| final_graph = self.add_tokens(final_graph) | ||
|
|
||
| self.fst = final_graph.optimize() |
|
mayuris-00 marked this conversation as resolved.
|
|
mayuris-00 marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import pynini | ||
| from pynini.lib import pynutil | ||
|
|
||
| from nemo_text_processing.inverse_text_normalization.hi.graph_utils import ( | ||
| NEMO_NOT_QUOTE, | ||
| GraphFst, | ||
| delete_space, | ||
| ) | ||
|
|
||
|
|
||
| class PercentageFst(GraphFst): | ||
| def __init__(self): | ||
| super().__init__(name="percentage", kind="verbalize") | ||
|
|
||
| # extract number part (remove labels and quotes) | ||
| # example: integer: "२०" → २० | ||
| integer_part = ( | ||
| pynutil.delete("integer:") | ||
| + delete_space | ||
| + pynutil.delete("\"") | ||
| + pynini.closure(NEMO_NOT_QUOTE, 1) | ||
| + pynutil.delete("\"") | ||
| ) | ||
|
|
||
| # extract percent symbol | ||
| # example: percent: "%" → % | ||
| percent_part = ( | ||
| pynutil.delete("percent:") | ||
| + delete_space | ||
| + pynutil.delete("\"") | ||
| + pynini.closure(NEMO_NOT_QUOTE, 1) | ||
| + pynutil.delete("\"") | ||
| ) | ||
|
|
||
| # combine both → २०% | ||
| graph = integer_part + delete_space + percent_part | ||
|
|
||
| # remove outer wrapper: percentage { ... } | ||
| delete_tokens = self.delete_tokens(graph) | ||
|
|
||
| self.fst = delete_tokens.optimize() |
|
mayuris-00 marked this conversation as resolved.
|
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cdifflib fallback fix is unrelated to the percentage class. Even if it was needed to get your environment working, it should be a separate commit or a separate PR. Mixing unrelated fixes into a feature PR makes the review harder and the git history messier. Please remove this change from this PR and raise it separately if needed.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted the cdifflib change from this PR. Will raise it separately if needed. |
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should not be here. You already have the correct copy at tests/nemo_text_processing/hi/test_percentage.py. This root-level version will not work -- the relative import from ..utils import CACHE_DIR requires the file to be inside the tests/nemo_text_processing/hi/ package. Please delete this file. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (c) 2024, 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 pytest | ||
| from parameterized import parameterized | ||
| from nemo_text_processing.inverse_text_normalization.inverse_normalize import InverseNormalizer | ||
| from ..utils import CACHE_DIR, parse_test_case_file | ||
|
|
||
|
|
||
| class TestPercentage: | ||
| inverse_normalizer = InverseNormalizer(lang='hi', cache_dir=CACHE_DIR, overwrite_cache=False) | ||
|
|
||
| @parameterized.expand(parse_test_case_file('hi/data_inverse_text_normalization/test_cases_percentage.txt')) | ||
| @pytest.mark.run_only_on('CPU') | ||
| @pytest.mark.unit | ||
| def test_denorm(self, test_input, expected): | ||
| pred = self.inverse_normalizer.inverse_normalize(test_input, verbose=False) | ||
| assert pred == expected |
|
RajanPutty marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| बीस प्रतिशत~२०% | ||
| पचास प्रतिशत~५०% | ||
| दस प्रतिशत~१०% | ||
| सौ प्रतिशत~१००% | ||
| पच्चीस प्रतिशत~२५% | ||
| पाँच प्रतिशत~५% | ||
| तीन प्रतिशत~३% | ||
| सत्तर परसेंट~७०% | ||
| एक प्रतिशत~१% | ||
| शून्य प्रतिशत~०% | ||
| पाँच सौ फ़ीसदी~५००% | ||
| तेरह प्रतिशत~१३% |
|
RajanPutty marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (c) 2024, 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 pytest | ||
| from parameterized import parameterized | ||
| from nemo_text_processing.inverse_text_normalization.inverse_normalize import InverseNormalizer | ||
| from ..utils import CACHE_DIR, parse_test_case_file | ||
|
|
||
|
|
||
| class TestPercentage: | ||
| inverse_normalizer = InverseNormalizer(lang='hi', cache_dir=CACHE_DIR, overwrite_cache=False) | ||
|
|
||
| @parameterized.expand(parse_test_case_file('hi/data_inverse_text_normalization/test_cases_percentage.txt')) | ||
| @pytest.mark.run_only_on('CPU') | ||
| @pytest.mark.unit | ||
| def test_denorm(self, test_input, expected): | ||
| pred = self.inverse_normalizer.inverse_normalize(test_input, verbose=False) | ||
| assert pred == expected |
|
RajanPutty marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.