fix(eval): stop a comma from swallowing the GSM8K answer - #3484
Merged
jundot merged 1 commit intoSep 8, 2026
Merged
Conversation
_extract_numeric_answer falls back to the last number in the response
when the model does not emit the "#### N" marker. Its fallback pattern
-?[\d,]+(?:\.\d+)? also matches a bare comma, because [\d,]+ needs only
one character from the class. Any comma after the final digit therefore
became the last "number" in the text, and .replace(",", "") turned it
into an empty string.
"The total is 72 clips, altogether." extracted "" instead of "72", so
check_answer returned False on a correct response and the question was
scored wrong (parse_error on the external-API path).
Anchor the pattern on a digit at both ends: -?\d(?:[\d,]*\d)?(?:\.\d+)?.
Thousands separators still match, since they sit between digits. The
"####" branch uses the same pattern.
All 1,319 gold answers in omlx/eval/data/gsm8k_test.jsonl extract
identically before and after, so scoring keys are untouched.
Owner
|
Thanks for the fix. I verified that trailing commas no longer cause correct answers to be rejected, while thousands separators and all 1,319 gold answer extractions remain unchanged. LGTM, merging. |
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.
Summary
GSM8K scores a correct answer as wrong whenever the model's last sentence puts a comma after the final number.
_extract_numeric_answerreturns an empty string instead of the number,check_answershort-circuits on the empty prediction, and the question is counted wrong (the external-API path reports it asparse_error).Root cause
omlx/eval/gsm8k.py:55. When the response has no#### Nmarker, extraction falls back to the last number in the text:[\d,]+needs only one character from the class, so a bare,is a match. On"The total is 72 clips, altogether."findall returns['72', ',']; the last element is the comma, and.replace(",", "")turns it into"". The number is right there in the text, and the function reports that it found nothing.The
####branch at line 51 uses the same class and has the same hole (#### ,captures a comma).Fix
Anchor the pattern on a digit at both ends and share it between the two branches:
Thousands separators still match, because they sit between digits:
1,234and1,234.50are unchanged.72,now matches just72. A lone comma matches nothing, so it can no longer become the "last number".Verification
tests/test_eval.py::TestGSM8Kgains three cases. Red onmainat aa8db73, green with the change:Scoring keys are untouched: I ran both the old and the new extractor over all 1,319 gold answers in
omlx/eval/data/gsm8k_test.jsonland every one of them extracts the same value (they all carry#### N, so they never reached the fallback).Adjacent suites:
pytest tests/test_eval.py tests/test_mbpp_extract_code.py tests/test_accuracy_benchmark.py tests/test_accuracy_upload.py tests/test_admin_external_accuracy_diagnostics.pygives 155 passed.Full suite with the CI filter,
pytest tests/ -m "not slow and not integration" -n 2on an M-series Mac with Python 3.11.15: 10807 passed, 176 skipped, 0 failed in 5m30s.ruff checkandblack --checkreport the same findings on this file before and after the change (one pre-existingUP045inget_category, and black wants to reformat an untouched dict literal inload_dataset), so nothing new was introduced.