You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用spaCy-entity-linker时遭遇知识库为空及组件工厂未找到问题求助

使用spaCy-entity-linker时遭遇知识库为空及组件工厂未找到问题求助

大家好,我在使用spaCy的entity linker库时遇到了两个棘手的问题,折腾了好久没搞明白,想请教下各位大佬。

我的环境情况

  • Python版本:3.8
  • 已安装依赖:
    • spacy(已下载en_core_web_md语言模型)
    • spacy-entity-linker(通过pip install spacy-entity-linker完成安装)
  • 已执行知识库下载命令:python -m spacy_entity_linker "download_knowledge_base"

错误场景1:知识库为空报错

我运行了以下代码:

import spacy

nlp = spacy.load("en_core_web_md")
nlp.add_pipe("entity_linker", last=True)

doc = nlp("I watched the Pirates of the Caribbean last silvester")
all_linked_entities = doc._.linkedEntities

for sent in doc.sents:
    sent._.linkedEntities.pretty_print()

得到的错误提示为:

ValueError: [E139] Knowledge base for component 'entity_linker' is empty. Use the methods kb.add_entity and kb.add_alias to add entries.

我猜测可能是下载的知识库没有被程序正确识别,但官方文档里完全没说明要把知识库放到哪个位置,不知道该怎么处理这个问题。


错误场景2:组件工厂未找到报错

后来我尝试按照原示例代码里的写法,把组件名改成驼峰命名的entityLinker,修改后的关键代码如下:

nlp.add_pipe("entityLinker", last=True)

结果又出现了新的错误:

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

现在完全搞不清问题出在哪了,明明已经按要求装了库、下载了知识库,为什么会出现这两个问题呢?有没有大佬能帮忙指点下?

备注:内容来源于stack exchange,提问作者AlextheVries

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 15:27:29