SpanBERT is a variant of the BERT language model specifically designed to improve the representation and prediction of contiguous text spans. Unlike standard BERT, which masks individual tokens, SpanBERT masks random contiguous spans of tokens during pre-training. This forces the model to predict the entire masked span content using only the representations of the tokens at the span's boundary, a mechanism called the Span-Boundary Objective (SBO).
Glossary
SpanBERT

What is SpanBERT?
SpanBERT is a pre-training method that improves span-level representations by masking contiguous random spans and using a span-boundary objective, leading to state-of-the-art results on span selection tasks like NER.
This architecture is uniquely suited for span selection tasks like Named Entity Recognition and Coreference Resolution, where identifying exact boundaries is critical. By discarding individual token masking in favor of span-level masking and relying on boundary tokens for prediction, SpanBERT learns a geometric structure where the representation of a span's endpoints encodes the full phrase, significantly outperforming standard BERT on extraction tasks.
Key Features of SpanBERT
SpanBERT introduces a novel pre-training methodology that fundamentally shifts the focus from individual tokens to contiguous spans of text, achieving state-of-the-art results on span selection tasks like Named Entity Recognition and extractive question answering.
Span Masking
Unlike standard BERT which masks random individual tokens, SpanBERT masks contiguous random spans of text. This forces the model to predict entire multi-token sequences based on surrounding context, directly training it to reason about phrase-level semantics. For example, in the sentence 'The New York Stock Exchange closed higher,' SpanBERT might mask the entire span 'New York Stock Exchange' rather than masking 'York' and 'Stock' independently. This is critical for NER where entities are often multi-word expressions.
Span Boundary Objective (SBO)
The SBO is a novel auxiliary training task that requires the model to predict each masked token using only the representations of the tokens at the boundaries of the masked span. Specifically:
- The model observes the hidden states of the external boundary tokens (immediately before and after the span)
- It also uses the relative position of the target token within the span
- This compels the model to encode span-level information directly into the boundary token representations This objective teaches the model that boundary tokens are information-rich anchors for understanding entire phrases.
Single-Sequence Training
SpanBERT departs from BERT's practice of concatenating two half-length documents with a 50% chance. Instead, it trains exclusively on single, full-length sequences without the Next Sentence Prediction (NSP) objective. This design choice ensures that masked spans are always contiguous and contextually coherent within a single document, preventing the model from learning spurious cross-document correlations. The removal of NSP also simplifies the training pipeline and focuses the model entirely on span-level understanding within a unified context.
Geometric Span Sampling
Span lengths are sampled from a geometric distribution rather than a uniform distribution. This means shorter spans are sampled much more frequently than longer ones, but the model still occasionally encounters very long spans. The distribution is parameterized by a prior probability p (typically 0.2), which controls the expected span length. This approach:
- Mirrors the natural distribution of entity lengths in real text
- Ensures the model is robust to both short entities (e.g., 'Apple') and long nominal phrases (e.g., 'the United States Department of Justice')
- Prevents the model from overfitting to a fixed span length
State-of-the-Art on Span Selection
SpanBERT achieved significant performance gains over BERT-base and BERT-large on core span selection benchmarks without task-specific architectural modifications:
- CoNLL-2003 NER: Outperformed BERT by 2.8 F1 points
- SQuAD 1.1: Improved exact match by 2.0 points
- SQuAD 2.0: Improved F1 by 3.3 points
- Coreference Resolution (OntoNotes): Achieved a 3.3 F1 point gain These results demonstrate that span-level pre-training provides a stronger inductive bias for any downstream task requiring the identification and classification of text spans.
Architectural Compatibility
SpanBERT is not a new architecture but a pre-training methodology applied to the standard Transformer encoder. It is fully compatible with the BERT architecture and can be used as a drop-in replacement for any BERT-based model. Key implications:
- No additional parameters or inference latency compared to BERT
- Can be fine-tuned using the same pipelines and hyperparameters
- Compatible with standard token classification heads (e.g., linear layer + CRF) for NER
- The boundary representations learned via SBO can be directly leveraged for span enumeration architectures like Global Pointer or Biaffine Classifiers
SpanBERT vs. BERT: Key Differences
A technical comparison of the architectural and pre-training differences between standard BERT and SpanBERT, highlighting the design choices that improve span-level representations for tasks like Named Entity Recognition.
| Feature | BERT | SpanBERT |
|---|---|---|
Masking Strategy | Random individual tokens | Contiguous random spans |
Span Boundary Objective (SBO) | ||
Training Objective | MLM + NSP | MLM + SBO |
Next Sentence Prediction (NSP) | ||
Single-Sequence Training | ||
Span-Level Representation | Implicit | Explicit |
Performance on Span Selection Tasks | Baseline | State-of-the-Art |
Coreference Resolution F1 (OntoNotes) | 79.6 | 79.6 |
Frequently Asked Questions
Clear, technical answers to the most common questions about SpanBERT's architecture, training objectives, and performance on span-level tasks like Named Entity Recognition.
SpanBERT is a pre-training method specifically designed to improve the representation and prediction of contiguous text spans, unlike BERT which focuses on individual tokens. The key architectural difference lies in its span-based masking strategy, where random contiguous spans of tokens are masked instead of random individual tokens. This forces the model to reason about entire multi-token phrases. Additionally, SpanBERT introduces a Span Boundary Objective (SBO) , which predicts each masked token using only the representations of the tokens at the span's boundary—the words immediately outside the masked sequence. This contrasts with BERT's masked language model, which relies on the surrounding context including other masked tokens. By using boundary tokens and masking spans, SpanBERT learns to encode span-level semantics, making it exceptionally effective for downstream tasks like Named Entity Recognition (NER) and coreference resolution.
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 mechanisms that make SpanBERT a state-of-the-art model for span-level tasks, along with its primary applications and architectural comparisons.
Span Masking
Unlike standard BERT which masks random individual tokens, SpanBERT masks contiguous random spans of text. This forces the model to predict entire multi-token sequences based on surrounding context, directly training it to reason about phrase-level semantics rather than just individual word identities. The geometric distribution used for span length sampling ensures a bias toward shorter, linguistically meaningful phrases.
Span Boundary Objective (SBO)
A novel auxiliary training loss that teaches the model to predict each masked token using only the representations of the tokens at the span's boundary (the tokens immediately before and after the masked span). This structural inductive bias explicitly encodes the intuition that span content is heavily determined by its immediate context, improving performance on tasks requiring precise boundary detection like Named Entity Recognition and Extractive Question Answering.
Single-Sequence Training
SpanBERT departs from BERT's Next Sentence Prediction (NSP) objective by training exclusively on single, long contiguous sequences (up to 512 tokens). This design choice eliminates the artificial noise from NSP and allows the model to learn richer, cross-sentence dependencies within a document. The removal of NSP was proven to be crucial for span-level tasks, as the model focuses entirely on intra-textual coherence rather than sentence-pair relationships.
SpanBERT vs. BERT
The key architectural divergence lies in the pre-training objectives. While both share the Transformer encoder backbone, SpanBERT replaces BERT's token-level masking and NSP with span-level masking and the Span Boundary Objective. This results in significantly superior performance on span selection tasks like CoNLL-2003 NER and SQuAD 2.0, while maintaining comparable performance on GLUE benchmarks, proving the targeted efficacy of its design.

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