Fix set-zip misalignment in PerClassScorer.__call__#571
Open
Chessing234 wants to merge 1 commit intoallenai:mainfrom
Open
Fix set-zip misalignment in PerClassScorer.__call__#571Chessing234 wants to merge 1 commit intoallenai:mainfrom
Chessing234 wants to merge 1 commit intoallenai:mainfrom
Conversation
untyped_predicted_spans is a set (unordered), so zipping it with predicted_spans (a list) pairs unrelated spans together. Derive untyped_span directly from span inside the loop instead.
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.
Bug
In
PerClassScorer.__call__(),untyped_predicted_spansis built as a set comprehension (line 21), then zipped withpredicted_spans(a list) on line 23. Since Python sets are unordered, the i-th element yielded by iterating the set does not correspond to the i-th element of the list. This meansuntyped_spanandspanin each loop iteration refer to unrelated predictions, corrupting both the typed and untyped precision/recall/F1 metrics.A secondary issue: if multiple predicted spans share the same
(start, end)but differ in label, the set deduplicates them, making it shorter than the list.zipsilently stops at the shorter iterable, so some predictions are never evaluated.Root cause
Line 23 assumes set iteration order matches list order, which is not guaranteed.
Fix
Derive
untyped_spandirectly fromspaninside the loop body instead of zipping with the set. This guarantees the untyped version always corresponds to the correct typed prediction.