首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >catalogue.RegistryError:[E893]在函数注册表'misc‘中找不到函数'Custom_Candidate_Gen.v1’

catalogue.RegistryError:[E893]在函数注册表'misc‘中找不到函数'Custom_Candidate_Gen.v1’
EN

Stack Overflow用户
提问于 2022-05-16 08:15:01
回答 1查看 127关注 0票数 0

我目前正在构建一个带有自定义NER、实体链接器和Textcat组件的spacy管道。对于我的实体链接器组件,我已经修改了candidate_generator()以适应我的用例。我借鉴了爱默生的演示项目。下面是我的custom_functions代码。

代码语言:javascript
复制
import spacy
from functools import partial
from pathlib import Path
from typing import Iterable, Callable
from spacy.training import Example
from spacy.tokens import DocBin
from spacy.kb import Candidate, KnowledgeBase, get_candidates

@spacy.registry.misc("Custom_Candidate_Gen.v1")
def create_candidates():
    return custom_get_candidates

def custom_get_candidates(kb, span):
    return kb.get_alias_candidates(span.text.lower())

@spacy.registry.readers("MyCorpus.v1")
def create_docbin_reader(file: Path) -> Callable[["Language"], Iterable[Example]]:
    return partial(read_files, file)


def read_files(file: Path, nlp: "Language") -> Iterable[Example]:
    # we run the full pipeline and not just nlp.make_doc to ensure we have entities and sentences
    # which are needed during training of the entity linker
    with nlp.select_pipes(disable="entity_linker"):
        doc_bin = DocBin().from_disk(file)
        docs = doc_bin.get_docs(nlp.vocab)
        for doc in docs:
            yield Example(nlp(doc.text), doc)

在培训了我的实体链接器并将我的textcat组件添加到管道之后,我得到了以下错误:

代码语言:javascript
复制
catalogue.RegistryError: [E893] Could not find function 'Custom_Candidate_Gen.v1' in function registry 'misc'. If you're using a custom function, make sure the code is available. If the function is provided by a third-party package, e.g. spacy-transformers, make sure the package is installed in your environment.

Available names: spacy.CandidateGenerator.v1, spacy.EmptyKB.v1, spacy.KBFromFile.v1, spacy.LookupsDataLoader.v1, spacy.ngram_range_suggester.v1, spacy.ngram_suggester.v1

为什么我的自定义候选生成器没有注册?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-16 15:14:41

在加载模型时加载和注册自定义代码的选项:

  • 在加载模型之前,直接在脚本中导入此代码
  • 使用spacy package --code将其打包到您的模型中,并从安装的包名(而不是目录)加载模型
  • 在一个单独的包中提供这段代码,该包使用setup.cfg中的入口点来注册方法(这很好,但在这种情况下不是我的首选)

请参见:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72256065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档