我正在尝试评估使用spacy lib创建的训练有素的NER模型.通常对于这些问题,您可以使用f1分数(精确度和召回率之间的比率).我在文档中找不到训练有素的NER模型的精确度函数.
我不确定它是否正确,但我尝试使用以下方式(示例)并使用f1_scorefrom sklearn:
from sklearn.metrics import f1_score
import spacy
from spacy.gold import GoldParse
nlp = spacy.load("en") #load NER model
test_text = "my name is John" # text to test accuracy
doc_to_test = nlp(test_text) # transform the text to spacy doc format
# we create a golden doc where we know the tagged entity for the text to be tested
doc_gold_text= nlp.make_doc(test_text)
entity_offsets_of_gold_text = [(11, 15,"PERSON")]
gold = GoldParse(doc_gold_text, entities=entity_offsets_of_gold_text)
# bring the data in …Run Code Online (Sandbox Code Playgroud)