Fix CorpusLevelF1Score(None) to report positive-class F1, not max-per-class#1275
Open
iamsharduld wants to merge 1 commit into
Open
Fix CorpusLevelF1Score(None) to report positive-class F1, not max-per-class#1275iamsharduld wants to merge 1 commit into
iamsharduld wants to merge 1 commit into
Conversation
…-class The num_classes==2 branch returned np.max(f1_score(..., average=None)). With average=None, f1_score returns the per-class F1 array, so np.max reports the BEST class's F1 instead of the positive-class binary F1 -- inflating the score. loglikelihood_f1 (glue:mrpc, glue:qqp) uses CorpusLevelF1Score(None), so those scores were overstated. Return the positive class (fscore[1]); scalar averages (micro/macro/weighted) pass through unchanged.
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
CorpusLevelF1Score.compute_corpus(thenum_classes == 2path) returnsnp.max(f1_score(golds, preds, average=self.average)). Whenaverage=None— which is howMetrics.loglikelihood_f1instantiates it (CorpusLevelF1Score(None), used byglue:mrpcandglue:qqp) —f1_scorereturns the per-class F1 array, sonp.maxreports the best class'sF1 rather than the positive-class binary F1, inflating the score.
Fix
When
average is None, return the positive classfscore[1]. Scalar averages(
micro/macro/weighted) are unchanged (np.maxof a scalar was a no-op).Tests
tests/test_unit_base_metrics.py::test_corpus_level_f1_binary_positive_classasserts thepositive-class F1 (
1/3) on a fixture where the max-per-class would be~0.714. Fails before,passes after.