Repository navigation
fix(normalizer): read money with more than two decimals as a decimal number - #599
Merged
Merged
Conversation
…number Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Owner
|
Looks good, thanks @lbarrosby |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
_moneyinnormalization/english.pytreats every fractional part as cents: it takes the digits after the dot as an integer and reads them as the coin. That only works for one or two decimals. Prices with more decimals are common (US fuel prices, per-token or per-unit rates, crypto):Gas is $3.499 a gallon$0.0012 per token-$1.005The
$0.0012case is the worst one, because the amount gets 10,000 times bigger when read aloud.When the matched number has more than two decimals and is not a whole amount, the amount is now read as a decimal number followed by the plural bill, the same way
$1.5 millionis already read. The words come from the matched digits rather than from the float, so small values never go through scientific notation. Whole amounts with trailing zeros (£2.000) still take the existing branch and stay "two pounds". One and two decimals ($5.5,$5.50,$1.05) are unchanged.Testing
uv run pytestpasses locally (API changes)npm run test:webpasses locally (web player changes)npm run cpu:up/gpu:up), for inference or docker changesCHANGELOG.mdentry, if users will notice the changeFour new
CASESinapi/tests/test_normalizer.py(the three rows above plus£2.000). The three rows fail on master and pass with the fix. I rantest_normalizer.py,test_normalizer_contract.pyandtest_normalizer_properties.pyin a small venv with the locked inflect 7.5.0, without torch or model weights (178 passed; the twotest_normalizer_redos.pycases that import the full text processor need torch and fail the same way on master), so I did not tick the fulluv run pytestbox.ruff checkandruff format --checkare clean.AI disclosure: written with the help of Claude Code, reviewed and tested by me.