问题总结1

1.ValueError: [E966] nlp.add_pipe now takes the string name of the registered component factory, not a callable component. Expected string, but got <spacy.pipeline.entityruler.EntityRuler object at 0x0000006C570CA2C0> (name: ‘None’).

  • If you created your component with nlp.create_pipe('name'): remove nlp.create_pipe and call nlp.add_pipe('name') instead.

  • If you passed in a component like TextCategorizer(): call nlp.add_pipe with the string name instead, e.g. nlp.add_pipe('textcat').

  • If you’re using a custom component: Add the decorator @Language.component (for function components) or @Language.factory (for class components / factories) to your custom component and assign it a name, e.g. @Language.component('your_name'). You can then run nlp.add_pipe('your_name') to add it to the pipeline.


import spacy
text = "Martha, a senior, moved to Spain where she will be playing basketball until 05 June 2022 or until she can't play any longer."
nlp = spacy.load("en_core_web_sm")
doc_ori = nlp(text)
for en in doc_ori.ents:
    print(en)
print("--"*10)
ruler = nlp.create_pipe("entity_ruler") # 这里有问题,应该是修改了函数
ruler.add_patterns([{"label": "SPORT", "pattern": "basketball"}])
nlp.add_pipe(ruler,before="ner")
doc = nlp(text)
for en1 in doc.ents:
    print(en1,en1.label_)

改一下两行,然后就可以了

ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns([{"label": "SPORT", "pattern": "basketball"}])
# nlp.add_pipe(ruler,before="ner") 
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值