spacy-llm: Integrating LLMs into Structured NLP Pipelines with spaCy
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
spacy-llm seamlessly integrates Large Language Models (LLMs) into spaCy, offering a modular system for rapid prototyping and transforming unstructured LLM responses into robust outputs for various NLP tasks. It supports a wide range of LLMs, including OpenAI, Cohere, Anthropic, and open-source models, enabling users to combine the power of LLMs with spaCy's production-ready capabilities. This package allows for quick experimentation and the creation of efficient, reliable, and controlled NLP systems.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
`spacy-llm` is a powerful Python package that integrates Large Language Models (LLMs) into spaCy, a leading library for advanced Natural Language Processing. This integration provides a modular system designed for fast prototyping and prompting, effectively turning unstructured LLM responses into robust outputs for a variety of NLP tasks, often without requiring training data.
The package features a serializable `llm` component for easy integration into your spaCy pipeline, along with modular functions to define specific tasks and models. It interfaces with major LLM APIs such as OpenAI, Cohere, Anthropic, Google PaLM, and Microsoft Azure AI. Additionally, `spacy-llm` supports a broad spectrum of open-source LLMs hosted on Hugging Face, including Falcon, Dolly, Llama 2, OpenLLaMA, StableLM, and Mistral. It also integrates with LangChain, allowing all LangChain models and features to be utilized within `spacy-llm`.
Out-of-the-box, `spacy-llm` provides tasks for Named Entity Recognition, Text Classification, Lemmatization, Relationship Extraction, Sentiment Analysis, Span Categorization, Summarization, Entity Linking, Translation, and raw prompt execution for maximum flexibility. Users can also implement their own custom functions for prompting, parsing, and model integrations via spaCy's registry. For handling prompts that exceed an LLM's context window, a map-reduce approach is available to split prompts and fuse the results.
Installation
To install `spacy-llm`, ensure you have `spacy` installed in your virtual environment, then run the following command:
python -m pip install spacy-llm
Examples
Here are a couple of quick examples to get started with `spacy-llm`.
In Python code
For quick experiments, you can use the following Python code to perform text classification with a GPT model from OpenAI:
import spacy
nlp = spacy.blank("en")
llm = nlp.add_pipe("llm_textcat")
llm.add_label("INSULT")
llm.add_label("COMPLIMENT")
doc = nlp("You look gorgeous!")
print(doc.cats)
# {"COMPLIMENT": 1.0, "INSULT": 0.0}
This example uses the `llm_textcat` factory, which leverages the latest version of the built-in text classification task and the default GPT-3.5 model from OpenAI.
Using a config file
For more control over the various parameters of the `llm` pipeline, you can utilize spaCy's config system. Create a `config.cfg` file like the one below:
[nlp]
lang = "en"
pipeline = ["llm"]
[components]
[components.llm]
factory = "llm"
[components.llm.task]
@llm_tasks = "spacy.TextCat.v3"
labels = ["COMPLIMENT", "INSULT"]
[components.llm.model]
@llm_models = "spacy.GPT-4.v2"
Then, run the following Python code to load and use your configured pipeline:
from spacy_llm.util import assemble
nlp = assemble("config.cfg")
doc = nlp("You look gorgeous!")
print(doc.cats)
# {"COMPLIMENT": 1.0, "INSULT": 0.0}
This approach provides greater flexibility for customizing your LLM-powered NLP workflows.
Why Use spacy-llm?
Large Language Models offer powerful natural language understanding, making them excellent for quickly prototyping custom NLP tasks with few or no examples. However, for production systems, supervised learning models often provide better efficiency, reliability, control, and accuracy for well-defined tasks.
`spacy-llm` offers the best of both worlds. You can rapidly initialize pipelines with LLM-powered components for quick experimentation and then seamlessly integrate or replace them with spaCy's traditional supervised learning or rule-based components as your project matures. This allows you to leverage the prototyping speed of LLMs while maintaining the production-readiness, efficiency, and control that spaCy is known for. Even when an LLM is justified for complex tasks, `spacy-llm` enables you to combine it with other spaCy components, such as cheaper text classification models for filtering or rule-based systems for output validation, creating a robust and optimized NLP system.
Links
- GitHub Repository: explosion/spacy-llm
- spaCy Documentation: spacy.io
- PyPI Project Page: spacy-llm
Related repositories
Similar repositories that may be relevant next.

Ragas: Supercharge Your LLM Application Evaluations
August 9, 2026
Ragas is an ultimate toolkit for evaluating and optimizing Large Language Model (LLM) applications. It offers objective metrics, intelligent test generation, and data-driven insights to move beyond subjective assessments. This framework helps developers build feedback loops and continuously improve their LLM applications.

awesome-cli-coding-agents: A Curated Directory of Terminal-Native AI Tools
August 9, 2026
The `awesome-cli-coding-agents` repository offers a comprehensive, curated directory of over 100 terminal-native AI coding agents. These powerful tools operate directly within your command line, enabling autonomous code reading, editing, and execution. The list also covers various harnesses and orchestration solutions for managing these agents.

QwenPaw: Your Personal AI Assistant for Local and Cloud Deployment
August 7, 2026
QwenPaw is a powerful personal AI assistant designed for easy installation and deployment, either on your local machine or in the cloud. It supports multiple chat applications and offers highly extensible capabilities, making it a versatile tool for various AI-driven tasks. With its robust memory system and security features, QwenPaw aims to be an intuitive and private partner in your digital life.

DeepTutor: Lifelong Personalized Tutoring with AI Agents
August 7, 2026
DeepTutor is an advanced AI-powered platform designed for lifelong personalized tutoring, integrating various learning modes into a single, extensible system. It leverages large language models and multi-agent systems to offer features like interactive chat, quiz generation, and skill development. This project provides a comprehensive environment for learners and educators seeking intelligent, adaptive educational tools.
Source repository
Open the original repository on GitHub.
6 counted GitHub visits