NER F1 Calculator
Compute entity-level precision, recall, and F1 score for NER evaluation.
An entity is considered correct only if both the span (start and end positions) AND the entity type match exactly.
Input:
- predicted: list of predicted entities, each a (start, end, type) tuple
- gold: list of gold/true entities, each a (start, end, type) tuple
Output: A string with three values separated by spaces: "precision recall f1" (each rounded to 4 decimal places, e.g. 0.6667 1.0 0.8). If precision or recall is undefined (0/0), output 0.0 for that metric and F1.
Example
3 0 1 PER 4 6 LOC 8 8 ORG 2 0 1 PER 4 6 LOC
0.6667 1.0 0.8
- Inputs:
predictedholds 3 entities — , , — andgoldholds 2: , . Each entity is a token span (start, end, inclusive) plus a type label. - Matching: a prediction counts only if its start, end and type all equal some gold entity. The PER span 0–1 and the LOC span 4–6 agree exactly; the ORG at token 8 has no gold partner, so it is a false positive. Correct .
- Precision asks "how many predictions were right": . Recall asks "how many gold entities were found": .
- F1: use the exact fractions, . Rounding only happens at the end.
- Output: the string
0.6667 1.0 0.8, values rounded to 4 decimal places with trailing zeros dropped. Notice the extra ORG guess cost precision but not recall; a wrong type on a correct span (say against a gold ) would cost both.
Constraints
- An entity match requires exact start, end, AND type match
- Precision = correct / predicted_count
- Recall = correct / gold_count
- F1 = 2 * P * R / (P + R), or 0.0 if P + R = 0
- Round to 4 decimal places