在官方的 spacy classy 分类示例中,是什么导致了这个错误?

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

我一直在尝试学习如何使用spacy,现在我想学习如何使用classy分类,但是,官方spacy网页中显示的classy示例不起作用。这是我正在使用的代码,后面是我收到的错误。有人可以告诉我如何解决这个问题吗?

import spacy

data = {
    "furniture": ["This text is about chairs.",
               "Couches, benches and televisions.",
               "I really need to get a new sofa."],
    "kitchen": ["There also exist things like fridges.",
                "I hope to be getting a new stove today.",
                "Do you also have some ovens."]
}

# see github repo for examples on sentence-transformers and Huggingface
nlp = spacy.load('en_core_web_md')
nlp.add_pipe("classy_classification", 
    config={
        "data": data,
        "model": "spacy"
    }
)

print(nlp("I am looking for kitchen appliances.")._.cats)

 File "C:\Users\vidrr\AppData\Local\Programs\Python\Python312\Lib\site-packages\spacy\language.py", line 821, in add_pipe
    pipe_component = self.create_pipe(
                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\vidrr\AppData\Local\Programs\Python\Python312\Lib\site-packages\spacy\language.py", line 690, in create_pipe
    raise ValueError(err)
ValueError: [E002] Can't find factory for 'classy_classification' 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 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, doc_cleaner, parser, beam_parser, lemmatizer, trainable_lemmatizer, entity_linker, entity_ruler, tagger, morphologizer, ner, beam_ner, senter, sentencizer, spancat, spancat_singlelabel, span_finder, future_entity_ruler, span_ruler, textcat, textcat_multilabel, en.lemmatizer
python spacy spacy-3
1个回答
0
投票

您缺少经典分类包。
尝试跑步:

pip install classy-classification
© www.soinside.com 2019 - 2024. All rights reserved.