1
我正在评估使用spacy lib创建的训练有素的NER模型。 通常对于这类问题,您可以使用f1分数(精度和召回之间的比例)。我无法在文档中找到经过训练的NER模型的精确度函数。在Spacer NER模型中的评估
我不知道,如果它的正确的,但我想用下面的方式(例如)做到这一点,并使用f1_score
从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 a format acceptable for sklearn f1 function
y_true = ["PERSON" if "PERSON" in x else 'O' for x in gold.ner]
y_predicted = [x.ent_type_ if x.ent_type_ !='' else 'O' for x in doc_to_test]
f1_score(y_true, y_predicted, average='macro')`[1]
> 1.0
任何想法或见解是有用的。
1.你github上链接断开 2.什么是自我在这种情况下?我可以在哪里找到self.make_gold? – farlee2121
@ farlee2121我已经更新了答案 更清晰。 –