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

Function verify_answer

src/benchmarks/aime/evaluate.py:76–105  ·  view source on GitHub ↗

Verify if the model's answer matches the ground truth using math-verify. Args: model_response: The full model response text. ground_truth: The ground truth answer (string of an integer for AIME). Returns: True if the answer is correct, False otherwise.

(model_response: str, ground_truth: str)

Source from the content-addressed store, hash-verified

74
75
76def verify_answer(model_response: str, ground_truth: str) -> bool:
77 """Verify if the model's answer matches the ground truth using math-verify.
78
79 Args:
80 model_response: The full model response text.
81 ground_truth: The ground truth answer (string of an integer for AIME).
82
83 Returns:
84 True if the answer is correct, False otherwise.
85 """
86 gt_normalized = _normalize_ground_truth(ground_truth)
87
88 try:
89 gold = parse(gt_normalized)
90 pred = parse(model_response)
91 if gold and pred:
92 return verify(gold, pred)
93 except Exception:
94 pass
95
96 # Fallback: exact string match on extracted boxed answer
97 parsed = _extract_boxed(model_response)
98 if parsed:
99 # AIME answers are integers; normalize by stripping leading zeros
100 try:
101 return int(parsed[-1].strip()) == int(gt_normalized.strip())
102 except (ValueError, TypeError):
103 pass
104
105 return False
106
107
108def evaluate(

Callers 1

_run_single_problemFunction · 0.90

Calls 2

_normalize_ground_truthFunction · 0.85
_extract_boxedFunction · 0.85

Tested by

no test coverage detected