edwinjilson's picture
chore: Prepare for Hugging Face Spaces deployment
77d2598
Raw
History Blame Contribute Delete
861 Bytes
import re
from typing import Any
from benchmarks.procedural.interfaces import Evaluator
class NumericEvaluator(Evaluator):
@property
def name(self) -> str:
return "numeric"
def evaluate(self, answer: str, ground_truth: Any) -> bool:
if not isinstance(ground_truth, (int, float)):
try:
ground_truth = float(ground_truth)
except ValueError:
return False
# Extract the last number from the model's answer (common heuristic)
# Handle negative numbers and decimals
matches = re.findall(r'-?\d+\.?\d*', str(answer))
if not matches:
return False
model_val = float(matches[-1])
# Check tolerance (e.g. 1e-4)
return abs(model_val - float(ground_truth)) < 1e-4