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
- 合并具有多索引的两个数据帧 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01