SpanBERT modifies the standard Masked Language Modeling (MLM) objective by masking contiguous sequences of tokens and using a Span Boundary Objective (SBO). Instead of predicting masked tokens based on their immediate context, SBO forces the model to predict each token in the span using only the representations of the tokens at the span's boundaries. This architectural change compels the model to learn higher-level compositional semantics and long-range dependencies.
Glossary
SpanBERT

What is SpanBERT?
SpanBERT is a pre-training method for the BERT language model that masks contiguous random spans of text rather than individual tokens, forcing the model to predict the entire masked span from its boundary tokens.
This pre-training strategy significantly improves performance on span-level tasks such as relation extraction, coreference resolution, and question answering. By learning to infer the content of an entire phrase from its surrounding context, SpanBERT generates more robust span representations than standard BERT, making it a foundational architecture for pipelines that require identifying and classifying semantic relationships between entities in unstructured text.
Key Features of SpanBERT
SpanBERT introduces a novel pre-training objective designed specifically to improve performance on span-level tasks like relation extraction and coreference resolution.
Span Masking
Unlike standard BERT which masks random individual tokens, SpanBERT masks contiguous random spans of text. This forces the model to predict entire sequences of masked words based on surrounding context, teaching it to reason about phrase-level semantics rather than relying on local collocation statistics. The span lengths are sampled from a geometric distribution, with a bias toward shorter spans to maintain a balanced training signal.
Span Boundary Objective (SBO)
The SBO is a key auxiliary loss function that requires the model to predict each masked token using only the representations of the tokens at the boundaries of the masked span. This explicitly teaches the model to encode span-level information at its edges, which is critical for downstream tasks that rely on identifying the start and end of entity mentions or argument spans. The final representation for a masked token is a function of the boundary tokens and its relative position within the span.
Single-Sequence Training
SpanBERT abandons the Next Sentence Prediction (NSP) objective used in original BERT. Instead, it pre-trains on single, long contiguous text sequences of up to 512 tokens, sampled from document boundaries. This design choice was motivated by the finding that NSP is detrimental or neutral for span-oriented tasks. By removing the artificial 50/50 sentence-pair construction, the model learns better long-range discourse-level dependencies within a single coherent context.
Performance on Relation Extraction
SpanBERT achieves state-of-the-art results on several span selection benchmarks without task-specific architectural modifications. On TACRED, a challenging relation extraction dataset, SpanBERT substantially outperforms BERT-base and BERT-large. This performance gain is directly attributed to the span masking and SBO objectives, which provide a better inductive bias for identifying the entity spans that serve as arguments to a relation classifier.
Coreference Resolution Gains
The architecture demonstrates exceptional performance on coreference resolution, the task of clustering all mentions that refer to the same real-world entity. On the OntoNotes benchmark, SpanBERT-large sets a new standard by learning to represent entire mention spans effectively. The SBO is particularly well-suited here, as coreference decisions often hinge on the semantic content concentrated at the head and tail of a noun phrase.
Contrast with BERT
The key differentiators from original BERT are threefold:
- Masking Strategy: Contiguous spans vs. random subword tokens
- Auxiliary Loss: Span Boundary Objective vs. Next Sentence Prediction
- Input Format: Single contiguous sequences vs. concatenated sentence pairs These changes are conceptually simple but represent a fundamental shift in pre-training philosophy from token-level language modeling to span-level semantic understanding, making SpanBERT a specialized tool for information extraction pipelines.
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.
Frequently Asked Questions
Clear, technical answers to the most common questions about SpanBERT's architecture, training methodology, and its specific advantages for span-level prediction tasks like relation extraction.
SpanBERT is a pre-training method for BERT that masks contiguous spans of text rather than random individual tokens, forcing the model to predict the entire masked span using only the boundary tokens. The key architectural difference lies in two novel training objectives: span masking, which replaces random token masking with geometrically distributed contiguous spans, and the Span Boundary Objective (SBO) , which requires the model to predict each token in a masked span solely from the representations of the tokens at the span's boundaries. Unlike standard BERT, which relies on individual masked token positions, SpanBERT explicitly trains the model to reason about the semantic content of an entire phrase using its surrounding context. This makes it significantly more effective at span-level tasks like relation extraction and coreference resolution, where understanding the full extent and meaning of an entity mention is critical.
Related Terms
Understand SpanBERT within the broader ecosystem of relation extraction, transformer architectures, and knowledge graph construction.
Relation Extraction (RE)
The core downstream task that SpanBERT was designed to improve. RE involves automatically identifying and classifying semantic relationships between named entities in unstructured text.
- Input: "Steve Jobs co-founded Apple in Cupertino."
- Output:
(Steve Jobs, founded, Apple) - SpanBERT's contiguous masking directly mirrors the need to process multi-token entity spans as atomic units.
Joint Entity and Relation Extraction
A modeling paradigm that simultaneously identifies entities and their relationships in a single step, rather than as a pipeline.
- Pipeline models suffer from error propagation where entity mistakes cascade into relation errors.
- Joint models leverage shared span representations, a concept SpanBERT's architecture inherently supports through its span-level pre-training objective.
Document-Level Relation Extraction (DocRED)
The task of extracting relationships between entities that span multiple sentences within a full document, requiring long-range reasoning.
- SpanBERT's ability to create robust span representations helps models track entities across sentence boundaries.
- This contrasts with sentence-level RE, where both entities appear in the same sentence.
Dependency Paths
The syntactic route through a dependency parse tree connecting two entities, historically used as a key feature for classifying their relationship.
- Before SpanBERT, many RE systems relied heavily on explicit dependency path features.
- SpanBERT's deep contextualized span representations largely eliminate the need for hand-crafted syntactic features, learning these patterns implicitly.
Knowledge Graph Population
The process of adding new entities and relationships to an existing knowledge graph from external data sources.
- SpanBERT serves as a critical encoder in this pipeline, extracting semantic triples from text corpora.
- The extracted triples—
(subject, predicate, object)—form the foundational units that populate and expand enterprise knowledge graphs.
Contrastive Representation Learning
A training paradigm where models learn to pull similar representations together and push dissimilar ones apart in embedding space.
- SpanBERT's span-level objective can be viewed as a form of contrastive learning, where the model learns that a contiguous span is semantically distinct from its surrounding context.
- This principle is shared with SimCSE and other sentence embedding methods.

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