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)
基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
