fix: apply strip_strings/normalize in avg_at_n (preprocess was skipped) - #1385
Open
Abelo9996 wants to merge 1 commit into
Open
fix: apply strip_strings/normalize in avg_at_n (preprocess was skipped)#1385Abelo9996 wants to merge 1 commit into
Abelo9996 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
AvgAtN.computenever calledself.preprocess(), so thestrip_strings/normalizeoptions the metric is configured with were silently ignored. The registeredavg_at_nmetric isAvgAtN(strip_strings=True), and the default scorer doesgold == pred, so a generative prediction like"Paris\n"scored 0 against gold"Paris"andavg@nwas biased downward. Its siblingsMajAtNandPassAtKboth preprocess gold and predictions first.Closes #1384.
Fix
Apply
preprocessto the gold and each prediction inAvgAtN.compute, mirroringPassAtK: preprocessdoc.choicesand keepgold_index(so it stays valid), then preprocess each prediction.avg_at_n_mathis unaffected because it sets nostrip_strings/normalize, so preprocessing is a no-op there.Behaviour
avg_at_nnow strips/normalizes before matching, so whitespace-only differences no longer score 0.["Paris", "London"]still averages to 0.5).avg_at_n_mathoutput 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, andruff check/ruff format --checkare clean on the changed file.