gpt4 book ai didi

python - Spacy 中的命名实体识别

转载 作者:太空狗 更新时间:2023-10-29 17:56:06 26 4
gpt4 key购买 nike

我正在尝试为下面的句子找到命名实体

import spacy.lang.en
parser = spacy.lang.en.English()
ParsedSentence = parser(u"Alphabet is a new startup in China")
for Entity in ParsedSentence.ents:
print (Entity.label, Entity.label_, ' '.join(t.orth_ for t in Entity))

我期望得到结果“Alphabet”,“China”,但结果是一个空集。我在这里做错了什么

最佳答案

根据 spacy documentation对于名称实体识别,这里是提取名称实体的方法

import spacy
nlp = spacy.load('en') # install 'en' model (python3 -m spacy download en)
doc = nlp("Alphabet is a new startup in China")
print('Name Entity: {0}'.format(doc.ents))

结果
名称实体:(中国,)

要使“Alphabet”成为“名词”,请在其后面加上“The”。

doc = nlp("The Alphabet is a new startup in China")
print('Name Entity: {0}'.format(doc.ents))

名称实体:(字母,中国)

关于python - Spacy 中的命名实体识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48200524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com