也许我跳过了部分文档,但我试图确定标准 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:{}\t{}\t"{}"\t'.format(ent.label,ent.label_,ent.text,))
displacy.render(doc, jupyter=True, style='ent')
returns:
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_id
and ent.ent_id_
但根据docs https://spacy.io/api/token。我找不到任何东西ent.root
任何一个。
例如,在GCP NLP https://cloud.google.com/natural-language/每个实体都会返回一个 ⟨entity⟩number,使您能够识别文本中同一实体的多个实例。
这是关于位于 ⟨旧金山⟩4 的 ⟨Apple Inc⟩1 的⟨文本⟩2。和
这里有一些关于 ⟨Samsung Corp⟩6 的 ⟨text⟩3。现在,这里还有一些
⟨text⟩8 关于 ⟨Apple⟩1 及其为 ⟨customers⟩7 提供的 ⟨products⟩5
⟨挪威⟩9"
spaCy 支持类似的东西吗?或者有没有办法使用 NLTK 或斯坦福大学?
您可以使用neuralcoref库来获得与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 https://github.com/huggingface/neuralcoref
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)