【发布时间】:2021-03-27 20:57:51
【问题描述】:
当我使用 SpaCy NER 时,SpaCy 会将“TodoA”识别为 PERSON。这显然是不合理的。有没有办法验证SpaCy提取的实体是否合理?谢谢!
这些不合理的实体大多是通过spacy beam search 提取的。束搜索代码为:
import spacy
import sys
from collections import defaultdict
nlp = spacy.load('en')
text = u'Will Japan join the European Union? If yes, we should \
move to United States. Fasten your belts, America we are coming'
with nlp.disable_pipes('ner'):
doc = nlp(text)
threshold = 0.2
(beams, somethingelse) = nlp.entity.beam_parse([ doc ], beam_width = 16, beam_density = 0.0001)
entity_scores = defaultdict(float)
for beam in beams:
for score, ents in nlp.entity.moves.get_beam_parses(beam):
for start, end, label in ents:
entity_scores[(start, end, label)] += score
print ('Entities and scores (detected with beam search)')
for key in entity_scores:
start, end, label = key
score = entity_scores[key]
if ( score > threshold):
print ('Label: {}, Text: {}, Score: {}'.format(label, doc[start:end], score))
【问题讨论】:
-
SpaCy 下面有神经网络,用于处理有监督学习的特征属性。如果您对使用的功能、分配的确定性或多类概率感兴趣,那么您的问题并不清楚。请澄清。
-
嗨@SergeyBushmanov 它与底层神经网络无关。我只是使用 spacy 中的预训练模型 en_core_web_lg 进行实体提取,并使用了 beam_search。当句子中包含'TodoA'时,spacy en_core_web_lg会识别'TodoA'为人,而'TodoA'显然不是人名,所以spacy en_core_web_lg识别错误,我现在要做的是判断其合理性spacy en_core_web_lg 提取的实体
标签: machine-learning nlp spacy named-entity-recognition