Skip to content

fix: apply strip_strings/normalize in avg_at_n (preprocess was skipped) - #1385

Open
Abelo9996 wants to merge 1 commit into
huggingface:mainfrom
Abelo9996:fix-avg-at-n-preprocess
Open

fix: apply strip_strings/normalize in avg_at_n (preprocess was skipped)#1385
Abelo9996 wants to merge 1 commit into
huggingface:mainfrom
Abelo9996:fix-avg-at-n-preprocess

Conversation

@Abelo9996

Copy link
Copy Markdown

What

AvgAtN.compute never called self.preprocess(), so the strip_strings / normalize options the metric is configured with were silently ignored. The registered avg_at_n metric is AvgAtN(strip_strings=True), and the default scorer does gold == pred, so a generative prediction like "Paris\n" scored 0 against gold "Paris" and avg@n was biased downward. Its siblings MajAtN and PassAtK both preprocess gold and predictions first.

Closes #1384.

Fix

Apply preprocess to the gold and each prediction in AvgAtN.compute, mirroring PassAtK: preprocess doc.choices and keep gold_index (so it stays valid), then preprocess each prediction. avg_at_n_math is unaffected because it sets no strip_strings/normalize, so preprocessing is a no-op there.

Behaviour

  • avg_at_n now strips/normalizes before matching, so whitespace-only differences no longer score 0.
  • Exact-match and mixed-correctness cases are unchanged (e.g. ["Paris", "London"] still averages to 0.5).
  • avg_at_n_math output is unchanged.

Tests

Adds a whitespace regression case to tests/unit/metrics/test_cases/avg_at_k.json ("Paris\n", " Paris" against gold "Paris" now averages to 1.0; it scored 0.0 before the fix). The existing avg/maj/pass metric suites still pass, and ruff check/ruff format --check are clean on the changed file.

AvgAtN.compute scored each prediction with compute_score(doc, model_response[i]) and never called
self.preprocess(), unlike its siblings MajAtN and PassAtK. The registered avg_at_n metric is built as
AvgAtN(strip_strings=True), so that setting was silently ignored: with the default exact-match scorer a
prediction like "Paris\n" scored 0 against gold "Paris", systematically under-counting avg@n.

Apply preprocess to the gold and each prediction before scoring, mirroring PassAtK (preprocess
doc.choices and keep gold_index, so gold_index stays valid). avg_at_n_math is unaffected: it sets no
strip_strings/normalize, so preprocess is a no-op there.

Add a whitespace regression case to the avg_at_k metric test suite.

Closes huggingface#1384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

avg_at_n silently ignores strip_strings/normalize (preprocess not applied), deflating scores

1 participant