spaCy: Industrial-strength NLP
spaCy is a library for advanced natural language processing in Python and Cython. spaCy is built on the very latest research, but it isn't researchware. It was designed from day one to be used in real products. spaCy currently supports English, German, French and Spanish, as well as tokenization for Italian, Portuguese, Dutch, Swedish, Finnish, Norwegian, Hungarian, Bengali, Hebrew, Chinese and Japanese. It's commercial open-source software, released under the MIT license.
|Usage Workflows||How to use spaCy and its features.|
|API Reference||The detailed reference for spaCy's API.|
|Troubleshooting||Common problems and solutions for beginners.|
|Tutorials||End-to-end examples, with code you can modify and run.|
|Showcase & Demos||Demos, libraries and products from the spaCy community.|
|Contribute||How to contribute to the spaCy project and code base.|
Where to ask questions
Please understand that we won't be able to provide individual support via email. We also believe that help is much more valuable if it's shared publicly, so that more people can benefit from it.
|Bug reports||GitHub issue tracker|
|Usage questions||StackOverflow, Gitter chat, Reddit user group|
|General discussion||Gitter chat, Reddit user group|
- Non-destructive tokenization
- Syntax-driven sentence segmentation
- Pre-trained word vectors
- Part-of-speech tagging
- Named entity recognition
- Labelled dependency parsing
- Convenient string-to-int mapping
- Export to numpy data arrays
- GIL-free multi-threading
- Efficient binary serialization
- Easy deep learning integration
- Statistical models for English, German, French and Spanish
- State-of-the-art speed
- Robust, rigorously evaluated accuracy
- Fastest in the world: <50ms per document. No faster system has ever been announced.
- Accuracy within 1% of the current state of the art on all tasks performed (parsing, named entity recognition, part-of-speech tagging). The only more accurate systems are an order of magnitude slower or more.
|Operating system||macOS / OS X, Linux, Windows (Cygwin, MinGW, Visual Studio)|
|Python version||CPython 2.6, 2.7, 3.3+. Only 64 bit.|
|Package managers||pip (source packages only), conda (via
Installation requires a working build environment. See notes on Ubuntu, macOS/OS X and Windows for details.
Using pip, spaCy releases are currently only available as source packages.
pip install -U spacy
When using pip it is generally recommended to install packages in a
virtualenv to avoid modifying system state:
virtualenv .env source .env/bin/activate pip install spacy
Thanks to our great community, we've finally re-added conda support. You can now install spaCy via
conda config --add channels conda-forge conda install spacy
For the feedstock including the build recipe and configuration, check out this repository. Improvements and pull requests to the recipe and setup are always appreciated.
As of v1.7.0, models for spaCy can be installed as Python packages. This means that they're a component of your application, just like any other module. They're versioned and can be defined as a dependency in your
requirements.txt. Models can be installed from a download URL or a local directory, manually or via pip. Their data can be located anywhere on your file system. To make a model available to spaCy, all you need to do is create a "shortcut link", an internal alias that tells spaCy where to find the data files for a specific model name.
|spaCy Models||Available models, latest releases and direct download.|
|Models Documentation||Detailed usage instructions.|
# out-of-the-box: download best-matching default model python -m spacy download en # download best-matching version of specific model for your spaCy installation python -m spacy download en_core_web_md # pip install .tar.gz archive from path or URL pip install /Users/you/en_core_web_md-1.2.0.tar.gz pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_md-1.2.0/en_core_web_md-1.2.0.tar.gz # set up shortcut link to load installed package as "en_default" python -m spacy link en_core_web_md en_default # set up shortcut link to load local model as "my_amazing_model" python -m spacy link /Users/you/data my_amazing_model
Loading and using models
To load a model, use
spacy.load() with the model's shortcut link:
import spacy nlp = spacy.load('en_default') doc = nlp(u'This is a sentence.')
If you've installed a model via pip, you can also
import it directly and then call its
load() method with no arguments. This should also work for older models in previous versions of spaCy.
import spacy import en_core_web_md nlp = en_core_web_md.load() doc = nlp(u'This is a sentence.')
Support for older versions
If you're using an older version (v1.6.0 or below), you can still download and install the old models from within spaCy using
python -m spacy.en.download all or
python -m spacy.de.download all. The
.tar.gz archives are also attached to the v1.6.0 release. To download and install the models manually, unpack the archive, drop the contained directory into
spacy/data and load the model via
Compile from source
The other way to install spaCy is to clone its GitHub repository and build it from source. That is the common way if you want to make changes to the code base. You'll need to make sure that you have a development enviroment consisting of a Python distribution including header files, a compiler, pip, virtualenv and git installed. The compiler part is the trickiest. How to do that depends on your system. See notes on Ubuntu, OS X and Windows for details.
# make sure you are using recent pip/virtualenv versions python -m pip install -U pip virtualenv git clone https://github.com/explosion/spaCy cd spaCy virtualenv .env source .env/bin/activate pip install -r requirements.txt pip install -e .
Compared to regular install via pip requirements.txt additionally installs developer dependencies such as Cython.
Instead of the above verbose commands, you can also use the following Fabric commands:
||Compile the source.|
||Remove compiled objects, including the generated C++.|
||Run basic tests, aborting after first failure.|
All commands assume that your
virtualenv is located in a directory
.env. If you're using a different directory, you can change it via the environment variable
VENV_DIR, for example:
VENV_DIR=".custom-env" fab clean make
Install system-level dependencies via
sudo apt-get install build-essential python-dev git
macOS / OS X
Install a recent version of XCode, including the so-called "Command Line Tools". macOS and OS X ship with Python and git preinstalled.
Install a version of Visual Studio Express or higher that matches the version that was used to compile your Python interpreter. For official distributions these are VS 2008 (Python 2.7), VS 2010 (Python 3.4) and VS 2015 (Python 3.5).
spaCy comes with an extensive test suite. First, find out where spaCy is installed:
python -c "import os; import spacy; print(os.path.dirname(spacy.__file__))"
pytest on that directory. The flags
--model are optional and enable additional tests:
# make sure you are using recent pytest version python -m pip install -U pytest python -m pytest <spacy-directory> --vectors --models --slow
||Spanish model, alpha support for Norwegian & Japanese, and bug fixes|
||French model and small improvements|
||Saving, loading and training bug fixes|
||Better NER training, saving and loading|
||Bug fixes and new CLI commands|
||Alpha support for Hebrew, new CLI commands and bug fixes|
||Small fixes to beam parser and model linking|
||Fix data download for system installation|
||New 50 MB model, CLI, better downloads and lots of bug fixes|
||Improvements to tokenizer and tests|
||Alpha support for Swedish and Hungarian|
||Improved language data and alpha Dutch support|
||Improve API consistency|
||Alpha tokenizers for Chinese, French, Spanish, Italian and Portuguese|
||Bug fixes and adjustments|
||Support for deep learning workflows and entity-aware rule matcher|
||Fixed German model|
||Add support for GloVe vectors|
||Fix incorrect use of header file|
||Fix OSX problem introduced in 0.100.3|
||Multi-threading, faster loading and bugfixes|
||Fix data version lock|
||Fix install for OSX|
||Revise setup.py, better model downloads, bug fixes|
||Improve span merging, internal refactoring|
||Smaller package, bug fixes|
||Load the StringStore from a json list, instead of a text file|
||Hotfix to .merge method|
||Fix memory and parse errors|
||Bug fixes to word vectors|