spacy 找不到“entityLinker”工厂

问题描述 投票:0回答:1

我想使用 entieyLink 获取 doc 中包含的实体,但出现错误。 我确信我的 spacy 版本是正确的。奇怪的是,我在我的电脑上运行它没有问题,但在服务器上运行它却出现错误。

这是我的代码:

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)

这是错误:

Traceback (most recent call last):
  File "predata.py", line 264, in <module>
    pre_data(file, entity_list, output_folder)
  File "predata.py", line 212, in pre_data
    sen_attributes_dit, ent_num = load_sen_attributes(sentences, entity_list, nlp)
  File "predata.py", line 185, in load_sen_attributes
    entities = load_entity_id(sen, entity_list, nlp)
  File "predata.py", line 98, in load_entity_id
    el = entieyLink(sen, nlp)  # 句子中提到的实体,实体链接
  File "../randwalk_untils/get_entity.py", line 19, in __init__
    nlp.add_pipe("entityLinker", last=True)
  File "/home/zrw/anaconda3/envs/py37_walkfake/lib/python3.7/site-packages/spacy/language.py", line 778, in add_pipe
    validate=validate,
  File "/home/zrw/anaconda3/envs/py37_walkfake/lib/python3.7/site-packages/spacy/language.py", line 639, in create_pipe
    raise ValueError(err)
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

我不知道,你能帮我吗?我将不胜感激您的帮助!

python spacy
1个回答
0
投票

好的,我找到解决方案了:

pip 安装 spacy-entity-linker==1.0.3

对应spacy版本3.0.6。

© www.soinside.com 2019 - 2024. All rights reserved.