A dynamic programming algorithm for span-based nested named-entity recognition in O(n²)

Caio CorroACL 2023

Introduction

Named-Entity Recognition (NER) is a fundamental task in natural language processing, traditionally focused on identifying non-overlapping entities like people, locations, or organizations. However, real-world language often contains nested entities, where one mention resides within another—for example, "[The [University of [Paris]]]" or "[[United States] army]".

Examples of nested named entities and their categorical labels.

While "flat" NER is computationally efficient, the gold standard for span-based nested NER has historically relied on the CYK algorithm, which carries a cubic-time ($O(n^3)$) complexity. This means that as sentence length increases, the computational cost grows exponentially, creating a significant bottleneck for processing long documents or real-time applications. This paper introduces a novel dynamic programming algorithm that reduces this complexity to quadratic-time ($O(n^2)$) with virtually no loss in accuracy.

Breaking the Cubic Barrier: The "One-Long-Child" Constraint

The core innovation of this research is the identification of a structural regularity in how humans nest entities. The authors observed that in standard datasets, nested entities are rarely balanced trees. Instead, most mentions contain at most one nested child that is itself a multi-word span.

By formalizing this as the "One-Long-Child" constraint, the algorithm avoids the expensive $O(n^3)$ "split-point" search required by CYK. This constraint allows the model to build internal structures of mentions by looking at specific "left" and "right" neighborhoods rather than every possible combination of sub-spans.

Algorithmic Features

  • Uniqueness: The algorithm ensures a unique derivation for every analysis. This mathematical property is vital for training models using negative log-likelihood (CRF-style), as it prevents the model from overestimating probabilities due to redundant paths.
  • Neural Backbone: The algorithm is integrated with a modern neural architecture, utilizing a fine-tuned BERT model, BiLSTM layers, and biaffine scorers to weight potential spans.

Key Insights and Efficiency

One of the most striking findings is that the trade-off between efficiency and coverage is largely a myth in this context. The $O(n^2)$ constraint still covers 98.9% to 99.8% of all mentions across standard English benchmarks like ACE-2004, ACE-2005, and GENIA. By sacrificing a negligible fraction of theoretical edge cases, the model gains massive practical speed.

Furthermore, by using a "parsing-as-deduction" framework, the authors provide a mathematically grounded transition from $O(n^3)$ to $O(n^2)$, making the logic transparent and verifiable.

Empirical Results

Speed and Scalability

The transition to $O(n^2)$ yields a dramatic performance boost. In head-to-head testing, the quadratic algorithm maintained high throughput even as sentence length increased, whereas the $O(n^3)$ version's performance degraded rapidly.

Comparison of decoding time (seconds per sentence) vs. sentence length for O(n³) and O(n²) algorithms.

As shown in the figure above, the cubic algorithm (solid line) scales poorly, while the proposed quadratic approach (dotted/dashed lines) remains efficient. In practical terms, the $O(n^2)$ model can decode over 1,500 sentences per second, compared to fewer than 50 for the cubic version on longer sequences.

Accuracy

Despite the simplified search space, accuracy remains competitive with state-of-the-art models:

  • GENIA: The $O(n^2)$ model achieved an F1 score of 78.25, slightly outperforming the $O(n^3)$ baseline (78.24).
  • ACE-2005: The F1 score was 84.85, nearly identical to the cubic version's 85.01.

Conclusion and Future Work

This paper demonstrates that nested NER does not inherently require cubic complexity for high-quality results. By leveraging the "One-Long-Child" constraint, the authors provide a path toward scalable, real-time nested entity recognition.

Future research may explore how these nesting patterns vary in morphologically rich languages or extend the algorithm to handle discontinuous mentions (e.g., "the pain in his left and right arms"). Additionally, incorporating lexical "heads"—the most significant word in a span—could further refine the model's accuracy in complex syntactic structures.

Summary updated

BibTeX
@inproceedings{corro2023dynamic,
  author = {Caio Corro},
  title = {{A dynamic programming algorithm for span-based nested named-entity recognition in O(n²)}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.598},
}
Figure