Repository navigation
fix(docvqa): keep the answer when a stray <answer> follows it - #402
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
extract_answer took the last "<answer>" and the last "</answer>" and only used them when the closing tag came after the opening one. If the response mentioned "<answer>" again after the final answer, for example "<answer>42</answer> (formatted with the <answer> tag as asked)", the pair was rejected and the last line of text was scored instead, so a correct answer got ANLS 0. ANLS is the DocVQA soft score and hard is ANLS >= 0.999, so both the training reward and reported scores dropped. Pair the last "</answer>" with the last "<answer>" before it. This stays a linear scan, and nested input such as "<answer>x<answer>y</answer>" still returns "y" as before.
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 #399.
DocVQA's
extract_answer()rejected the final answer when the response mentioned<answer>again after it, for example<answer>42</answer> (formatted with the <answer> tag as asked). It then scored the last line of text instead, so a correct answer got ANLS 0. The last</answer>is now paired with the last<answer>before it.User impact: ANLS is the DocVQA
softscore andhardisANLS >= 0.999, so a correct answer followed by a stray tag got zero training reward and counted as a miss in reported scores.Proof: the regression tests fail on upstream
45f65caand pass with this change.Root cause
extract_answer()inskillopt/envs/docvqa/evaluator.pytookrfind("<answer>")andrfind("</answer>")independently and used them only when the closing tag came after the opening one. A stray<answer>after the final</answer>made the last opening tag come after the last closing tag, so the valid pair was discarded and the last-line fallback ran.Changes
extract_answer()finds the last</answer>, then the last<answer>before it. This is still a linear scan over the text.<answer>x<answer>y</answer>still returnsy, and the last-line fallback is unchanged when there is no closing tag.tests/test_docvqa_evaluator.py, including the nested case as a guard.Reproduction
Before:
After:
'42' 1.0for all three.Testing
python -m pytest tests/test_docvqa_evaluator.py -q: on upstream45f65ca, 3 failed (assert '<answer>' == '42'and similar) and 33 passed; with the fix, 36 passed.python -m pytest tests/test_docvqa_evaluator.py tests/test_benchmark_task_output_paths.py -q: 52 passed.python -m pytest -q: 2220 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 responses with an
<answer>after the last</answer>change outcome, and those were scored from the wrong text before. No backend, config key, file format or CLI change.