From 80594cd38cb265e72159942b0a10b232ddee01d4 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Thu, 4 Jun 2026 14:30:35 +0300 Subject: [PATCH] Handle percent/decimal convention in Number-Match --- evaluations/evaluations/numbers.py | 4 ++++ evaluations/tests/test_evaluators.py | 8 ++++++++ evaluations/tests/test_numbers.py | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/evaluations/evaluations/numbers.py b/evaluations/evaluations/numbers.py index d0778000..0bf3c8ed 100644 --- a/evaluations/evaluations/numbers.py +++ b/evaluations/evaluations/numbers.py @@ -47,6 +47,10 @@ def extract_numbers(text: str) -> list[float]: value = _to_float(token) if value is not None: numbers.append(value) + if "%" in token: + # Gold answers store ratios as either a percent (24.69) or a + # decimal (0.935); offer both readings of a percent figure. + numbers.append(value / 100) for number, scale in _SCALED_RE.findall(text): value = _to_float(number) if value is not None: diff --git a/evaluations/tests/test_evaluators.py b/evaluations/tests/test_evaluators.py index 936d0392..97dbbb19 100644 --- a/evaluations/tests/test_evaluators.py +++ b/evaluations/tests/test_evaluators.py @@ -82,6 +82,14 @@ class TestNumberMatchEvaluator: ctx = self._make_ctx("50.3", "In 2008 it grew from 27.0 to 50.3 percent") assert self.evaluator.evaluate(ctx) == 1.0 + def test_percent_answer_matches_decimal_gold(self) -> None: + ctx = self._make_ctx("0.935", "the cumulative total return was 93.5%") + assert self.evaluator.evaluate(ctx) == 1.0 + + def test_percent_answer_matches_percent_gold(self) -> None: + ctx = self._make_ctx("24.691358024691358", "approximately 24.69% of production") + assert self.evaluator.evaluate(ctx) == 1.0 + def test_non_numeric_prediction(self) -> None: ctx = self._make_ctx("127.4", "I cannot determine the value") assert self.evaluator.evaluate(ctx) == 0.0 diff --git a/evaluations/tests/test_numbers.py b/evaluations/tests/test_numbers.py index 2f38a376..0cc937c4 100644 --- a/evaluations/tests/test_numbers.py +++ b/evaluations/tests/test_numbers.py @@ -8,8 +8,8 @@ class TestExtractNumbers: def test_currency_and_thousands(self) -> None: assert extract_numbers("$1,234.5") == [1234.5] - def test_percent_stripped(self) -> None: - assert extract_numbers("margin was 50.3%") == [50.3] + def test_percent_yields_both_readings(self) -> None: + assert extract_numbers("margin was 50.3%") == [50.3, 0.503] def test_parenthesised_negative(self) -> None: assert extract_numbers("loss of (123)") == [-123.0]