3 回答

TA贡献1812条经验 获得超5个赞
不,不可能在 Spacy 中获得模型的置信度分数(不幸的是)。
虽然使用 F1 分数有利于整体评估,但我更希望 Spacy 为其预测提供个人置信度分数,而目前还没有提供。

TA贡献1744条经验 获得超4个赞
对此没有直接的解释。首先,spaCy
为命名实体解析实现两个不同的目标:
贪婪的模仿学习目标。这个目标询问,“如果我从这个状态执行,哪些可用的操作不会引入新的错误?”
全局波束搜索目标。全局模型不是优化单个转换决策,而是询问最终解析是否正确。为了优化这个目标,我们构建了 top-k 最有可能不正确解析和 top-k 最可能正确解析的集合。
注意:测试过spaCy v2.0.13
import spacy
import sys
from collections import defaultdict
nlp = spacy.load('en')
text = 'Hi there! Hope you are doing good. Greetings from India.'
with nlp.disable_pipes('ner'):
doc = nlp(text)
threshold = 0.2
# Number of alternate analyses to consider. More is slower, and not necessarily better -- you need to experiment on your problem.
beam_width = 16
# This clips solutions at each step. We multiply the score of the top-ranked action by this value, and use the result as a threshold. This prevents the parser from exploring options that look very unlikely, saving a bit of efficiency. Accuracy may also improve, because we've trained on greedy objective.
beam_density = 0.0001
beams, _ = nlp.entity.beam_parse([ doc ], beam_width, beam_density)
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
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))
输出:
Label: GPE, Text: India, Score: 0.9999509961251819
添加回答
举报