Inferensys

Glossary

Nested NER

Nested Named Entity Recognition (Nested NER) is a challenging NLP task that identifies entities hierarchically contained within other entities, such as a 'dosage' entity being part of a larger 'medication' entity in clinical text.
Product manager reviewing autonomous task execution dashboard on laptop, completed tasks visible, casual work session.
HIERARCHICAL ENTITY RECOGNITION

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.

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.

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.

HIERARCHICAL ENTITY STRUCTURES

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'.

01

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 a Body_Site and 'carcinoma' is a Histology.
  • Clinical Relevance: This mirrors how clinicians document—moving from broad impressions to specific anatomical and morphological details within a single phrase.
02

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_Site entities overlapping with the Diagnosis.

Handling both requires architectures that move beyond simple BIO tagging, which assumes non-overlapping, sequential labels.

03

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 for Dosage).
  • 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.
04

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, and UNARY construct nested structures incrementally.
  • Advantage: This method explicitly models the hierarchical dependencies between entities, ensuring that a Dosage cannot be created without a parent Medication.
  • Clinical Application: Enforces ontological constraints, such as a Severity modifier being attached to a Finding rather than existing independently.
05

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.
06

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 Drug and Dosage into a Medication phrase 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.
NESTED NER EXPLAINED

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.

Prasad Kumkar

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.