Skip to content

fix(scoring): DROP recognises numeric tokens before stripping punctuation, like the official metric - #424

Merged
James-CUDA merged 2 commits into
James-CUDA:mainfrom
RealDiligent:fix/critical-drop-leading-decimal
Jul 23, 2026
Merged

fix(scoring): DROP recognises numeric tokens before stripping punctuation, like the official metric#424
James-CUDA merged 2 commits into
James-CUDA:mainfrom
RealDiligent:fix/critical-drop-leading-decimal

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Type

  • General improvement — bug fix, docs, refactor, or infrastructure (welcome but earns no TAO)

General improvement

What does this PR do?

Fixes #423.

_normalize_token strips edge punctuation — a set that includes .before trying the numeric parse, so a leading-decimal token like .5 loses its point and normalizes to "5.0":

candidate gold expected (official DROP) before after
Answer: .5 0.5 1.0 0.0 1.0
Answer: .5 5 0.0 1.0 0.0

Root cause: the official DROP _remove_punc (allennlp drop_em_and_f1) tests _is_number first and leaves numeric tokens untouched; this module's docstring promises to match that normalization but ran the strip first, corrupting exactly the token shape the official order protects. Both a false positive (an answer ten times off graded correct) and a false negative (a correct shorthand answer graded wrong).

Fix approach (minimal): try the numeric parse on the raw token (commas removed) first; only non-numeric tokens fall through to edge-punctuation stripping. One code path added, nothing removed — currency ($16), sentence-final periods (16.), thousands commas (1,234.5), preserved signs (-5), and word tokens normalize byte-identically to before (pinned by tests).

Why is it needed?

DROP golds include decimal averages/rates (0.5, 24.5) and .5-style shorthand is ordinary model output, so this diverges from the official metric on real grading traffic. Same bug class as the merged #395 (hyphen tokenization "like the official metric"). No existing test covered a leading-decimal token.

Tests: tests/test_drop_leading_decimal.py (7 cases) pins the number-first order (.5/-.5), both grading directions through score_drop, and regression-guards currency/edge-punctuation/sign/comma/word behavior unchanged.

Note on CI: current main fails Ruff/pytest by itself — src/trinity/analysis/__init__.py carries unresolved merge-conflict markers (#404, fixed by #402/#405). Like #420, this branch carries one chore(ci) commit applying the only correct resolution (credit for #404 belongs to those PRs) purely so CI can validate this fix; it resolves to a no-op once the dedicated fix lands, and I will rebase it away on request. With it, the full suite passes locally: 1736 passed, 2 skipped (+7 new), ruff check clean.

Checklist

  • Tests pass: pytest tests/ (1736 passed, 2 skipped locally; 3 Windows-only console-encoding failures unrelated to this change pass on Linux)
  • Lint passes: ruff check src/
  • Type check passes: mypy src/ (for changed files)
  • New code follows existing style
  • Public functions have docstrings and type annotations

🤖 Generated with Claude Code

RealDiligent and others added 2 commits July 23, 2026 02:34
… can validate this PR

main currently fails Ruff/pytest by itself: src/trinity/analysis/__init__.py
carries unresolved merge-conflict markers (James-CUDA#404), so every PR's merge-ref CI
is red before it reaches the PR's own changes. This commit applies the only
correct resolution — keep all three import blocks (union_diagnostics,
oracle_column, definition_of_done), the same resolution James-CUDA#402/James-CUDA#405 propose —
purely to unblock CI validation of the scoring fix in this branch. Once the
dedicated fix lands on main this resolves to a no-op in the merge (or will be
dropped by rebase); credit for the James-CUDA#404 fix belongs to those PRs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nctuation

_normalize_token stripped edge punctuation — a set that includes "." —
BEFORE trying the numeric parse, so a leading-decimal token like ".5"
lost its point and normalized to "5.0": equal to a gold "5" (a wrong
answer, ten times off, graded correct) and unequal to the
value-identical gold "0.5" (a correct answer graded wrong). The
official DROP _remove_punc tests _is_number first and leaves numeric
tokens untouched, which the module docstring already promises to match.

Fix: try the numeric parse on the raw token (commas removed) first;
only non-numeric tokens go through edge-punctuation stripping. All
surrounding behaviors are unchanged — currency ("$16"), sentence-final
periods ("16."), thousands commas ("1,234.5"), preserved signs ("-5"),
and word tokens normalize exactly as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@James-CUDA
James-CUDA merged commit 669f5c8 into James-CUDA:main Jul 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants