Command Line Interface

As of v1.7.0, spaCy comes with new command line helpers to download and link models and show useful debugging information. For a list of available commands, type spacy --help.

Download

Download models for spaCy. The downloader finds the best-matching compatible version, uses pip to download the model as a package and automatically creates a shortcut link to load the model by name. Direct downloads don't perform any compatibility checks and require the model name to be specified with its version (e.g., en_core_web_sm-1.2.0).

spacy download [model] [--direct]
ArgumentTypeDescription
modelpositionalModel name or shortcut (en, de, vectors).
--direct, -dflagForce direct download of exact model version.
--help, -hflagShow help message and available arguments.

Link

Create a shortcut link for a model, either a Python package or a local directory. This will let you load models from any location using a custom name via spacy.load() .

spacy link [origin] [link_name] [--force]
ArgumentTypeDescription
originpositionalModel name if package, or path to local directory.
link_namepositionalName of the shortcut link to create.
--force, -fflagForce overwriting of existing link.
--help, -hflagShow help message and available arguments.

Info

Print information about your spaCy installation, models and local setup, and generate Markdown-formatted markup to copy-paste into GitHub issues.

spacy info [--markdown]
spacy info [model] [--markdown]
ArgumentTypeDescription
modelpositionalA model, i.e. shortcut link, package name or path (optional).
--markdown, -mdflagPrint information as Markdown.
--help, -hflagShow help message and available arguments.

Convert

Convert files into spaCy's JSON format for use with the train command and other experiment management functions. The right converter is chosen based on the file extension of the input file. Currently only supports .conllu.

spacy convert [input_file] [output_dir] [--n-sents] [--morphology]
ArgumentTypeDescription
input_filepositionalInput file.
output_dirpositionalOutput directory for converted JSON file.
--n-sents, -noptionNumber of sentences per document.
--morphology, -moptionEnable appending morphology to tags.
--help, -hflagShow help message and available arguments.

Train

Train a model. Expects data in spaCy's JSON format.

spacy train [lang] [output_dir] [train_data] [dev_data] [--n-iter] [--n-sents] [--use-gpu] [--no-tagger] [--no-parser] [--no-entities]
ArgumentTypeDescription
langpositionalModel language.
output_dirpositionalDirectory to store model in.
train_datapositionalLocation of JSON-formatted training data.
dev_datapositionalLocation of JSON-formatted dev data (optional).
--n-iter, -noptionNumber of iterations (default: 20).
--n-sents, -nsoptionNumber of sentences (default: 0).
--use-gpu, -goptionUse GPU.
--no-tagger, -TflagDon't train tagger.
--no-parser, -PflagDon't train parser.
--no-entities, -NflagDon't train NER.
--help, -hflagShow help message and available arguments.

Environment variables for hyperparameters

spaCy lets you set hyperparameters for training via environment variables. This is useful, because it keeps the command simple and allows you to create an alias for your custom train command while still being able to easily tweak the hyperparameters. For example:

parser_hidden_depth=2 parser_maxout_pieces=1 train-parser
NameDescriptionDefault
dropout_from0.2
dropout_to0.2
dropout_decay0.0
batch_from1
batch_to64
batch_compound1.001
token_vector_width128
embed_size7500
parser_maxout_pieces2
parser_hidden_depth1
hidden_width128
learn_rate0.001
optimizer_B10.9
optimizer_B20.999
optimizer_eps1e-08
L2_penalty1e-06
grad_norm_clip1.0

Package

Generate a model Python package from an existing model data directory. All data files are copied over. If the path to a meta.json is supplied, or a meta.json is found in the input directory, this file is used. Otherwise, the data can be entered directly from the command line. The required file templates are downloaded from GitHub to make sure you're always using the latest versions. This means you need to be connected to the internet to use this command.

spacy package [input_dir] [output_dir] [--meta] [--force]
ArgumentTypeDescription
input_dirpositionalPath to directory containing model data.
output_dirpositionalDirectory to create package folder in.
--meta-path, -moptionPath to meta.json file (optional).
--create-meta, -cflag Create a meta.json file on the command line, even if one already exists in the directory.
--force, -fflagForce overwriting of existing folder in output directory.
--help, -hflagShow help message and available arguments.