2020-08-13 15:38:30 +00:00
{# This is a template for training configs used for the quickstart widget in
the docs and the init config command. It encodes various best practices and
can help generate the best possible configuration, given a user's requirements. #}
2021-01-27 12:56:33 +00:00
{%- set use_transformer = hardware != "cpu" -%}
2020-08-15 12:50:29 +00:00
{%- set transformer = transformer_data[optimize] if use_transformer else {} -%}
2020-08-13 15:38:30 +00:00
[paths]
2020-09-29 20:33:46 +00:00
train = null
dev = null
2020-08-13 15:38:30 +00:00
2020-08-15 12:50:29 +00:00
[system]
2020-09-20 10:30:53 +00:00
{% if use_transformer -%}
gpu_allocator = "pytorch"
{% else -%}
gpu_allocator = null
{% endif %}
2020-08-15 12:50:29 +00:00
2020-08-13 15:38:30 +00:00
[nlp]
lang = "{{ lang }}"
2021-03-02 14:53:30 +00:00
{%- if "tagger" in components or "morphologizer" in components or "parser" in components or "ner" in components or "entity_linker" in components or (("textcat" in components or "textcat_multilabel" in components) and optimize == "accuracy") -%}
2020-08-15 12:50:29 +00:00
{%- set full_pipeline = ["transformer" if use_transformer else "tok2vec"] + components %}
2021-03-02 14:53:30 +00:00
{%- else -%}
{%- set full_pipeline = components %}
{%- endif %}
2020-08-15 12:50:29 +00:00
pipeline = {{ full_pipeline|pprint()|replace("'", '"')|safe }}
2020-12-09 08:13:26 +00:00
batch_size = {{ 128 if hardware == "gpu" else 1000 }}
2020-08-13 15:38:30 +00:00
[components]
{# TRANSFORMER PIPELINE #}
2020-08-15 12:50:29 +00:00
{%- if use_transformer -%}
2020-08-13 15:38:30 +00:00
[components.transformer]
factory = "transformer"
[components.transformer.model]
@architectures = "spacy-transformers.TransformerModel.v1"
2020-08-15 12:50:29 +00:00
name = "{{ transformer["name"] }}"
2020-08-13 15:38:30 +00:00
tokenizer_config = {"use_fast": true}
[components.transformer.model.get_spans]
2020-09-03 15:37:06 +00:00
@span_getters = "spacy-transformers.strided_spans.v1"
2020-08-13 15:38:30 +00:00
window = 128
stride = 96
2020-10-02 13:06:16 +00:00
{% if "morphologizer" in components %}
[components.morphologizer]
factory = "morphologizer"
[components.morphologizer.model]
@architectures = "spacy.Tagger.v1"
nO = null
[components.morphologizer.model.tok2vec]
@architectures = "spacy-transformers.TransformerListener.v1"
grad_factor = 1.0
[components.morphologizer.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
{%- endif %}
2020-08-13 15:38:30 +00:00
{% if "tagger" in components %}
[components.tagger]
factory = "tagger"
[components.tagger.model]
@architectures = "spacy.Tagger.v1"
nO = null
[components.tagger.model.tok2vec]
2020-08-31 10:41:39 +00:00
@architectures = "spacy-transformers.TransformerListener.v1"
2020-08-13 15:38:30 +00:00
grad_factor = 1.0
[components.tagger.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
{%- endif %}
{% if "parser" in components -%}
[components.parser]
factory = "parser"
[components.parser.model]
2020-12-18 10:56:57 +00:00
@architectures = "spacy.TransitionBasedParser.v2"
2020-09-23 14:53:49 +00:00
state_type = "parser"
2020-09-23 11:35:09 +00:00
extra_state_tokens = false
2020-08-13 15:38:30 +00:00
hidden_width = 128
maxout_pieces = 3
use_upper = false
nO = null
[components.parser.model.tok2vec]
2020-08-31 10:41:39 +00:00
@architectures = "spacy-transformers.TransformerListener.v1"
2020-08-13 15:38:30 +00:00
grad_factor = 1.0
[components.parser.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
{%- endif %}
{% if "ner" in components -%}
[components.ner]
factory = "ner"
[components.ner.model]
2020-12-18 10:56:57 +00:00
@architectures = "spacy.TransitionBasedParser.v2"
2020-09-23 11:35:09 +00:00
state_type = "ner"
extra_state_tokens = false
2020-08-13 15:38:30 +00:00
hidden_width = 64
maxout_pieces = 2
use_upper = false
nO = null
[components.ner.model.tok2vec]
2020-08-31 10:41:39 +00:00
@architectures = "spacy-transformers.TransformerListener.v1"
2020-08-13 15:38:30 +00:00
grad_factor = 1.0
[components.ner.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
{% endif -%}
2020-09-22 08:40:05 +00:00
{% if "entity_linker" in components -%}
[components.entity_linker]
factory = "entity_linker"
get_candidates = {"@misc":"spacy.CandidateGenerator.v1"}
incl_context = true
incl_prior = true
[components.entity_linker.model]
@architectures = "spacy.EntityLinker.v1"
nO = null
[components.entity_linker.model.tok2vec]
@architectures = "spacy-transformers.TransformerListener.v1"
grad_factor = 1.0
2020-09-23 07:24:28 +00:00
[components.entity_linker.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
2020-09-22 08:40:05 +00:00
{% endif -%}
2020-09-22 08:22:06 +00:00
{% if "textcat" in components %}
[components.textcat]
factory = "textcat"
{% if optimize == "accuracy" %}
[components.textcat.model]
2020-10-18 12:50:41 +00:00
@architectures = "spacy.TextCatEnsemble.v2"
nO = null
[components.textcat.model.tok2vec]
@architectures = "spacy-transformers.TransformerListener.v1"
grad_factor = 1.0
2020-11-10 12:14:47 +00:00
[components.textcat.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
2020-10-18 12:50:41 +00:00
[components.textcat.model.linear_model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2021-01-06 02:07:14 +00:00
exclusive_classes = true
2020-09-22 08:22:06 +00:00
ngram_size = 1
2020-10-18 12:50:41 +00:00
no_output_layer = false
2020-09-22 08:22:06 +00:00
{% else -%}
[components.textcat.model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2021-01-06 02:07:14 +00:00
exclusive_classes = true
ngram_size = 1
no_output_layer = false
{%- endif %}
{%- endif %}
{% if "textcat_multilabel" in components %}
[components.textcat_multilabel]
factory = "textcat_multilabel"
{% if optimize == "accuracy" %}
[components.textcat_multilabel.model]
@architectures = "spacy.TextCatEnsemble.v2"
nO = null
[components.textcat_multilabel.model.tok2vec]
@architectures = "spacy-transformers.TransformerListener.v1"
grad_factor = 1.0
[components.textcat_multilabel.model.tok2vec.pooling]
@layers = "reduce_mean.v1"
[components.textcat_multilabel.model.linear_model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2021-01-06 02:07:14 +00:00
exclusive_classes = false
ngram_size = 1
no_output_layer = false
{% else -%}
[components.textcat_multilabel.model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2020-09-22 08:22:06 +00:00
exclusive_classes = false
ngram_size = 1
2020-09-22 10:06:40 +00:00
no_output_layer = false
2020-09-22 08:22:06 +00:00
{%- endif %}
{%- endif %}
2020-08-13 15:38:30 +00:00
{# NON-TRANSFORMER PIPELINE #}
{% else -%}
[components.tok2vec]
factory = "tok2vec"
[components.tok2vec.model]
2021-01-07 05:39:27 +00:00
@architectures = "spacy.Tok2Vec.v2"
2020-08-13 15:38:30 +00:00
[components.tok2vec.model.embed]
2021-04-22 08:04:15 +00:00
@architectures = "spacy.MultiHashEmbed.v2"
2020-08-20 09:20:58 +00:00
width = ${components.tok2vec.model.encode.width}
2020-10-05 19:19:41 +00:00
{% if has_letters -%}
attrs = ["NORM", "PREFIX", "SUFFIX", "SHAPE"]
rows = [5000, 2500, 2500, 2500]
{% else -%}
attrs = ["ORTH", "SHAPE"]
rows = [5000, 2500]
{% endif -%}
2020-10-05 19:21:30 +00:00
include_static_vectors = {{ "true" if optimize == "accuracy" else "false" }}
2020-08-13 15:38:30 +00:00
[components.tok2vec.model.encode]
2021-01-07 05:39:27 +00:00
@architectures = "spacy.MaxoutWindowEncoder.v2"
2020-08-13 15:38:30 +00:00
width = {{ 96 if optimize == "efficiency" else 256 }}
depth = {{ 4 if optimize == "efficiency" else 8 }}
window_size = 1
maxout_pieces = 3
2020-10-02 13:06:16 +00:00
{% if "morphologizer" in components %}
[components.morphologizer]
factory = "morphologizer"
[components.morphologizer.model]
@architectures = "spacy.Tagger.v1"
nO = null
[components.morphologizer.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
width = ${components.tok2vec.model.encode.width}
{%- endif %}
2020-08-13 15:38:30 +00:00
{% if "tagger" in components %}
[components.tagger]
factory = "tagger"
[components.tagger.model]
@architectures = "spacy.Tagger.v1"
nO = null
[components.tagger.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
2020-08-20 09:20:58 +00:00
width = ${components.tok2vec.model.encode.width}
2020-08-13 15:38:30 +00:00
{%- endif %}
{% if "parser" in components -%}
[components.parser]
factory = "parser"
[components.parser.model]
2020-12-18 10:56:57 +00:00
@architectures = "spacy.TransitionBasedParser.v2"
2020-09-23 14:53:49 +00:00
state_type = "parser"
2020-09-23 11:35:09 +00:00
extra_state_tokens = false
2020-08-13 15:38:30 +00:00
hidden_width = 128
maxout_pieces = 3
use_upper = true
nO = null
[components.parser.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
2020-08-20 09:20:58 +00:00
width = ${components.tok2vec.model.encode.width}
2020-08-13 15:38:30 +00:00
{%- endif %}
{% if "ner" in components %}
[components.ner]
factory = "ner"
[components.ner.model]
2020-12-18 10:56:57 +00:00
@architectures = "spacy.TransitionBasedParser.v2"
2020-09-23 11:35:09 +00:00
state_type = "ner"
extra_state_tokens = false
2020-08-13 15:38:30 +00:00
hidden_width = 64
maxout_pieces = 2
use_upper = true
nO = null
[components.ner.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
2020-08-20 09:20:58 +00:00
width = ${components.tok2vec.model.encode.width}
2020-08-13 15:38:30 +00:00
{% endif %}
2020-09-22 08:22:06 +00:00
2020-09-22 08:40:05 +00:00
{% if "entity_linker" in components -%}
[components.entity_linker]
factory = "entity_linker"
get_candidates = {"@misc":"spacy.CandidateGenerator.v1"}
incl_context = true
incl_prior = true
[components.entity_linker.model]
@architectures = "spacy.EntityLinker.v1"
nO = null
[components.entity_linker.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
width = ${components.tok2vec.model.encode.width}
{% endif %}
2020-09-22 08:22:06 +00:00
{% if "textcat" in components %}
[components.textcat]
factory = "textcat"
{% if optimize == "accuracy" %}
[components.textcat.model]
2020-10-18 12:50:41 +00:00
@architectures = "spacy.TextCatEnsemble.v2"
nO = null
[components.textcat.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
width = ${components.tok2vec.model.encode.width}
[components.textcat.model.linear_model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2021-01-06 02:07:14 +00:00
exclusive_classes = true
2020-09-22 08:22:06 +00:00
ngram_size = 1
2020-10-18 12:50:41 +00:00
no_output_layer = false
2020-09-22 08:22:06 +00:00
{% else -%}
[components.textcat.model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2021-01-06 02:07:14 +00:00
exclusive_classes = true
ngram_size = 1
no_output_layer = false
{%- endif %}
{%- endif %}
{% if "textcat_multilabel" in components %}
[components.textcat_multilabel]
factory = "textcat_multilabel"
{% if optimize == "accuracy" %}
[components.textcat_multilabel.model]
@architectures = "spacy.TextCatEnsemble.v2"
nO = null
[components.textcat_multilabel.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
width = ${components.tok2vec.model.encode.width}
[components.textcat_multilabel.model.linear_model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2021-01-06 02:07:14 +00:00
exclusive_classes = false
ngram_size = 1
no_output_layer = false
{% else -%}
[components.textcat_multilabel.model]
2021-06-16 09:45:00 +00:00
@architectures = "spacy.TextCatBOW.v2"
2020-09-22 08:22:06 +00:00
exclusive_classes = false
ngram_size = 1
2020-09-22 10:06:40 +00:00
no_output_layer = false
2020-09-22 08:22:06 +00:00
{%- endif %}
{%- endif %}
2020-08-13 15:38:30 +00:00
{% endif %}
{% for pipe in components %}
2021-01-06 02:07:14 +00:00
{% if pipe not in ["tagger", "morphologizer", "parser", "ner", "textcat", "textcat_multilabel", "entity_linker"] %}
2020-08-13 15:38:30 +00:00
{# Other components defined by the user: we just assume they're factories #}
[components.{{ pipe }}]
factory = "{{ pipe }}"
{% endif %}
{% endfor %}
2020-09-17 09:38:59 +00:00
[corpora]
[corpora.train]
@readers = "spacy.Corpus.v1"
path = ${paths.train}
2021-05-20 12:48:09 +00:00
max_length = 0
2020-09-17 09:38:59 +00:00
[corpora.dev]
@readers = "spacy.Corpus.v1"
path = ${paths.dev}
max_length = 0
2020-08-13 15:38:30 +00:00
[training]
2020-08-15 12:50:29 +00:00
{% if use_transformer -%}
accumulate_gradient = {{ transformer["size_factor"] }}
2020-09-23 11:21:42 +00:00
{% endif -%}
2020-09-17 09:38:59 +00:00
dev_corpus = "corpora.dev"
train_corpus = "corpora.train"
2020-08-13 15:38:30 +00:00
[training.optimizer]
@optimizers = "Adam.v1"
2020-09-04 19:22:50 +00:00
{% if use_transformer -%}
2020-08-13 15:38:30 +00:00
[training.optimizer.learn_rate]
@schedules = "warmup_linear.v1"
warmup_steps = 250
total_steps = 20000
initial_rate = 5e-5
2020-09-04 19:22:50 +00:00
{% endif %}
2020-08-13 15:38:30 +00:00
2020-08-15 12:50:29 +00:00
{% if use_transformer %}
2020-08-13 15:38:30 +00:00
[training.batcher]
2020-09-03 15:30:41 +00:00
@batchers = "spacy.batch_by_padded.v1"
2020-08-13 15:38:30 +00:00
discard_oversize = true
size = 2000
buffer = 256
{%- else %}
[training.batcher]
2020-09-03 15:30:41 +00:00
@batchers = "spacy.batch_by_words.v1"
2020-08-13 15:38:30 +00:00
discard_oversize = false
tolerance = 0.2
[training.batcher.size]
@schedules = "compounding.v1"
start = 100
stop = 1000
compound = 1.001
{% endif %}
2020-09-28 10:05:23 +00:00
[initialize]
{% if use_transformer or optimize == "efficiency" or not word_vectors -%}
2021-06-23 09:07:14 +00:00
vectors = ${paths.vectors}
2020-09-28 10:05:23 +00:00
{% else -%}
vectors = "{{ word_vectors }}"
{% endif -%}