赞
踩
写了一个实体链接类,代码如下:
nlp = spacy.load("en_core_web_md") class entieyLink: def __init__(self, doc, nlp): self.nlp = nlp self.doc = self.nlp(doc) # Check if "entityLinker" is already in the pipeline entity_linker_exists = False for name, component in nlp.pipeline: if name == "entityLinker": entity_linker_exists = True break # Add "entityLinker" only if it doesn't exist in the pipeline if not entity_linker_exists: self.pipe = nlp.add_pipe("entityLinker", last=True)
结果总是提示 ‘entityLinker
’ 不能找到,明明是有这个模块的:
ValueError: [E002] Can't find factory for 'entityLinker' for language English (en). This usually happens when spaCy calls `nlp.create_pipe` with a custom component name that's not registered on the current language class. If you're using a Transformer, make sure to install 'spacy-transformers'. If you're using a custom component, make sure you've added the decorator `@Language.component` (for function components) or `@Language.factory` (for class components).
Available factories: attribute_ruler, tok2vec, merge_noun_chunks, merge_entities, merge_subtokens, token_splitter, parser, beam_parser, entity_linker, ner, beam_ner, entity_ruler, lemmatizer, tagger, morphologizer, senter, sentencizer, textcat, textcat_multilabel, en.lemmatizer
后来发现,在从自己的电脑移动到服务器的时候,下载requirements.txt的时候,包spacy-entity-linker
并没有被写入到requirements.txt依赖中。
因此,安装spacy-entity-linker
包报错解决,注意要和spacy版本对应。
pip install spacy-entity-linker==1.0.3 (我的spacy=3.0.6)
因为自己一开始敲代码的时候,是使用的自己的电脑,网络问题非常顺畅,在spacy第一次实体链接的时候就自动下载了knowledge base。 结果后来挪到服务器的时候,网络下载很慢,或者无法访问外网,就会出现一些问题 Downloading knowledge base: 0.00B
。
例如:我连接的这个服务器在内网,不能够连接外网下载这个knowledge base
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。