Skip to content

Do not let an extracted expression end with an operator (bold answers) - #1477

Open
ChrystianSchutz wants to merge 1 commit into
huggingface:mainfrom
ChrystianSchutz:fix/bold-answer-expression
Open

ChrystianSchutz wants to merge 1 commit into
huggingface:mainfrom
ChrystianSchutz:fix/bold-answer-expression

Conversation

@ChrystianSchutz

Copy link
Copy Markdown

Fixes #1475

expr_re allowed an expression to end with any operator, so in ANSWER: **18** the closing bold markers were read as part of the expression 18**. That string does not parse. math_scorer() (first_match) then scores a correct answer I, and MultilingualExtractiveMatchMetric (any_match) falls through to the last bare number in the text.

This PR requires an expression to end with a digit or ). Valid expressions are unchanged: all_expr_chars is only digits, ., whitespace and operators.

completion gold before (expr_gold_metric / math_scorer) after
ANSWER: **18** 18 1.0 / I 1.0 / C
ANSWER: **18**\n\nThis took 3 steps. 18 0.0 / I 1.0 / C
ANSWER: **18**\n\nThis took 3 steps. 3 1.0 / I 0.0 / I
The answer is **18**, found in 3 steps. 18 0.0 / I 1.0 / C

Tests:

  • New tests in tests/unit/metrics/test_extractive_match.py: 11 extraction cases, including controls for (1+2), 3 + 4 and 2^10, plus 2 Inspect math_scorer cases. 8 of the 13 fail on main and all 13 pass with the change.
  • test_extractive_match.py + test_normalizations.py: 250 passed.
  • ruff check and ruff format --check are clean.

The same mechanism is reported for the Math-Verify package in huggingface/Math-Verify#76. lighteval keeps its own copy of the parser (#848).

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

🤖 Generated with Claude Code

In 'ANSWER: **18**' the closing bold markers were read as part of the expression '18**', which does not parse, so the score fell back to another number.

Fixes huggingface#1475

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] Bold answers ("ANSWER: **18**") are parsed as the expression "18**", so the score falls back to another number

1 participant