[Bug] first_option_postprocess returns 'A' from words like 'Answer'/'All' when the answer is bolded or boxed
Prerequisite
- [x] I have searched Issues and Discussions but cannot get the expected help.
- [x] The bug has not been fixed in the latest version.
Type
I'm evaluating with the officially supported tasks/models/datasets.
Environment
Reproduced on main at 8b4193ff (OpenCompass 0.5.5), Python 3.11, macOS (Apple M2). The bug is in pure regex code in opencompass/utils/text_postprocessors.py, so it does not depend on the environment.
Reproduces the problem - code/configuration sample
from opencompass.utils.text_postprocessors import first_option_postprocess as f
for x in ["Answer: **B**", "ANSWER: \\boxed{B}", "Answer: (B)",
"Answer: All of the above", "All of the above",
"Absolutely, Definitely Correct"]:
print(repr(x), "->", repr(f(x, "ABCD")))
Reproduces the problem - command or script
python repro.py with the snippet above.
Reproduces the problem - error message
There is no error. The wrong letter is returned:
| Model output | Expected | first_option_postprocess(x, 'ABCD') |
|---|---|---|
Answer: **B** |
B |
A |
ANSWER: \boxed{B} |
B |
A |
Answer: (B) |
B |
A |
Answer: All of the above |
'' |
A |
All of the above |
'' |
A |
Absolutely, Definitely Correct |
'' |
A |
These already work and must stay unchanged: The answer is B., Answer: B, **Answer: B**, 答案:B, 答案是B, 答案:(B), \boxed{B}, Option B is correct, B) Paris, 选B, 我选择B项, 所以选C。 (→ C), 正确答案是D (→ D), B, A, (C).
Other information
Cause
- The cushion fallback patterns (
cushion_patterns, lines 131–134 onmain) are([{options}]):and([{options}]). They match a capital option letter anywhere, including inside a word, so theAof "Answer", "All" or "Absolutely" is returned whenever no earlier pattern matches. - The
(?i)ANSWER\s*:\s*([{options}])pattern (line 115) allows only whitespace between:and the letter. With**B**,\boxed{B}or(B)it doesn't match, so the text falls through to the cushion, which then returns theAof "Answer". It also doesn't check what follows the letter, soAnswer: All of the abovereturnsAfrom "All".
Impact
98 dataset configs import this extractor from opencompass.utils, including MMLU, MMLU-Pro, GPQA, ARC-c/ARC-e, HellaSwag and C-Eval. Bold, boxed and parenthesised answers are common in chat-model output. The error gives false credit whenever the gold answer is A, so it inflates scores.
The default rule-based gen configs still use this extractor, and the error is a bias (false credit when the gold answer is A), not just a parse failure, so it affects reported scores even when the outputs look fine.
Proposed fix
- Cushion patterns: require that the letter is not part of an ASCII word, with
(?<![A-Za-z])([{options}]):and(?<![A-Za-z])([{options}])(?![A-Za-z]). ASCII-letter lookarounds rather than\bkeep Chinese outputs such as选Bworking (\btreats CJK characters as word characters). ANSWERpattern: accept an optional**,\boxed{or(before the letter, and require that no letter follows it (Python source, as in the f-string list):f'(?i)ANSWER\s*:\s*(?:\*\*|\\\\boxed\\{{|\\()?\\s*([{options}])(?![A-Za-z])'.
With these two changes all six cases above give the expected result, and all the controls listed above are unchanged.
Related
- #1933: MMLU-Pro outputs starting with
Answer: Let's think step by step.were extracted asL, the same "letter at the start of a word" problem (there in theANSWER-style pattern used bymatch_answer_pattern). - #1973: a reporter changed the
ANSWERpattern locally to handle**ANSWER:** C.
Out of scope / possible follow-ups
the answer is B, not A.returnsAbecause of pattern order.- Full-width letters such as
Bare not recognised. opencompass/datasets/mathbench.pyhas its own copy offirst_option_postprocesswith the same cushion patterns.
I'll open a PR with tests.