PIXELBANKv9.1.0
Menu

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 format:

  • Line 1: Number of predicted entities P
  • Lines 2 to P+1: start end type (predicted entities)
  • Line P+2: Number of gold/true entities G
  • Lines P+3 to P+G+2: start end type (gold entities)

Output: Three values on one line: precision recall f1 (each rounded to 4 decimal places). If precision or recall is undefined (0/0), output 0.0 for that metric and F1.

Example:

Input:
3
0 1 PER
4 6 LOC
8 8 ORG
2
0 1 PER
4 6 LOC
Output:
0.6667 1.0 0.8
Reasoning:

Predicted entities: (0,1,PER), (4,6,LOC), (8,8,ORG) Gold entities: (0,1,PER), (4,6,LOC)

Matches: (0,1,PER) and (4,6,LOC) both match => 2 correct

Precision: 2/3 = 0.6667 (2 correct out of 3 predicted) Recall: 2/2 = 1.0 (2 correct out of 2 gold) F1: 2 * 0.6667 * 1.0 / (0.6667 + 1.0) = 1.3333 / 1.6667 = 0.8

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
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
NER F1 Calculator - Medium | PixelBank