Repolode
explosion

explosion/spacy-llm

A spaCy extension that plugs large language models into structured NLP pipelines for tasks like NER and text classification without training data.

Stars
1,398
Forks
112
Open issues
50
Last commit
24 days ago

What is it?

spacy-llm integrates Large Language Models into spaCy, letting you add LLM-powered components to a regular spaCy pipeline. Each component combines a task (the prompt template and the parser that turns the model's free-text reply into structured output) with a model backend, so results land in standard spaCy fields such as doc.ents or doc.cats.

The package ships with built-in tasks for named entity recognition, text classification, lemmatization, relation extraction, sentiment analysis, span categorization, summarization, entity linking and translation, along with a raw prompt option. Backends include OpenAI, Cohere, Anthropic, Google PaLM and Azure AI, as well as open-source models hosted on Hugging Face such as Falcon, Dolly, Llama 2, Mistral and StableLM. Pipelines can be defined in spaCy's config system and serialized, and custom tasks or models can be registered through spaCy's registry.

The project is aimed at quick prototyping: you can start with prompts and no labelled data, then mix in or replace LLM components with supervised spaCy models as a project matures. The package is marked experimental, so interfaces may change in minor releases.

Key features

  • 01Serializable llm component that adds prompt-based steps to a spaCy pipeline.
  • 02Modular task and model functions, including custom ones registered via spaCy's registry.
  • 03Supports OpenAI, Cohere, Anthropic, Google PaLM and Azure AI APIs.
  • 04Runs open-source models from Hugging Face such as Llama 2, Mistral and Falcon.
  • 05Built-in tasks for NER, text classification, relation extraction, summarization and more.
  • 06Map-reduce handling for inputs that exceed the LLM's context window.

Use cases

  • Prototyping an NER or text classification step before collecting labelled training data.
  • Combining LLM-based components with rule-based or supervised spaCy components in one pipeline.
  • Extracting structured fields from unstructured text using a hosted or local open-source LLM.

Quick start

  1. 1

    Install the package with pip

    python -m pip install spacy-llm
  2. 2

    Create an OpenAI API key and set it as an environment variable

  3. 3

    Run text classification with the llm_textcat factory in Python

Things to know

  • Still experimental, so interface changes may break in minor version updates.
  • Most built-in models need an API key from a paid provider such as OpenAI, or a hosted LLM.

Topics

FAQ

What is spacy-llm?
A spaCy extension that plugs large language models into structured NLP pipelines for tasks like NER and text classification without training data. spacy-llm integrates Large Language Models into spaCy, letting you add LLM-powered components to a regular spaCy pipeline. Each component combines a task (the prompt template and the parser that turns the model's free-text reply into structured output) with a model backend, so results land in standard spaCy fields such as doc.ents or doc.cats.
Is spacy-llm free to use? What license does it have?
spacy-llm is open source under the MIT license. Check the license terms before using it in commercial products.
Is spacy-llm still maintained?
Actively maintained. The last commit to spacy-llm was on Sep 27, 2026.
What can I use spacy-llm for?
Prototyping an NER or text classification step before collecting labelled training data. Combining LLM-based components with rule-based or supervised spaCy components in one pipeline. Extracting structured fields from unstructured text using a hosted or local open-source LLM.
How do I install spacy-llm?
Install the package with pip: python -m pip install spacy-llm Create an OpenAI API key and set it as an environment variable Run text classification with the llm_textcat factory in Python
Where can I get spacy-llm?
The source code and installation instructions are on GitHub: https://github.com/explosion/spacy-llm

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects