is there a way in the NER model in spaCy to extract the metrics (precision, recall, f1 score) per entity type?
Something that will look like this:
precision recall f1-score support
B-LOC 0.810 0.784 0.797 1084
I-LOC 0.690 0.637 0.662 325
B-MISC 0.731 0.569 0.640 339
I-MISC 0.699 0.589 0.639 557
B-ORG 0.807 0.832 0.820 1400
I-ORG 0.852 0.786 0.818 1104
B-PER 0.850 0.884 0.867 735
I-PER 0.893 0.943 0.917 634
avg / total 0.809 0.787 0.796 6178
taken from: http://www.davidsbatista.net/blog/2018/05/09/Named_Entity_Evaluation/
Thank you!
@gdaras 's answer is not right. The first comment gives the idea why. You should filter entities of
I did it like this
I have been working on this, and now its integrated withing spacy by this Pull Request.
Now you just need to call
Scorer().scores
and it will return the usual dict with an additional key,ents_per_type
, that will contains the metrics Precision, Recall and F1-Score for each entity.Hope it helps!
Nice question.
First, we should clarify that spaCy uses the BILUO annotation scheme instead of the BIO annotation scheme you are referring to. From the spacy documentation the letters denote the following:
Then, some definitions:
Spacy has a built-in class to evaluate NER. It's called scorer. Scorer uses exact matching to evaluate NER. The precision score is returned as ents_p, the recall as ents_r and the F1 score as ents_f.
The only problem with that is that it returns the score for all the tags together in the document. However, we can call the function only with the TAG we want and get the desired result.
All together, the code should look like this:
Call the evaluate function with the proper ent parameter to get the results for each tag.
Hope it helps :)