这是我使用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在spacy的NER模型中,YouTube是ORG标签,但我想将Youtube更新为我的项目的社区。为了更新这一点,我遵循spacy https://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。
发布于 2019-07-22 09:31:55
在文档中,您可以看到update需要一个可迭代的:nlp.update([doc], [gold], drop=0.5, sgd=optimizer)
因此,解决办法就是把单词放在列表中:
new_nlp.update(['YouTube'], ['Community'], sgd=optimizer)但是,您可能仍然会想,为什么错误看起来是这样的。这是因为字符串本身是可迭代的!当您在字符串上迭代时,它会生成每个字符-- 'YouTube'有7个字符,而'Community'有9个字符,这样就产生了"7 docs, 9 golds“。
发布于 2021-02-04 16:44:59
New_nlp.update(json.loads,Youtube),json.loads(社区),sgd=optimizer
https://stackoverflow.com/questions/57142947
复制相似问题