MedSpaCy is an open-source Python library that extends the general-purpose spaCy framework with specialized components and pre-trained models designed explicitly for clinical natural language processing (NLP) tasks. It provides a modular architecture for building pipelines that can identify medical entities, detect negation and uncertainty, and perform concept normalization against standard ontologies like the UMLS Metathesaurus, making it a foundational tool for extracting structured data from unstructured clinical narratives.
Glossary
MedSpaCy

What is MedSpaCy?
A specialized Python library extending spaCy for clinical natural language processing, providing pre-trained models and components for medical entity recognition and context analysis.
Unlike general NLP frameworks, MedSpaCy incorporates clinical-specific components such as the ConText algorithm for contextual analysis and medspacy.ner for medical named entity recognition. The library supports hybrid NER approaches that combine rule-based logic with statistical models, enabling high-precision extraction of drugs, diseases, and procedures from electronic health records. Its spaCy-native design ensures seamless integration with existing clinical NLP pipelines and downstream tasks like clinical entity linking and PHI recognition.
Key Features of MedSpaCy
MedSpaCy extends the spaCy library with specialized components and pre-trained models designed for the unique linguistic challenges of clinical text. It provides a modular, production-ready toolkit for extracting, interpreting, and normalizing medical concepts.
Clinical Named Entity Recognition
Pre-trained models for identifying drugs, diseases, procedures, and lab values in unstructured text. MedSpaCy's NER components are fine-tuned on clinical corpora, handling the idiosyncratic shorthand and abbreviations common in EHR notes. It supports both span-based and token-based entity extraction, allowing for the capture of complex, multi-word clinical phrases.
Contextual Analysis with ConText
Implements the ConText algorithm to determine the contextual status of clinical findings. It goes beyond simple negation to detect:
- Hypotheticality: 'If symptoms worsen, return to ED'
- Historical context: 'History of asthma'
- Family history: 'Mother had breast cancer'
- Negation: 'Patient denies chest pain' This ensures extracted entities are clinically actionable and not misleading.
Section Detection & Segmentation
A rule-based sectionizer that parses clinical notes into logical zones like Past Medical History, Medications, and Assessment/Plan. This component uses header patterns and formatting cues to segment documents, enabling downstream models to apply section-specific logic—for example, treating a medication mention in the 'Allergies' section differently than one in 'Current Medications'.
UMLS Concept Linking
Integrates with the Unified Medical Language System (UMLS) to normalize recognized entities to unique Concept Unique Identifiers (CUIs). MedSpaCy's Linker component performs approximate nearest-neighbor search over concept embeddings, mapping ambiguous surface forms like 'MI' to the correct concept (myocardial infarction vs. mitral insufficiency) based on surrounding context.
Customizable Pipeline Architecture
Leverages spaCy's native component-based pipeline design. Developers can mix and match MedSpaCy's clinical components with custom rules, statistical models, or transformer backbones. The framework supports:
- Rule-based components for high-precision extraction
- Deep learning models for high-recall pattern recognition
- Hybrid approaches combining both for production robustness
Clinical Abbreviation Detection
A dedicated component for identifying and expanding clinical abbreviations in real-time. Using a curated dictionary of common medical shorthand, it detects tokens like 'pt' (patient), 'bid' (twice daily), and 'sob' (shortness of breath). This normalization step significantly improves downstream NER and linking accuracy by reducing lexical variability.
Frequently Asked Questions
Clear, technical answers to the most common questions about using MedSpaCy for clinical natural language processing, entity extraction, and context analysis.
MedSpaCy is an open-source Python library built on the spaCy framework that provides pre-trained models and specialized components designed specifically for clinical natural language processing tasks. It works by extending spaCy's standard NLP pipeline with clinical-specific components for medical named entity recognition, negation detection, context analysis, and document section splitting. The library includes pre-trained models like en_core_med7_lg and en_ner_bc5cdr_md that can identify clinical concepts such as drugs, diseases, and procedures directly from unstructured medical text. MedSpaCy's architecture leverages spaCy's efficient tokenization and linguistic feature extraction while adding clinical components like medspacy.context for ConText algorithm implementation and medspacy.sectionizer for identifying document sections. The library processes text through a sequential pipeline where each component transforms the Doc object, enabling end-to-end clinical information extraction with minimal configuration.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core components and complementary tools that form the MedSpaCy clinical NLP ecosystem.
ConText Algorithm
MedSpaCy implements the ConText algorithm to analyze the linguistic context surrounding clinical entities. It extends simple negation detection to a broader set of semantic modifiers.
- Identifies entities experienced by the patient vs. a family member
- Detects historical conditions ('history of asthma') vs. current ones
- Flags hypothetical scenarios ('if fever develops, return to ER')
Target Rules
A core concept in MedSpaCy's ConText implementation. Target rules define the scope of a modifier's effect within a sentence.
- Forward direction: Modifier applies to entities after the cue word
- Backward direction: Modifier applies to entities before the cue word
- Bidirectional: Modifier applies to the entire sentence
- Termination points: Stop the modifier's scope at punctuation or conjunctions
Sectionizer Component
A rule-based pipeline component that segments clinical notes into logical sections. It identifies standard headers like 'HISTORY OF PRESENT ILLNESS' or 'PAST MEDICAL HISTORY'.
- Uses pattern matching on section header strings
- Adds
Sectionspans and attributes to the Doc - Enables downstream components to apply section-specific logic, such as ignoring entities in the 'Family History' section
Clinical Tokenizer
MedSpaCy extends spaCy's default tokenizer with rules specific to clinical text. It correctly handles the unique punctuation and formatting found in EHR narratives.
- Preserves infixes like slashes in 'mg/kg' without splitting
- Handles chemical formulas (e.g., 'H2O') as single tokens
- Manages irregular line breaks and list formats common in dictated notes

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us