空格引用解析-命名实体识别(NER)以返回唯一实体ID? [英] spaCy coreference resolution - named entity recognition (NER) to return unique entity ID's?

查看:14
本文介绍了空格引用解析-命名实体识别(NER)以返回唯一实体ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我跳过了文档的一部分,但我试图确定的是标准NER工具集中每个实体的唯一ID。例如:

import spacy
from spacy import displacy
import en_core_web_sm
nlp = en_core_web_sm.load()

text = "This is a text about Apple Inc based in San Fransisco. "
        "And here is some text about Samsung Corp. "
        "Now, here is some more text about Apple and its products for customers in Norway"

doc = nlp(text)

for ent in doc.ents:
    print('ID:{}	{}	"{}"	'.format(ent.label,ent.label_,ent.text,))


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

退货:

ID:381    ORG "Apple Inc" 
ID:382    GPE "San Fransisco" 
ID:381    ORG "Samsung Corp." 
ID:381    ORG "Apple" 
ID:382    GPE "Norway"

我一直在查看ent.ent_ident.ent_id_,但根据docs它们是非活动的。我在ent.root中也找不到任何东西。

例如,在GCP NLP中,每个实体都返回一个⟨Entity⟩编号,使您能够在文本中标识同一实体的多个实例。

这是一个⟨Text⟩2,关于⟨Apple Inc.⟩1,总部设在旧金山⟨⟩4。 以下是一些⟨Text⟩3关于⟨三星公司⟩6的信息。现在,这里有更多 ⟨Text⟩8关于⟨苹果⟩1及其⟨产品⟩5面向⟨客户的⟩7 ⟨挪威⟩9"

Spacy是否支持类似的功能?或者有办法使用NLTK或斯坦福大学吗?

推荐答案

您可以使用神经参照库来获得与Spacy模型一起工作的共指关系解析,如下所示:

# Load your usual SpaCy model (one of SpaCy English models)
import spacy
nlp = spacy.load('en')

# Add neural coref to SpaCy's pipe
import neuralcoref
neuralcoref.add_to_pipe(nlp)

# You're done. You can now use NeuralCoref as you usually manipulate a SpaCy document annotations.
doc = nlp(u'My sister has a dog. She loves him.')

doc._.has_coref
doc._.coref_clusters

在此处查找安装和使用说明:https://github.com/huggingface/neuralcoref

这篇关于空格引用解析-命名实体识别(NER)以返回唯一实体ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆