这是我使用spacy进行名称实体识别的代码。你知道吗
import spacy
nlp = spacy.load("en")
text = "But YouTube is starting from behind. The company made a late push\ninto hardware, and Apple’s Siri, available on iPhones, and Amazon’s Alexa\nsoftware, which runs on its Echo and Dot devices, have clear leads in\nconsumer adoption."
doc = nlp(text)
for ent in doc.ents:
print(ent.text,ent.label_)
输出:
YouTube ORG
Apple’s Siri ORG
iPhones ORG
Amazon ORG
Echo and Dot ORG
在空间上YouTube的模型是label ORG,但我想为我的项目更新YouTube as Community。 为了更新这一点,我遵循spacyhttps://spacy.io/usage/training的官方文档,并按以下方式进行更新:
new_nlp = spacy.blank('en')
optimizer = new_nlp.begin_training()
new_nlp.update('YouTube', 'Community', sgd=optimizer)
更新时出现以下错误:
IndexError: [E009] The `update` method expects same number of docs and golds, but got: 7 docs, 9 golds.
请告诉我哪里出了问题,我怎样才能以正确的方式更新Youtube。你知道吗
在文档中可以看到
update
需要一个iterable:nlp.update([doc], [gold], drop=0.5, sgd=optimizer)
所以解决方法就是把这些单词放在列表中:
但是你可能仍然想知道为什么这个错误看起来是这样的。;)这是因为字符串本身就是一个iterable!当你在一个字符串上迭代时,它会产生每个字符,
'YouTube'
有7个字符,'Community'
有9个字符,这样就得到了“7 docs, 9 golds
”相关问题 更多 >
编程相关推荐