Skip to content

Read numbers grouped with no-break, narrow no-break or thin spaces - #1478

Open
ChrystianSchutz wants to merge 1 commit into
huggingface:mainfrom
ChrystianSchutz:fix/nbsp-digit-groups
Open

ChrystianSchutz wants to merge 1 commit into
huggingface:mainfrom
ChrystianSchutz:fix/nbsp-digit-groups

Conversation

@ChrystianSchutz

Copy link
Copy Markdown

Fixes #1476

Format 1 of number_re joined digit groups only with an ASCII space or a comma. Numbers typeset with U+00A0 (no-break space), U+202F (narrow no-break space) or U+2009 (thin space) were split in two: ANSWER: 2\u202f500 was read as 2, and The total is 2\u2009500. as 500. Both math_scorer() and MultilingualExtractiveMatchMetric were affected.

This PR does two things:

  • Accepts those three spaces as group separators and strips them in extract_expr.
  • Adds (?!\d) after the last group, so a run of four or more digits is no longer cut: ANSWER: 7 1234 was 7123 and is now 7. As a side effect, 1,2345 now reads as 1.2345 through the decimal-comma format, the same way 3,14 already does; before, it was 1234 with a digit dropped.

Tests:

  • 12 new parametrized cases in tests/unit/metrics/test_extractive_match.py: the three spaces, a decimal part, several groups, and controls for an ASCII space, a 4-digit group and a space before a word. 9 of the 12 fail on main and all 12 pass with the change.
  • test_extractive_match.py + test_normalizations.py: 249 passed.
  • ruff check and ruff format --check are clean.

The patch file stays ASCII: the code points are written as \u escapes.

Prepared with AI assistance (Claude). The tests above were run in a clean environment at b97a653.

🤖 Generated with Claude Code

Format 1 of number_re joined digit groups only with an ASCII space or a comma, so a number written with U+202F between groups was read as only one of its groups.

Fixes huggingface#1476

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Numbers grouped with a no-break or narrow no-break space ("2 500") are read as only their first or last group

1 participant