Repository navigation
fix(mcqa): boxed answer extraction - #1844
Merged
Merged
Conversation
…option text
Strict grading scored correct answers as no_answer for \boxed{\text{E}} and \boxed{E: ...}. Read the answer letter even when inside \text{} or followed by option text. Add regression tests.
Signed-off-by: Frankie Siino <[email protected]>
…he answer
- strict_single_letter_boxed read the FIRST \boxed{...}, so a boxed intermediate candidate may hide the real answer.
- Switch _extract_boxed_inner() to rfind() so the final box wins.
- Add regression tests and update the README.
Signed-off-by: Frankie Siino <[email protected]>
fsiino-nvidia
marked this pull request as ready for review
June 30, 2026 23:59
…-answer-extraction Signed-off-by: Frankie Siino <[email protected]>
Signed-off-by: Frankie Siino <[email protected]>
marta-sd
reviewed
Jul 9, 2026
Signed-off-by: Frankie Siino <[email protected]>
…-answer-extraction Signed-off-by: Frankie Siino <[email protected]>
marta-sd
approved these changes
Jul 10, 2026
Contributor
|
/ok to test 99de3be |
marta-sd
enabled auto-merge (squash)
July 10, 2026 06:46
OlegSudakov
pushed a commit
to OlegSudakov/Gym
that referenced
this pull request
Jul 15, 2026
## Summary
The MCQA verifier's `strict_single_letter_boxed` grading mode only
accepted a single uppercase letter directly inside `\boxed{...}`. Real
model rollouts frequently emit the answer wrapped in `\text{}` (e.g.
`\boxed{\text{E}}`) or with the option text appended after the letter
(e.g. `\boxed{E: A polygenic risk score...}`), and these were
incorrectly scored as `no_answer`. This PR rewrites the boxed-letter
extraction to tolerate those formats while preserving strict semantics,
recovering rewards that were previously lost on valid answers.
## Key Changes
- Replaced the single regex (`STRICT_BOXED_PATTERN`) with a
brace-counting helper `_extract_boxed_inner()` that returns the full
contents of the last `\boxed{...}`, correctly handling nested braces
like `\boxed{\text{E}}` instead of stopping at the first `}`. Selecting
the last box means CoT intermediate boxes (e.g. `\boxed{C} ...
\boxed{E}`) no longer shadow the final answer, matching the convention
in `math_with_code`/`abstention`.
- Strict extraction now strips `\text{...}` wrappers, then matches
either a bare padded letter (`BOXED_LETTER_ONLY_PATTERN`) or a leading
letter followed by a label delimiter (`:`, `)`, `.`, `-`) with trailing
option text ignored (`BOXED_LETTER_LABEL_PATTERN`).
- Strict mode deliberately does not match bare option text without a
leading letter - that remains `lenient_boxed`'s responsibility -
preserving the boundary between the two modes.
- `_match_option_text` (lenient mode) reuses the same
`_extract_boxed_inner()` helper, so lenient inherits both the
nested-brace and last-box handling.
- README grading-mode docs updated to describe the new tolerated
formats, last-box selection, and the explicit non-match case.
## Validation
Validated the extractor directly (in isolation from model sampling)
across the boxed-answer formats seen in real rollouts from
gpt-4.1-2025-04-14:
- **Recovered formats** - `\boxed{\text{E}}`, `\boxed{E: <option
text>}`, and `\boxed{\text{C: <option text>}}` now resolve to their
letter instead of scoring `no_answer` (the formats models emit when they
ignore the "letter and nothing else" prompt).
- **Last box wins** - with multiple `\boxed{...}` (e.g. a CoT
intermediate before the final answer), the extractor reads the last one;
verified for both a letter intermediate (`\boxed{C} ... \boxed{E}` ->
`E`) and a non-letter one (`\boxed{\text{idea}} ... \boxed{E}` -> `E`).
- **Strict stays strict** - bare option text with no leading letter
(`\boxed{A polygenic...}`) is deliberately left unmatched, preserving
the `strict` / `lenient_boxed` boundary.
- **Fails safe** - an unbalanced `\boxed{` returns `no_answer`, not a
crash.
- **Lenient inheritance** - `lenient_boxed` picks up the same `\text{}`
and nested-brace handling through the shared helper.
| Boxed output | `main` | this branch |
|---|---|---|
| `\boxed{\text{E}}` | `no_answer` | `E` ✓ |
| `\boxed{\text{B: Polymerase Chain Reaction (PCR)}}` | `no_answer` |
`B` ✓ |
| `\boxed{E: \text{A polygenic risk score...}}` | `no_answer` | `E` ✓ |
| `\boxed{\text{I: NGS can detect...}}` | `no_answer` | `I` ✓ |
---------
Signed-off-by: Frankie Siino <[email protected]>
Co-authored-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Oleg Sudakov <[email protected]>
This branch was previously 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
The MCQA verifier's
strict_single_letter_boxedgrading mode only accepted a single uppercase letter directly inside\boxed{...}. Real model rollouts frequently emit the answer wrapped in\text{}(e.g.\boxed{\text{E}}) or with the option text appended after the letter (e.g.\boxed{E: A polygenic risk score...}), and these were incorrectly scored asno_answer. This PR rewrites the boxed-letter extraction to tolerate those formats while preserving strict semantics, recovering rewards that were previously lost on valid answers.Key Changes
STRICT_BOXED_PATTERN) with a brace-counting helper_extract_boxed_inner()that returns the full contents of the last\boxed{...}, correctly handling nested braces like\boxed{\text{E}}instead of stopping at the first}. Selecting the last box means CoT intermediate boxes (e.g.\boxed{C} ... \boxed{E}) no longer shadow the final answer, matching the convention inmath_with_code/abstention.\text{...}wrappers, then matches either a bare padded letter (BOXED_LETTER_ONLY_PATTERN) or a leading letter followed by a label delimiter (:,),.,-) with trailing option text ignored (BOXED_LETTER_LABEL_PATTERN).lenient_boxed's responsibility - preserving the boundary between the two modes._match_option_text(lenient mode) reuses the same_extract_boxed_inner()helper, so lenient inherits both the nested-brace and last-box handling.Validation
Validated the extractor directly (in isolation from model sampling) across the boxed-answer formats seen in real rollouts from gpt-4.1-2025-04-14:
\boxed{\text{E}},\boxed{E: <option text>}, and\boxed{\text{C: <option text>}}now resolve to their letter instead of scoringno_answer(the formats models emit when they ignore the "letter and nothing else" prompt).\boxed{...}(e.g. a CoT intermediate before the final answer), the extractor reads the last one; verified for both a letter intermediate (\boxed{C} ... \boxed{E}->E) and a non-letter one (\boxed{\text{idea}} ... \boxed{E}->E).\boxed{A polygenic...}) is deliberately left unmatched, preserving thestrict/lenient_boxedboundary.\boxed{returnsno_answer, not a crash.lenient_boxedpicks up the same\text{}and nested-brace handling through the shared helper.main\boxed{\text{E}}no_answerE✓\boxed{\text{B: Polymerase Chain Reaction (PCR)}}no_answerB✓\boxed{E: \text{A polygenic risk score...}}no_answerE✓\boxed{\text{I: NGS can detect...}}no_answerI✓