Repository navigation
fix(searchqa): treat a single string gold answer as one answer - #401
Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Conversation
evaluate() and the EM, F1 and sub_em helpers iterate gold_answers. When an item's answers field was a single string instead of a list, they iterated its characters: the correct answer "Paris" scored EM 0, while "P" or "s" scored EM 1 and F1 1. hard is EM and soft is F1, so these items gave an inverted training reward and wrong reported scores. Wrap a string gold answer in a list at the start of evaluate(), which is the entry point both rollout paths call. List gold answers are unchanged.
This branch has not been deployed
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
Fixes #398.
When a SearchQA item's
answersfield was a single string instead of a list,evaluate()and the EM, F1 andsub_emhelpers iterated its characters. The correct answerParisscored EM 0, whilePorsscored EM 1 and F1 1. A single string gold answer is now treated as a one-item list.User impact:
hardis EM andsoftis F1, so such items gave an inverted training reward (correct answers penalized, one-letter answers rewarded) and wrong reported scores.Proof: the regression tests fail on upstream
45f65caand pass with this change.Root cause
evaluate()inskillopt/envs/searchqa/evaluator.pypassedgold_answersstraight toexact_match(),f1_score()andsub_em(), which loop over it. Iterating astryields characters.materialize_searchqa.pywrites lists, but custom data or a hand-written split can store"answers": "Paris", and nothing normalized it. The DocVQA evaluator already accepts a single string gold answer.Changes
evaluate()wraps a stringgold_answersin a list before scoring. This is the entry point both rollout paths inrollout.pycall, so they are both covered. List gold answers are unchanged.gold_answersis the normalized list, so result rows show["Paris"]instead of the bare string.tests/test_searchqa_evaluator.py.Reproduction
Before:
After:
Parisscores1.0 1.0 1.0and the other three score0.0 0.0 0.0.Testing
python -m pytest tests/test_searchqa_evaluator.py -q: on upstream45f65ca, 3 failed (assert 1.0 == 0.0andassert 0.0 == 1.0) and 6 passed; with the fix, 9 passed.python -m pytest tests/test_searchqa_evaluator.py tests/test_searchqa_rollout_failfast.py tests/test_materialize_searchqa.py tests/test_qwen_backend.py -q: 43 passed.python -m pytest -q: 2219 passed, 12 skipped, 4 xfailed.python -m ruff checkandpython -m ruff format --checkon the changed files: clean.python -m mkdocs build --strict: passed.Risk and compatibility
Only calls that pass a string as
gold_answerschange, and those were scored incorrectly before. List inputs are scored exactly as before. No backend, config key, file format or CLI change.