Skip to content

fix: correct overall PerClassScorer totals collapsed by set comprehension#622

Open
Chessing234 wants to merge 1 commit into
allenai:mainfrom
Chessing234:fix/per-class-scorer-overall-dedup
Open

fix: correct overall PerClassScorer totals collapsed by set comprehension#622
Chessing234 wants to merge 1 commit into
allenai:mainfrom
Chessing234:fix/per-class-scorer-overall-dedup

Conversation

@Chessing234

Copy link
Copy Markdown

Bug

PerClassScorer.get_metric computes the overall totals with set comprehensions:

sum_true_positives = sum({v for k, v in self._true_positives.items() if k != "untyped"})

The set collapses equal per-tag counts into one, so totals are undercounted and overall precision/recall/F1 are wrong whenever two tags share a count.

Repro

s = PerClassScorer()
pred = [(0,1,'A'),(2,3,'A'),(4,5,'B'),(6,7,'B'),(8,9,'B'),(10,11,'B'),(12,13,'B')]
gold = [(0,1,'A'),(2,3,'A'),(4,5,'B'),(6,7,'B')]
s(pred, gold)
s.get_metric()["precision-overall"]  # before: 0.4 ; after: 0.5714 (=4/7)

Fix

Use generator comprehensions instead of set comprehensions for the three sums.

Made with Cursor

…sion

get_metric summed per-tag counts with a set comprehension
(`sum({v for ...})`), so equal counts across tags collapsed to one,
undercounting true/false positives/negatives and skewing overall
precision/recall/F1. Use generators instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant