我如何获得一个词的NER(命名实体识别)

How can I getting NER (Named Entity Recognition) for one word

这是我为 NER(命名实体识别)编写的 python 代码,这是一个用例场景,用户使用 Jupiter notebook 作为给定文本输入。

首先,我写了一段代码,将场景作为文本输入。

text = "customer must be registered if wants to buy the product.unregistered user can’t go to 
the shopping cart. Customer logins to the system by entering valid user id and password for 
the shopping.  customer  can make order or cancel order of the product from the shopping cart  
after login or registration. Customer has to logout after ordering or surfing for the product "

下一步,我必须把它变成一个字符串。

text_combined = str(text)

其次我将其放入文档中。

doc = nlp(text_combined)

然后我写了NER代码。我已经放了输出的屏幕截图。

for ent in doc.ents:
print(ent.text,ent.label_)

最后,我希望像客户这样的实体是一个人。但是代码将其标识为一个组织。 (附上截图)你能给我解释一下这是为什么吗?有没有人可以解决这个问题?

spacy.displacy.render(doc, style='ent',jupyter=True)

spaCy 模型是在类似报纸的文本上训练的。他们拥有的一些标签是 PER(人)和 ORG(组织)之类的东西。但它了解这些是基于报纸文章的。因此,如果您有这样的新闻文章...

John Smith of Eggplant Limited reported a new product today...

然后它会被标记成这样:

[John Smith PER] of [Eggplant Limited ORG] reported a new product today...

所以命名实体是专有名词

在您的示例中,“Customer”不是专有名词,因此没有理由将其标记为 PER。它被标记为 ORG 有点奇怪,我认为这是一个错误。至于为什么那里有错误,很难说清楚,但模型并不完美,它们确实有错误,所以你必须能够在你的应用程序中处理这样的问题。