MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / parse_answer

Function parse_answer

src/benchmarks/aime/evaluate.py:17–37  ·  view source on GitHub ↗

r"""Extract the answer from the model response using math-verify. Tries to parse the last \boxed{} expression. Falls back to extracting raw \boxed{} content if math-verify parsing fails.

(response: str)

Source from the content-addressed store, hash-verified

15
16
17def parse_answer(response: str) -> Optional[str]:
18 r"""Extract the answer from the model response using math-verify.
19
20 Tries to parse the last \boxed{} expression. Falls back to extracting
21 raw \boxed{} content if math-verify parsing fails.
22 """
23 # First try math-verify's robust parser
24 try:
25 parsed = parse(response)
26 if parsed:
27 # Return string representation for logging; actual comparison uses verify()
28 return str(parsed[-1]).strip()
29 except Exception:
30 pass
31
32 # Fallback: manually extract last \boxed{}
33 results = _extract_boxed(response)
34 if results:
35 return results[-1].strip()
36
37 return None
38
39
40def _extract_boxed(text: str) -> list[str]:

Callers 1

_run_single_problemFunction · 0.90

Calls 1

_extract_boxedFunction · 0.85

Tested by

no test coverage detected