Value Error: nlp.add_pipe(LanguageDetector(), name=#39;language_detector#39;, last=True)(值错误:nlp.AddPIPE(LanguageDetector(),Name=#39;Language_Detector#39;,Last=True))
问题描述
我在kaggel的下面的代码中发现了这个,每次我运行代码都会得到ValueError。 这是因为新版本的Spacy。请帮助 提前感谢
import scispacy
import spacy
import en_core_sci_lg
from spacy_langdetect import LanguageDetector
nlp = en_core_sci_lg.load(disable=["tagger", "ner"])
nlp.max_length = 2000000
nlp.add_pipe(LanguageDetector(), name='language_detector', last=True)
ValueError:[E966]nlp.add_pipe现在接受已注册组件工厂的字符串名称,而不是可调用的组件。应为字符串,但在0x00000216BB4C8D30>;处获取了语言对象(名称:‘<;spacy_langdetect.spacy_langdetect.LanguageDetector_Detector’)。
如果您使用
nlp.create_pipe('name')创建组件:删除nlp.create_pive并改为调用nlp.add_pipe('name')。如果传入类似
TextCategorizer()的组件:使用字符串名称调用nlp.add_pipe,例如nlp.add_pipe('textcat')。如果您正在使用定制组件:将修饰符
@Language.component(用于功能组件)或@Language.factory(用于类组件/工厂)添加到您的定制组件中,并为其指定一个名称,例如@Language.component('your_name')。然后,您可以运行nlp.add_pipe('your_name')将其添加到管道。
我已安装:
scispacy.version:‘0.4.0’
en_core_sci_lg版本:‘0.4.0’
Python_Version:3.8.5
space.版本:‘3.0.3’
推荐答案
add_pipe在v3中改变了工作方式;组件必须注册,然后只需使用它们的名称就可以添加到管道中。在本例中,您必须按如下方式包装LanguageDetector:
import scispacy
import spacy
import en_core_sci_lg
from spacy_langdetect import LanguageDetector
from spacy.language import Language
def create_lang_detector(nlp, name):
return LanguageDetector()
Language.factory("language_detector", func=create_lang_detector)
nlp = en_core_sci_lg.load(disable=["tagger", "ner"])
nlp.max_length = 2000000
nlp.add_pipe('language_detector', last=True)
您可以在the spaCy docs中阅读有关此操作的详细信息。
这篇关于值错误:nlp.AddPIPE(LanguageDetector(),Name=';Language_Detector';,Last=True)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:值错误:nlp.AddPIPE(LanguageDetector(),Name=';Language_Detector';,Last=True)
基础教程推荐
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
