当前位置:   article > 正文

spaCy库的实体链接踩坑,以及spaCy-entity-linker的knowledge_base下载问题_spacy entity linker

spacy entity linker

问题1. spacy Can’t find factory for ‘entityLinker’

1)问题

写了一个实体链接类,代码如下:

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

结果总是提示 ‘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
  • 1
  • 2
  • 3

2)解决方法

后来发现,在从自己的电脑移动到服务器的时候,下载requirements.txt的时候,包spacy-entity-linker并没有被写入到requirements.txt依赖中。
因此,安装spacy-entity-linker包报错解决,注意要和spacy版本对应。

pip install spacy-entity-linker==1.0.3  (我的spacy=3.0.6
  • 1

问题2. spacy Can’t download knowledge base

1)问题

因为自己一开始敲代码的时候,是使用的自己的电脑,网络问题非常顺畅,在spacy第一次实体链接的时候就自动下载了knowledge base。 结果后来挪到服务器的时候,网络下载很慢,或者无法访问外网,就会出现一些问题 Downloading knowledge base: 0.00B
例如:我连接的这个服务器在内网,不能够连接外网下载这个knowledge base

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/343512
推荐阅读
相关标签