From 98c0aad1b496712a365676503c937408aab9c789 Mon Sep 17 00:00:00 2001 From: marktech0813 Date: Fri, 24 Jul 2026 15:11:54 +0000 Subject: [PATCH] =?UTF-8?q?fix(scoring):=20normalize=20=E2=88=9E=20and=20\?= =?UTF-8?q?infty=20to=20the=20same=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #495 --- pyproject.toml | 2 +- src/trinity/adapters/drop.py | 12 +++++++----- src/trinity/orchestration/reward.py | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 02d4f008..e911c0da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ ] [project.optional-dependencies] -dev = ["pytest>=8.0", "ruff>=0.5", "mypy>=1.10"] +dev = ["pytest>=8.0", "ruff>=0.5,<0.16", "mypy>=1.10"] [build-system] requires = ["hatchling"] diff --git a/src/trinity/adapters/drop.py b/src/trinity/adapters/drop.py index 1314803f..2db3f03c 100644 --- a/src/trinity/adapters/drop.py +++ b/src/trinity/adapters/drop.py @@ -132,7 +132,7 @@ def _maybe_unbox(segment: str) -> str: #: Surrounding punctuation stripped from a token, EXCLUDING the signs ``+``/``-`` — a #: leading sign is part of a number's value, not wrapping noise. -_STRIP_EDGE = "".join(c for c in string.punctuation if c not in "+-") +_STRIP_EDGE = "".join(c for c in string.punctuation if c not in "+-.") def _normalize_token(raw: str) -> str: @@ -157,10 +157,12 @@ def _normalize_token(raw: str) -> str: except ValueError: pass core = raw.strip(_STRIP_EDGE) - try: - return str(float(core.replace(",", ""))) - except ValueError: - return _PUNCT.sub("", raw) + for cand in (core, core.rstrip(".")): + try: + return str(float(cand.replace(",", ""))) + except ValueError: + continue + return _PUNCT.sub("", raw) def _split_internal_hyphens(token: str) -> list[str]: diff --git a/src/trinity/orchestration/reward.py b/src/trinity/orchestration/reward.py index 7192ef8e..d411caec 100644 --- a/src/trinity/orchestration/reward.py +++ b/src/trinity/orchestration/reward.py @@ -842,6 +842,8 @@ def normalize_math_answer(ans: str | None) -> str: # (the product symbol) is intentionally left untouched. s = re.sub(r"\\pi(?![a-zA-Z])", "pi", s) s = s.replace("π", "pi") + s = s.replace("∞", "oo") + s = re.sub(r"\\infty(?![a-zA-Z])", "oo", s) # The fraction normalizer wraps arbitrary operands, so ``\frac{\pi}{2}`` # becomes ``(pi)/(2)`` while ``\pi/2`` becomes ``pi/2``. Remove only # standalone atomic operands adjacent to division — including a lone