The extract_final_answer function does not work.
The function:
def extract_final_answer(self, response: str) -> str:
"""Extract the final numerical answer from model response."""
# Look for patterns like "The answer is X" or numbers at the end
patterns = [
r"The answer is ([+-]?\d+\.?\d*)",
r"= ([+-]?\d+\.?\d*)",
r"([+-]?\d+\.?\d*)\s*$"
]
for pattern in patterns:
matches = re.findall(pattern, response)
if matches:
return matches[-1].strip()
# Fallback: extract last number
numbers = re.findall(r'([+-]?\d+\.?\d*)', response)
return numbers[-1] if numbers else "0"
For the example:
--- Example 1 ---
Question: Janet’s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for ...
Correct: 18
Predicted: 9
Response: She bakes 4 muffins with the four duck eggs.
16 - 3 - 4 = 9
She can sell 9 fresh duck eggs, which is equal to $18.
The model predicts $18 but extract_final_answer returns 9. And is clearly wrong. Can this please be corrected?