- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 spaCy 的 NER 模型中有没有一种方法可以提取每个实体类型的指标(精度、召回率、f1 分数)?
看起来像这样的东西:
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
平均/总计 0.809 0.787 0.796 6178
取自:http://www.davidsbatista.net/blog/2018/05/09/Named_Entity_Evaluation/
谢谢!
最佳答案
好问题。
首先,我们应该澄清一下,spaCy 使用的是 BILUO 注释方案,而不是您所指的 BIO 注释方案。来自空间documentation这些字母表示以下内容:
然后,一些定义:
Spacy 有一个内置类来评估 NER。它被称为得分手。Scorer 使用精确匹配来评估 NER。精度得分作为 ents_p 返回,召回率作为 ents_r 和 F1 得分作为 ents_f。
唯一的问题是它返回文档中所有标签的分数。但是,我们可以仅使用我们想要的 TAG 调用该函数并获得所需的结果。
总的来说,代码应该是这样的:
import spacy
from spacy.gold import GoldParse
from spacy.scorer import Scorer
def evaluate(nlp, examples, ent='PERSON'):
scorer = Scorer()
for input_, annot in examples:
text_entities = []
for entity in annot.get('entities'):
if ent in entity:
text_entities.append(entity)
doc_gold_text = nlp.make_doc(input_)
gold = GoldParse(doc_gold_text, entities=text_entities)
pred_value = nlp(input_)
scorer.score(pred_value, gold)
return scorer.scores
examples = [
("Trump says he's answered Mueller's Russia inquiry questions \u2013 live",{"entities":[[0,5,"PERSON"],[25,32,"PERSON"],[35,41,"GPE"]]}),
("Alexander Zverev reaches ATP Finals semis then reminds Lendl who is boss",{"entities":[[0,16,"PERSON"],[55,60,"PERSON"]]}),
("Britain's worst landlord to take nine years to pay off string of fines",{"entities":[[0,7,"GPE"]]}),
("Tom Watson: people's vote more likely given weakness of May's position",{"entities":[[0,10,"PERSON"],[56,59,"PERSON"]]}),
]
nlp = spacy.load('en_core_web_sm')
results = evaluate(nlp, examples)
print(results)
使用适当的 ent 参数调用评估函数以获得每个标签的结果。
希望对您有所帮助:)
关于python - spaCy 的 NER 有没有办法计算每个实体类型的指标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52856057/
在 spaCy < 3.0 中,我能够在经过训练的 en_core_web_sm 模型中训练 NER 组件: python -m spacy train en model training valid
代码片段如下: In [390]: t Out[390]: ['my', 'phone', 'number', 'is', '1111', '1111', '1111'] In [391]: ner_
我正在使用 python 的内置库 nltk 来获取 stanford ner tagger api 设置,但我发现此 api 的单词标记与 stanford 的 ner tagger 网站上的在线演
我已经在我的 VM 上设置了所有安装的需求包,但我发现没有安装 nvidia GPU 驱动程序,在需求中没有 nvidia GPU 驱动程序安装说明,我想知道哪个 cuda 版本和它兼容的 nvidi
我正在尝试使用Stanford CoreNLP训练NER模型,但是找不到主类。我已经在我的CLASSPATH中包含了jar文件的路径,但仍然找不到它们。有什么办法解决这个问题吗? C:\ Users
在 opennlp 的文档中提到,我们必须用 15000 行来训练我们的模型以获得良好的性能。 现在,我必须从文档中提取不同的实体,这意味着我必须为训练数据(15000 行)中的许多标记添加不同的标签
我正在编写一些代码来执行命名实体识别 (NER),这对于英文文本来说效果很好。但是,我希望能够将 NER 应用于任何语言。为此,我想 1) 识别文本的语言,然后 2) 将 NER 应用于识别的语言。对
我正在尝试训练一种新的实体类型“HE INST”——以识别大学。 那是唯一的新标签。我有一个很长的文档作为原始文本。我在其上运行 NER 并将实体保存到 TRAIN DATA 中,然后将新实体标签添加
...或者性别信息就足够了吗?更具体地说,我有兴趣知道是否可以减少斯坦福核心 NLP 加载的模型数量以提取共指。我对实际的命名实体识别不感兴趣。 谢谢 最佳答案 根据描述使用斯坦福 CoreNLP 打
我刚刚开始使用斯坦福 CoreNLP,我想构建一个自定义 NER 模型来查找人员。 不幸的是,我没有找到一个好的意大利语ner模型。我需要在简历/简历文档中找到这些实体。 这里的问题是像这样的文档可以
我从这里学会了如何用 Java 定制斯坦福 NER(命名实体识别器): http://nlp.stanford.edu/software/crf-faq.shtml#a 但是我正在使用 Python
我需要构建一个识别特定域中的 NE 的分类器。例如,如果我的域是曲棍球或足球,分类器应该接受该域中的 NE,但不接受它在网页上看到的所有代词。我的最终目标是通过 NER 改进文本分类。 对于从事该领域
我想识别特定领域(例如棒球)中的命名实体。我知道有一些可用的工具,如斯坦福NER、LingPipe、AlchemyAPI,我已经用它们做了一些测试。但正如我之前提到的,我希望它们是针对特定领域的。这怎
我正在尝试构建一个用于产品名称及其型号的自定义命名实体提取器。 我的用例包含如下句子:“微软使用了产品 ABC-300 并将其与 ASQ 集成”。上句提到的产品是:ABC-300和ASQ 我已经尝试过
我从来没有真正处理过 NLP,但对 NER 有一个想法,它不应该起作用,但在某种情况下却做得非常好。我不明白它为什么起作用,为什么不起作用或天气可以延长。 我们的想法是通过以下方式提取故事中主要人物的
我正在寻找关于以下问题的想法/想法: 我正在处理食品成分数据,例如:牛奶、糖、鸡蛋、面粉,可能含有坚果 我希望能够从这样的文本中识别和提取像可能包含坚果这样的短语,以分别对其进行预处理 这类短语在长度
我已经创建了一个用于训练 NER 数据的数据集。创建后,我想在应用于训练管道之前测试实体和数据是否匹配。使用位移我们可以以更好的方式可视化。但是如何在 spacy 3 中完成。 最佳答案 上面问题的代
执行此 Stanford NLP FAQ 中的步骤后,我能够生成模型的 zip 文件。但在文档中,他们使用 TSV 文件来计算针对已注释文件的预测准确性,但没有任何文档说明如何针对新文件对其进行测试!
我在检测以小写字母开头的命名实体时遇到问题。如果我只用小写单词训练模型,那么准确率是合理的;但是,当模型使用完全大写的标记或什至是小写和大写混合训练时,结果非常糟糕。我尝试了斯坦福 NLP 小组提供的
我现在正在使用一些 NLP 库,(stanford 和 nltk) 斯坦福我看到了演示部分,但只是想问问是否可以用它来识别更多的实体类型。 因此,目前斯坦福 NER 系统(如演示所示)可以将实体识别为
我是一名优秀的程序员,十分优秀!