How to compute a confusion matrix using spaCy's Scorer/Example classes? #12682
-
I am trying to calculate the Accuracy and Specificity of a NER model using spaCy's API. The scorer.scores(example) method found here computes the Recall, Precision and F1_Score for the spans predicted by the model, but does not allow for the extrapolation of TP, FP, TN, or FN. Below is the code I have currently written, with an example of the data structure I am using when passing my expected found entites into the model. Code Being Used to Score the Model:
The data structure I am currently using to load the Example class (list of dictionaries): example_list[0] {'full_text': 'I would like to remove my kid Florence from the will. How do I do that?', 'entities': [(30, 38, 'PERSON')]} The result that I am returning from running print(scores) is as expected; a dictionary of tokenization's precision, recall, f1_score, as well as the entity recognition's precision, recall and f1_score.
How can I extrapolate the TP, FP, TN and FN from this function using some form of an attribute? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This isn't currently supported by the provided scorers (you haven't overlooked any built-in options), but you can replace the default scorer with your own custom registered scoring method in the Here are what the basics look like when you define a custom scorer (this example just modifies the names of the returned keys): spaCy/spacy/tests/test_language.py Lines 188 to 199 in 9b7a59c You'd usually provide your custom scorer with The current NER scorer is here: Lines 750 to 792 in 9b7a59c |
Beta Was this translation helpful? Give feedback.
This isn't currently supported by the provided scorers (you haven't overlooked any built-in options), but you can replace the default scorer with your own custom registered scoring method in the
scorer
setting in the config.Here are what the basics look like when you define a custom scorer (this example just modifies the names of the returned keys):
spaCy/spacy/tests/test_language.py
Lines 188 to 199 in 9b7a59c