我的环境
我正在尝试使用spacy-langdetect在spaCy NLP管道中添加语言检测功能。当我使用单个进程执行检测时,一切看起来都很好,如下面的示例所示
import spacy
from spacy_langdetect import LanguageDetector
from spacy.language import Language
# Load Language detection
@Language.factory('language_detector')
def language_detector(nlp, name):
return LanguageDetector()
# Load Spacy
nlp = spacy.load("en_core_web_lg")
nlp.add_pipe('language_detector', last=True)
print([doc._.language for doc in nlp.pipe(['I bless the rains down in Africa'], n_process=-1)])
返回
[{'language': 'en', 'score': 0.9999985260933938}]
但是我在设置n_进程时出现了以下错误>;1:
AttributeError: [E046] Can't retrieve unregistered extension attribute 'language'. Did you forget to call the `set_extension` method?
我认为这是因为在macOS上使用了spawn方法(在多处理中),因为Python3.8和一些上下文没有发送到子进程,但在Linux上使用fork方法时,我得到了相同的错误。有人对此错误有何解释和解决方法吗
目前没有回答
相关问题 更多 >
编程相关推荐