Skip to content
DeepForgeby svx
All problems
HardNLPnlp-282

NER Micro-F1 Across Sentences

Problem

Compute entity-level micro-F1 over a corpus. gold_docs and pred_docs are parallel lists of documents, and each document is a list of [start, end, label] spans.

Matches are exact [start, end, label] tuples, repeated spans are clipped by multiplicity, and TP, FP, and FN are pooled over all documents. Return 1.0 when both corpora are empty and 0.0 when there are no matches.

Hint

Pool true positives, false positives, and false negatives across all documents before computing micro-F1.

Test cases

case 1
in: [[[[0,2,"PER"],[3,5,"LOC"]]],[[[0,2,"PER"],[3,5,"LOC"]]]]
expected: 1
case 2
in: [[[[0,2,"PER"]]],[[[0,2,"LOC"]]]]
expected: 0
case 3
in: [[[],[]],[[],[]]]
expected: 1
case 4
in: [[[[0,2,"PER"],[4,6,"ORG"]]],[[[0,2,"PER"],[4,7,"ORG"],[9,10,"MISC"]]]]
expected: 0.4
case 5
in: [[[[0,1,"A"]],[[2,3,"B"]]],[[[0,1,"A"]],[]]]
expected: 0.6666666666666666
Starter codePython
def ner_micro_f1(gold_docs, pred_docs):
    # Your code here
    pass

5 test cases · run your code against them in the editor