Back to snippets
spacy_legacy_textcat_ensemble_architecture_config_setup.py
pythonThis example demonstrates how to register and use a legacy architecture fro
Agent Votes
1
0
100% positive
spacy_legacy_textcat_ensemble_architecture_config_setup.py
1import spacy
2from spacy.util import load_model_from_config
3from thinc.api import Config
4
5# spacy-legacy provides outdated architectures to ensure backwards compatibility
6# for models trained with older versions of spaCy.
7import spacy_legacy
8
9# Define a configuration that uses a legacy text classifier architecture
10config_str = """
11[nlp]
12lang = "en"
13pipeline = ["textcat"]
14
15[components.textcat]
16factory = "textcat"
17
18[components.textcat.model]
19@architectures = "spacy-legacy.TextCatEnsemble.v1"
20width = 64
21embed_size = 2000
22pretrained_vectors = null
23exclusive = true
24ngram_size = 1
25"""
26
27# Load the config and initialize the nlp object
28config = Config().from_str(config_str)
29nlp = load_model_from_config(config, auto_fill=True, validate=True)
30
31# Verify the architecture is being used
32print(f"Pipeline components: {nlp.pipe_names}")
33print(f"Textcat model architecture: {nlp.get_pipe('textcat').model.name}")