forked from NVIDIA/NeMo-text-processing
-
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
Open
mayuris-00
wants to merge
4
commits into
RajanPutty:ITN-KT_Percentage-Class
Choose a base branch
from
mayuris-00:ITN-KT_Percentage-Class
base: ITN-KT_Percentage-Class
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
4 changes: 4 additions & 0 deletions
4
nemo_text_processing/inverse_text_normalization/hi/data/percentage/percent_symbol.tsv
|
mayuris-00 marked this conversation as resolved.
|
This file contains hidden or 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,4 @@ | ||
| % प्रतिशत | ||
| % परसेंट | ||
| % फ़ीसदी | ||
| % फीसदी |
54 changes: 54 additions & 0 deletions
54
nemo_text_processing/inverse_text_normalization/hi/taggers/percentage.py
|
mayuris-00 marked this conversation as resolved.
|
This file contains hidden or 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,54 @@ | ||
| # 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 pynini | ||
| from pynini.lib import pynutil | ||
|
|
||
| from nemo_text_processing.inverse_text_normalization.hi.graph_utils import ( | ||
| GraphFst, | ||
| delete_space, | ||
| ) | ||
| from nemo_text_processing.inverse_text_normalization.hi.utils import get_abs_path | ||
|
|
||
|
|
||
| class PercentageFst(GraphFst): | ||
| """ | ||
| Finite state transducer for classifying percentages | ||
| e.g. बीस प्रतिशत -> percentage { integer: "२०" percent: "%" } | ||
|
|
||
| Args: | ||
| cardinal: CardinalFst | ||
| """ | ||
|
|
||
| def __init__(self, cardinal): | ||
| super().__init__(name="percentage", kind="classify") | ||
|
|
||
| graph_percent_symbol = pynini.string_file( | ||
| get_abs_path("data/percentage/percent_symbol.tsv") | ||
| ).invert() | ||
|
|
||
| integer_graph = cardinal.graph_no_exception | ||
|
|
||
| final_graph = ( | ||
| pynutil.insert("integer: \"") | ||
| + integer_graph | ||
| + pynutil.insert("\"") | ||
| + delete_space | ||
| + pynutil.insert(" percent: \"") | ||
| + graph_percent_symbol | ||
| + pynutil.insert("\"") | ||
| ) | ||
|
|
||
| final_graph = self.add_tokens(final_graph) | ||
| self.fst = final_graph.optimize() |
|
mayuris-00 marked this conversation as resolved.
|
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
nemo_text_processing/inverse_text_normalization/hi/verbalizers/percentage.py
|
mayuris-00 marked this conversation as resolved.
|
This file contains hidden or 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,53 @@ | ||
| # 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 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): | ||
| """ | ||
| Finite state transducer for verbalizing percentage | ||
| e.g. percentage { integer: "२०" percent: "%" } -> २०% | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| super().__init__(name="percentage", kind="verbalize") | ||
|
|
||
| integer_part = ( | ||
| pynutil.delete("integer:") | ||
| + delete_space | ||
| + pynutil.delete("\"") | ||
| + pynini.closure(NEMO_NOT_QUOTE, 1) | ||
| + pynutil.delete("\"") | ||
| ) | ||
|
|
||
| percent_part = ( | ||
| pynutil.delete("percent:") | ||
| + delete_space | ||
| + pynutil.delete("\"") | ||
| + pynini.closure(NEMO_NOT_QUOTE, 1) | ||
| + pynutil.delete("\"") | ||
| ) | ||
|
|
||
| graph = integer_part + delete_space + percent_part | ||
|
|
||
| delete_tokens = self.delete_tokens(graph) | ||
| self.fst = delete_tokens.optimize() |
|
mayuris-00 marked this conversation as resolved.
|
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
tests/nemo_text_processing/hi/data_inverse_text_normalization/test_cases_percentage.txt
|
RajanPutty marked this conversation as resolved.
|
This file contains hidden or 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,12 @@ | ||
| बीस प्रतिशत~२०% | ||
| पचास प्रतिशत~५०% | ||
| दस प्रतिशत~१०% | ||
| सौ प्रतिशत~१००% | ||
| पच्चीस प्रतिशत~२५% | ||
| पाँच प्रतिशत~५% | ||
| तीन प्रतिशत~३% | ||
| सत्तर परसेंट~७०% | ||
| एक प्रतिशत~१% | ||
| शून्य प्रतिशत~०% | ||
| पाँच सौ फ़ीसदी~५००% | ||
| तेरह प्रतिशत~१३% |
|
RajanPutty marked this conversation as resolved.
|
This file contains hidden or 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,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.
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.