Repository navigation
Conversation
…verage `evaluate_accuracy` rescales sklearn's macro average by the ratio of all label names to the labels that have support, to undo the zeros sklearn contributes for labels that never occur in the truth. A label that never occurs in the truth but is still predicted was being dropped from that count as well. Every prediction of such a label is a false positive, so it has a measured precision of 0, and the rescale hid it: with 100 correctly labelled ADDRESS characters and 100 background characters tagged SSN, the returned f1 was 1.0000 while the micro precision was 0.5. A label now counts as active when it occurs in the truth (support) or when anything was predicted as it, which is its column in the confusion matrix being non-empty. The four existing cases in TestEvaluateAccuracy are unchanged, and a label that neither the truth nor the prediction used is still excluded from the average. Fixes capitalone#1229
This branch has not been deployed
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.
Fixes #1229.
evaluate_accuracyrescales sklearn's macro average bylen(label_names) / labels with support, to undo the zeros sklearn contributes for labels that never occur in the truth. The count that produces that denominator looked only atsupport, so a label that never occurs in the truth but is still predicted was dropped from it too. Every prediction of such a label is a false positive, so it has a measured precision of 0 — and dropping it both hid those false positives and inflated the rescale.Measured before the change
Running the function with the mapping
{0: PAD, 1: UNKNOWN, 2: ADDRESS, 3: SSN, 4: PERSON}and the defaultomitted_labels, on ground truth of 100ADDRESScharacters plus 100 background characters:f1SSNSSN+PERSONADDRESScharacters taggedSSNADDRESSSSNA model that tags background text with an absent label scored a perfect
f1, and mislabelling 40% of one label's characters did not move the precision component at all.Change
A label counts toward the average when it occurs in the truth (
support) or when anything was predicted as it, which is its column of the confusion matrix being non-empty:After it, the same cases return 0.5000, 0.3333 and 0.3750 — the average over the labels that the truth or the prediction actually used. The controls are untouched, and a label that neither side used is still excluded.
Tests
Two cases added next to
test_no_support_classes:test_predicted_label_without_support_lowers_f1— the false positive now costs half the returnedf1, and the per-label row showsprecision 0withsupport 0.test_label_neither_predicted_nor_in_truth_is_still_excluded— the rescale still ignores a label nobody used, which is whattest_no_support_classesrelies on.All six cases in
TestEvaluateAccuracypass, and the four existing ones return exactly the values they did before. This environment cannot install TensorFlow, so I ran them throughunittestwithlabeler_utils' module-levelimport tensorflowstubbed; nothing inevaluate_accuracytouches it.black,isortandflake8are clean on both files.Credit for the analysis in #1229 — the code location, the measured table and the direction of the fix are all from that report.