如何查看spacy ner softmax值?
我正在尝试从Spacy NER模型中获取每个输出类别的SoftMax预测。当我在下面的代码中放置一个“ preds”的断点并跳过管道,直到在NER模型管道组件上调用预测方法,我可以看到我可以看到从self返回的对象。 。
import spacy
from thinc.model import Model, InT, OutT
def predict(self, X:InT) -> OutT:
preds = self._func(self, X, is_train=False)[0]
return preds
Model.predict = predict
nlp = spacy.load('en_core_web_sm')
def show_ents(doc):
if doc.ents:
for ent in doc.ents:
print(ent.text + ' - ' + str(ent.start_char) + ' - ' + str(ent.end) + ' - ' +
ent.label_ + ' - ' + str(spacy.explain(ent.label_)))
else:
print('No named entities found.')
doc = nlp('Apple is looking at buying U.K. startup for $1 billion')
show_ents(doc)
我假设“选摆模”对象包含处理输入文本的结果,因为我可以看到该对象包含属性“ tokvec”和模型“ vec2scores”。因此,我假设如果要运行模型并且矢量输入IE,则
preds.vec2scores(preds.tokvecs, is_train = False)
结果数组将是每个实体的SoftMax预测。但是,如果我设置is_train = true,则输出似乎不会更改。我希望有人可以解释如何查看NER模型中的SoftMax预测以及SoftMax预测与哪些实体有关的预测?
I'm trying to obtain the softmax predictions for each output class from the spacy NER model. When I place a break point at 'preds' in the code below and skip through the pipeline until the predict method is being called on the NER model pipeline component I can see that object returned from the self._func call is a 'ParserStepModel' object.
import spacy
from thinc.model import Model, InT, OutT
def predict(self, X:InT) -> OutT:
preds = self._func(self, X, is_train=False)[0]
return preds
Model.predict = predict
nlp = spacy.load('en_core_web_sm')
def show_ents(doc):
if doc.ents:
for ent in doc.ents:
print(ent.text + ' - ' + str(ent.start_char) + ' - ' + str(ent.end) + ' - ' +
ent.label_ + ' - ' + str(spacy.explain(ent.label_)))
else:
print('No named entities found.')
doc = nlp('Apple is looking at buying U.K. startup for $1 billion')
show_ents(doc)
I assume that the 'ParserStepModel' object contains the results of processing the input text as I can see the object contains the properties 'tokvec' and the model 'vec2scores'. I was therefore assuming that if were to run the model and the vectorised input i.e.
preds.vec2scores(preds.tokvecs, is_train = False)
The resulting array would be a softmax prediction for each of the entities. However the outputs don't appear to change if I set is_train = True. I was hoping someone could explain how I can view the softmax predictions from the NER model and which entities the softmax predictions relate to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NER组件使用基于过渡的解析模型,该模型并未真正为单个实体预测提供有用的分数。
如果您需要实体预测的有意义的置信度得分,请训练a
spancat
spancat 组件而不是ner
。分数是在doc [spans_key] .attrs [“ scores”]
下保存的。一些相关线程:
The NER component uses a transition-based parsing model that doesn't really provide useful scores for individual entity predictions.
If you need meaningful confidence scores for entity predictions, train a
spancat
component instead ofner
. The scores are saved underdoc[spans_key].attrs["scores"]
.Some related threads: