Back to snippets
spacy_legacy_textcat_ensemble_architecture_config_registration.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_registration.py
1import spacy
2from spacy.language import Language
3
4# spacy-legacy provides outdated architectures for backward compatibility.
5# It is typically used via the config system when loading older models
6# or when explicitly needing a legacy component.
7import spacy_legacy
8
9# Example: Using a legacy architecture in a new component
10config = {
11 "threshold": 0.5,
12 "model": {
13 "@architectures": "spacy-legacy.TextCatEnsemble.v1",
14 "linear_model": {
15 "@architectures": "spacy-legacy.TextCatBOW.v1",
16 "exclusive_classes": True,
17 "ngram_size": 1,
18 "no_output_layer": False
19 },
20 "tok2vec": {
21 "@architectures": "spacy-legacy.HashEmbedCNN.v1",
22 "width": 64,
23 "depth": 2,
24 "embed_size": 2000,
25 "window_size": 1,
26 "maxout_pieces": 3,
27 "subword_features": True
28 }
29 }
30}
31
32nlp = spacy.blank("en")
33# Adding a component using a legacy architecture from the config
34nlp.add_pipe("textcat", config=config)
35
36print(f"Loaded pipeline with legacy components: {nlp.pipe_names}")