MCPcopy Index your code
hub / github.com/explosion/spacy-transformers

github.com/explosion/spacy-transformers @release-v2.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release release-v2.0.0 ↗ · + Follow
230 symbols 1,113 edges 37 files 67 documented · 29%

Browse by type

Functions 214 Types & classes 13 Endpoints 3
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

spacy-transformers: Use pretrained transformers like BERT, XLNet and GPT-2 in spaCy

This package provides spaCy components and architectures to use transformer models via Hugging Face's transformers in spaCy. The result is convenient access to state-of-the-art transformer architectures, such as BERT, GPT-2, XLNet, etc.

This release requires spaCy v3. For the previous version of this library, see the v0.6.x branch.

tests PyPi GitHub Code style: black

Features

  • Use pretrained transformer models like BERT, RoBERTa and XLNet to power your spaCy pipeline.
  • Easy multi-task learning: backprop to one transformer model from several pipeline components.
  • Train using spaCy v3's powerful and extensible config system.
  • Automatic alignment of transformer output to spaCy's tokenization.
  • Easily customize what transformer data is saved in the Doc object.
  • Easily customize how long documents are processed.
  • Out-of-the-box serialization and model packaging.

🚀 Installation

Installing the package from pip will automatically install all dependencies, including PyTorch and spaCy. Make sure you install this package before you install the models. Also note that this package requires Python 3.6+, PyTorch v1.5+ and spaCy v3.0+.

pip install 'spacy[transformers]'

For GPU installation, find your CUDA version using nvcc --version and add the version in brackets, e.g. spacy[transformers,cuda92] for CUDA9.2 or spacy[transformers,cuda100] for CUDA10.0.

If you are having trouble installing PyTorch, follow the instructions on the official website for your specific operating system and requirements.

📖 Documentation

⚠️ Important note: This package has been extensively refactored to take advantage of spaCy v3.0. Previous versions that were built for spaCy v2.x worked considerably differently. Please see previous tagged versions of this README for documentation on prior versions.

Applying pretrained text and token classification models

Note that the transformer component from spacy-transformers does not support task-specific heads like token or text classification. A task-specific transformer model can be used as a source of features to train spaCy components like ner or textcat, but the transformer component does not provide access to task-specific heads for training or inference.

Alternatively, if you only want use to the predictions from an existing Hugging Face text or token classification model, you can use the wrappers from spacy-huggingface-pipelines to incorporate task-specific transformer models into your spaCy pipelines.

Bug reports and other issues

Please use spaCy's issue tracker to report a bug, or open a new thread on the discussion board for any other issue.

Core symbols most depended-on inside this repo

Shape

Function 139
Method 75
Class 13
Route 3

Languages

Python100%

Modules by API surface

spacy_transformers/data_classes.py29 symbols
spacy_transformers/tests/test_pipeline_component.py23 symbols
spacy_transformers/pipeline_component.py21 symbols
spacy_transformers/layers/transformer_model.py18 symbols
spacy_transformers/tests/util.py17 symbols
spacy_transformers/tests/test_serialize.py15 symbols
spacy_transformers/tests/test_truncation.py9 symbols
spacy_transformers/tests/test_model_sequence_classification.py9 symbols
spacy_transformers/span_getters.py9 symbols
spacy_transformers/util.py8 symbols
spacy_transformers/tests/test_model_wrapper.py8 symbols
spacy_transformers/layers/listener.py8 symbols

For agents

$ claude mcp add spacy-transformers \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page