opencompass icon indicating copy to clipboard operation
opencompass copied to clipboard

[Bug] first_option_postprocess returns 'A' from words like 'Answer'/'All' when the answer is bolded or boxed

Open shlokbam opened this issue 3 weeks ago • 0 comments

Prerequisite

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

  1. The cushion fallback patterns (cushion_patterns, lines 131–134 on main) are ([{options}]): and ([{options}]). They match a capital option letter anywhere, including inside a word, so the A of "Answer", "All" or "Absolutely" is returned whenever no earlier pattern matches.
  2. 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 the A of "Answer". It also doesn't check what follows the letter, so Answer: All of the above returns A from "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 \b keep Chinese outputs such as 选B working (\b treats CJK characters as word characters).
  • ANSWER pattern: 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 as L, the same "letter at the start of a word" problem (there in the ANSWER-style pattern used by match_answer_pattern).
  • #1973: a reporter changed the ANSWER pattern locally to handle **ANSWER:** C.

Out of scope / possible follow-ups

  • the answer is B, not A. returns A because of pattern order.
  • Full-width letters such as B are not recognised.
  • opencompass/datasets/mathbench.py has its own copy of first_option_postprocess with the same cushion patterns.

I'll open a PR with tests.

shlokbam avatar Nov 11 '26 14:11 shlokbam