Nested NER addresses the structural limitation of traditional flat sequence labeling, which cannot represent overlapping or hierarchically contained clinical concepts. In a phrase like "metastatic carcinoma of the lung," a flat model must choose between labeling the full string as a Diagnosis or its sub-component "lung" as an Anatomical Site. Nested NER resolves this by allowing the Anatomical Site entity to exist as a child span entirely within the parent Diagnosis entity, preserving the rich compositional semantics of clinical language.
Glossary
Nested NER

What is Nested NER?
Nested Named Entity Recognition (NER) is an advanced information extraction task that identifies entities hierarchically contained within other entities, such as a 'dosage' entity existing inside a 'medication' entity, rather than treating them as flat, non-overlapping spans.
This capability is critical for high-fidelity clinical data extraction, where medical concepts are inherently compositional. A Medication mention often contains nested attributes like Dosage, Frequency, and Route. Architecturally, this is solved by moving beyond token-level BIO tagging to layered, region-based, or generative parsing approaches. Techniques such as span categorization enumerate and classify all possible text subspans, while constituency-based methods explicitly model the tree structure, enabling downstream systems to accurately map these granular, interlocking concepts to structured schemas like FHIR.
Key Characteristics of Nested NER
Nested Named Entity Recognition addresses the critical challenge of extracting entities that are hierarchically contained within one another—a common occurrence in clinical narratives where a 'dosage' is part of a 'medication', which is part of a 'treatment regimen'.
Hierarchical Containment
The defining characteristic of nested NER is the ability to model parent-child relationships between entity spans. Unlike flat NER, which assigns a single label to a token, nested systems recognize that a text segment can simultaneously belong to multiple semantic categories at different levels of granularity.
- Example: In 'metastatic carcinoma of the lung', the entire phrase is a
Diagnosis, while 'lung' is aBody_Siteand 'carcinoma' is aHistology. - Clinical Relevance: This mirrors how clinicians document—moving from broad impressions to specific anatomical and morphological details within a single phrase.
Overlapping vs. Strict Nesting
Nested NER systems must distinguish between two structural patterns:
- Strict Nesting: One entity is fully contained within another. The inner entity's span is a complete substring of the outer entity's span.
- Overlapping Entities: Two entities share some tokens but neither fully contains the other. This is common in coordinate structures like 'liver and kidney failure', where 'liver' and 'kidney' are separate
Body_Siteentities overlapping with theDiagnosis.
Handling both requires architectures that move beyond simple BIO tagging, which assumes non-overlapping, sequential labels.
Layered Decoding Architectures
Standard linear-chain CRFs cannot model nested structures because they assume a single tag per token. Nested NER requires specialized decoding strategies:
- Layered Approach: Deploy multiple stacked NER models, each predicting entities at a different level of granularity (e.g., one layer for
Medication, another forDosage). - Span-Based Classification: Enumerate all possible text spans up to a maximum length and classify each span independently as an entity type or 'none'. This naturally handles nesting and overlapping.
- Pointer Networks: Use a generative approach where the model predicts the start and end indices of entities, allowing multiple entities to share tokens.
Transition-Based Parsing
An alternative to span classification is treating nested NER as a shift-reduce parsing problem, adapted from constituency parsing in NLP.
- Mechanism: The model reads tokens sequentially and uses a stack to build a forest of entity trees. Actions like
SHIFT,REDUCE-ENTITY, andUNARYconstruct nested structures incrementally. - Advantage: This method explicitly models the hierarchical dependencies between entities, ensuring that a
Dosagecannot be created without a parentMedication. - Clinical Application: Enforces ontological constraints, such as a
Severitymodifier being attached to aFindingrather than existing independently.
Evaluation Metrics for Nesting
Standard token-level F1 score is insufficient for evaluating nested NER because it penalizes systems that correctly identify an entity but assign it to the wrong hierarchical level. Specialized metrics are required:
- Entity-Level Precision/Recall: An entity is considered a true positive only if both its span boundaries and entity type match exactly.
- Strict vs. Lenient Matching: Strict matching requires exact boundary match; lenient matching may give partial credit for overlapping spans.
- Tree Edit Distance: Measures the structural similarity between the predicted entity tree and the gold-standard tree, capturing hierarchical errors that flat metrics miss.
Synthetic Data Generation for Training
Manually annotating nested clinical entities is exponentially more expensive and error-prone than flat annotation. A common mitigation strategy is synthetic data generation:
- Template-Based Composition: Programmatically combine known entities into nested structures using clinical templates. For example, inserting a known
DrugandDosageinto aMedicationphrase template. - Context-Free Grammar (CFG): Define a grammar that generates valid nested clinical expressions, ensuring coverage of rare nesting patterns.
- Data Augmentation: Apply back-translation or synonym replacement to existing nested annotations to increase dataset diversity without manual effort.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about identifying and extracting hierarchically structured clinical entities from unstructured medical text.
Nested Named Entity Recognition (Nested NER) is the task of identifying clinical entities that are hierarchically contained within one another in unstructured text, as opposed to flat NER, which assumes entities are non-overlapping, atomic spans. In a flat schema, the phrase '500 mg of acetaminophen twice daily' might be tagged as a single Medication entity. In a nested schema, the system simultaneously recognizes Medication as the outer entity, while 500 mg is tagged as Dosage, acetaminophen as Drug, and twice daily as Frequency—all occupying overlapping or contained token spans. This structural representation is critical for clinical use cases like medication reconciliation and prior authorization automation, where downstream logic requires the precise extraction of drug names, their strengths, and their administration schedules as discrete, related data points rather than a single monolithic string. Architecturally, flat NER models using BIO tagging or token classification cannot assign multiple labels to the same token, making them fundamentally incapable of representing nested structures without complex post-processing or schema workarounds.
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
Mastering nested NER requires understanding the foundational techniques and advanced architectures that make hierarchical extraction possible in clinical text.
Span Categorization
A modern NER paradigm that directly classifies arbitrary text spans as entity types, bypassing token-level BIO tagging. This approach is inherently superior for nested NER because it can enumerate all possible spans in a sentence and classify each one independently, naturally capturing overlapping and hierarchically contained entities like a 'dosage' inside a 'medication' mention without conflicting tag sequences.
BIO Tagging
The standard token-level annotation scheme using B (Beginning), I (Inside), and O (Outside) tags. While foundational for flat NER, standard BIO tagging fundamentally breaks with nested entities because a single token cannot simultaneously be the beginning of one entity and the inside of another. Extended schemes like BILOU or multi-layered BIO are often required as workarounds for hierarchical clinical concepts.
Conditional Random Fields (CRF)
A discriminative probabilistic model for segmenting and labeling sequence data. CRFs excel at capturing dependencies between adjacent tags, ensuring valid BIO transitions. However, standard linear-chain CRFs assume a single label per token, making them incompatible with nested structures. They are often replaced by hypergraph-based CRFs or discarded entirely in favor of span-based models for nested clinical NER tasks.
Concept Normalization
The downstream task of mapping a recognized clinical entity mention to its unique Concept Unique Identifier (CUI) in the UMLS Metathesaurus. In nested NER, normalization becomes more complex because a parent entity (e.g., 'metastatic carcinoma') and its child (e.g., 'carcinoma') may map to different CUIs with distinct semantic types, requiring the system to maintain hierarchical grounding fidelity.
Clinical NLP Pipeline
A modular, sequential architecture orchestrating components for tokenization, NER, negation detection, and concept normalization. Supporting nested NER requires a pipeline design that preserves span provenance across stages—ensuring that a negation signal applied to a parent entity correctly propagates to all its children, and that extracted hierarchical relationships survive through to final structured output.
Hybrid NER
An approach combining high-precision rule-based systems with high-recall statistical models. For nested entities, hybrid systems can use deterministic rules to define parent-child relationships (e.g., a regex for 'dosage' always being a child of 'medication') while letting a neural span categorizer handle ambiguous boundaries. This balances the structural rigidity needed for hierarchy with the flexibility of machine learning.

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