Repository navigation
feat: English/Spanish call ASR normalizations for gladia-3 #32
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3eaa03e
feat: add English/Spanish jail-call ASR normalizations for gladia-3
egenthon-cmd dfafb82
fix: removing wrong normalization tests (+replacements)
egenthon-cmd 1c5e4d0
fix: wordtonum normalization redo + test coverage
egenthon-cmd d57da7e
fix: formatting
egenthon-cmd 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
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 |
|---|---|---|
|
|
@@ -17,4 +17,5 @@ wheels/ | |
| .vscode/ | ||
| .idea/ | ||
| .cursor/ | ||
| .claude/ | ||
| .claude/ | ||
| /site | ||
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
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
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
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 |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| ENGLISH_SENTENCE_REPLACEMENTS: dict[str, str] = { | ||
| "good bye": "goodbye", | ||
| # ASR / WER canonicalizations | ||
| "m a c": "mac", | ||
| "all right": "alright", | ||
| "fire fire": "firefires", | ||
| "paul s": "pauls", | ||
| } |
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 |
|---|---|---|
|
|
@@ -27,4 +27,6 @@ | |
| "vds": "ustedes", | ||
| "versus": "versus", | ||
| "vs": "versus", | ||
| # ASR / WER canonicalizations | ||
| "ahorita": "ahora", | ||
| } | ||
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
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 |
|---|---|---|
|
|
@@ -36,3 +36,4 @@ cuarenta y cinco,45 | |
| setenta y ocho,78 | ||
| quinientos,500 | ||
| quince mil,15000 | ||
| ahorita,ahora | ||
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,165 @@ | ||
| import pytest | ||
|
|
||
| from normalization.languages.english.number_normalizer import EnglishNumberNormalizer | ||
| from normalization.pipeline.loader import load_pipeline | ||
|
|
||
| _ONES_UNITS: dict[str, int] = { | ||
| "one": 1, | ||
| "two": 2, | ||
| "three": 3, | ||
| "four": 4, | ||
| "five": 5, | ||
| "six": 6, | ||
| "seven": 7, | ||
| "eight": 8, | ||
| "nine": 9, | ||
| } | ||
|
|
||
| _TEENS: dict[str, int] = { | ||
| "ten": 10, | ||
| "eleven": 11, | ||
| "twelve": 12, | ||
| "thirteen": 13, | ||
| "fourteen": 14, | ||
| "fifteen": 15, | ||
| "sixteen": 16, | ||
| "seventeen": 17, | ||
| "eighteen": 18, | ||
| "nineteen": 19, | ||
| } | ||
|
|
||
| _TENS: dict[str, int] = { | ||
| "twenty": 20, | ||
| "thirty": 30, | ||
| "forty": 40, | ||
| "fifty": 50, | ||
| "sixty": 60, | ||
| "seventy": 70, | ||
| "eighty": 80, | ||
| "ninety": 90, | ||
| } | ||
|
|
||
| _ROUND_TENS = (10, 20, 30, 40, 50, 60, 70, 80, 90) | ||
| _LEADING_DIGITS = (2, 10, 20, 30, 99) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def normalizer() -> EnglishNumberNormalizer: | ||
| return EnglishNumberNormalizer() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("digit", "word", "word_value"), | ||
| [ | ||
| (digit, word, value) | ||
| for digit in _ROUND_TENS | ||
| for word, value in _ONES_UNITS.items() | ||
| ], | ||
| ) | ||
| def test_round_digit_plus_unit_adds( | ||
| normalizer: EnglishNumberNormalizer, | ||
| digit: int, | ||
| word: str, | ||
| word_value: int, | ||
| ) -> None: | ||
| """'40 four' → '44', '30 two' → '32' (tens + ones), not concatenation.""" | ||
| assert normalizer(f"{digit} {word}") == str(digit + word_value) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("digit", "word", "word_value"), | ||
| [ | ||
| (digit, word, value) | ||
| for digit in _LEADING_DIGITS | ||
| for word, value in {**_TEENS, **_TENS}.items() | ||
| ], | ||
| ) | ||
| def test_digit_plus_teen_or_tens_concatenates( | ||
| normalizer: EnglishNumberNormalizer, | ||
| digit: int, | ||
| word: str, | ||
| word_value: int, | ||
| ) -> None: | ||
| """'20 thirteen' → '2013', '20 twenty' → '2020'.""" | ||
| assert normalizer(f"{digit} {word}") == f"{digit}{word_value}" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("digit", range(1, 100)) | ||
| def test_digit_plus_hundred_multiplies( | ||
| normalizer: EnglishNumberNormalizer, digit: int | ||
| ) -> None: | ||
| """'20 hundred' → '2000', '25 hundred' → '2500', … for every 1–99.""" | ||
| assert normalizer(f"{digit} hundred") == str(digit * 100) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("text", "expected"), | ||
| [ | ||
| ("1 thousand", "1000"), | ||
| ("10 thousand", "10000"), | ||
| ("25 thousand", "25000"), | ||
| ("100 thousand", "100000"), | ||
| ("1 million", "1000000"), | ||
| ("20 million", "20000000"), | ||
| ("25 million", "25000000"), | ||
| ], | ||
| ) | ||
| def test_digit_plus_large_multiplier( | ||
| normalizer: EnglishNumberNormalizer, text: str, expected: str | ||
| ) -> None: | ||
| assert normalizer(text) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("text", "expected"), | ||
| [ | ||
| # "for" is ASR for "four": 40 + 4 + .5 | ||
| ("40 for point 5", "44.5"), | ||
| ("40 four point 5", "44.5"), | ||
| ("44 point 5", "44.5"), | ||
| ("eleventh 2000 and twelve", "11 2012"), | ||
| ("eleventh 2 thousand and twelve", "11 2012"), | ||
| ("eleventh 2 thousaond and twelve", "11 2012"), | ||
| ], | ||
| ) | ||
| def test_asr_number_phrase_forms( | ||
| normalizer: EnglishNumberNormalizer, text: str, expected: str | ||
| ) -> None: | ||
| assert normalizer(text) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("text", "expected"), | ||
| [ | ||
| ("40 for point 5", "44 point 5"), | ||
| ("40 four point 5", "44 point 5"), | ||
| ("eleventh 2000 and twelve", "112012"), | ||
| ("eleventh 2 thousand and twelve", "112012"), | ||
| ("eleventh 2 thousaond and twelve", "112012"), | ||
| ("25 hundred", "2500"), | ||
| ("35 hundred", "3500"), | ||
| ("20 hundred", "2000"), | ||
| ("20 thirteen", "2013"), | ||
| ("30 two", "32"), | ||
| ("20 one", "21"), | ||
| ("20 twenty", "2020"), | ||
| ("10 thousand", "10000"), | ||
| ], | ||
| ) | ||
| def test_words_to_num_through_gladia_3_pipeline(text: str, expected: str) -> None: | ||
| pipeline = load_pipeline("gladia-3", "en") | ||
| assert pipeline.normalize(text) == expected | ||
|
|
||
|
|
||
| def test_standalone_ordinal_still_keeps_suffix( | ||
| normalizer: EnglishNumberNormalizer, | ||
| ) -> None: | ||
| assert normalizer("eleventh") == "11th" | ||
| assert normalizer("first") == "1st" | ||
|
|
||
|
|
||
| def test_for_not_rewritten_outside_number_point_context( | ||
| normalizer: EnglishNumberNormalizer, | ||
| ) -> None: | ||
| assert normalizer("for example") == "for example" | ||
| assert normalizer("40 for example") == "40 for example" |
Oops, something went wrong.
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.