Skip to content

fix(mcqa): boxed answer extraction - #1844

Merged
marta-sd merged 7 commits into
mainfrom
fsiino/fix-mcqa-boxed-answer-extraction
Jul 10, 2026
Merged

marta-sd merged 7 commits into
mainfrom
fsiino/fix-mcqa-boxed-answer-extraction

Conversation

@fsiino-nvidia

@fsiino-nvidia fsiino-nvidia commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

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 ✓

…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]>
@copy-pr-bot

copy-pr-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

…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
fsiino-nvidia marked this pull request as ready for review June 30, 2026 23:59
Comment thread resources_servers/mcqa/app.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: outdated docstring

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Fixed in f1e0e98

@marta-sd

Copy link
Copy Markdown
Contributor

/ok to test 99de3be

@marta-sd
marta-sd enabled auto-merge (squash) July 10, 2026 06:46
@marta-sd
marta-sd merged commit c59e3cc into main Jul 10, 2026
14 checks passed
@marta-sd
marta-sd deleted the fsiino/fix-mcqa-boxed-answer-extraction branch 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

1 inactive deployment
public — 99de3be7 Deployed Jul 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mcqa strict_single_letter_boxed undercounts correct answers wrapped in LaTeX \text{}

2 participants