Paper commentary
SpanBERT: Improving Pre-training by Representing and Predicting Spans
Span masking and boundary prediction improve BERT pre-training
- Problem BERT hides single word pieces and predicts each from its neighbours, which gives a weak training signal for relations between multi-token spans. Question answering and coreference resolution depend on exactly those span relations.
- Method SpanBERT masks random contiguous spans instead of single tokens. It adds a span boundary objective that predicts each masked token from the encodings at the span's two outside neighbours, and it drops the next sentence prediction task.
- Results With the BERT large configuration, SpanBERT reaches 94.6% F1 on SQuAD 1.1 and 88.7% F1 on SQuAD 2.0. It also reaches 79.6% F1 on the OntoNotes coreference benchmark, a new state of the art.
Why token masking falls short for spans
BERT pre-trains by hiding individual word pieces and recovering them from context, and this has produced strong gains across many NLP tasks. Many downstream questions, however, depend on how two or more spans of text relate to each other, not on any one token in isolation. A phrase such as a team name is hard to recover as a whole when it is hidden, while predicting a single token next to a known neighbour is comparatively easy, so a token-level objective gives a weaker signal for spans.
SpanBERT addresses this by changing two things at once: the choice of what gets masked and the training objective that uses the masked positions. The objective is designed so that the representations at a span's boundary carry enough information about the span's interior to be reused later, during fine-tuning.
Choosing contiguous spans to mask
A start position is then chosen uniformly among word beginnings, so a masked span never starts in the middle of a word, and the sampling continues until the masking budget of about 15% of the tokens is used up. The replacement rule keeps BERT's 80%, 10% and 10% split between the mask token, a random token and the original token, but it is applied to whole spans rather than to each token separately.
Predicting a masked span from its boundaries
For a masked span running from position s to position e, each token x_i inside it is predicted from the encodings of the two tokens just outside the span, x_{s-1} and x_{e+1}, together with a relative position embedding for the token's place inside the span. The combined representation is written as \( y_i = f(x_{s-1}, x_{e+1}, p_{i-s+1}) \), where the position index counts from the left boundary token.
The function f is a two-layer feed-forward network with GeLU activations and layer normalization applied after each layer, applied to the concatenation of the two boundary encodings and the position vector.
The vector y_i is then used to predict the original token with the same cross-entropy loss as MLM. Each masked token contributes the sum of the MLM term and the span boundary term, \( L(x_i) = L_{MLM}(x_i) + L_{SBO}(x_i) \), and the input embedding of the target token is shared between the two terms.
Single-sequence input instead of paired segments
BERT packs two sequences per example and adds a binary objective that asks whether the second follows the first, which is the next sentence prediction objective. SpanBERT removes both the NSP objective and the two-segment sampling, and instead draws one contiguous block of up to 512 tokens for each example.
The authors conjecture that this helps for two reasons: the model can use longer full contexts, and conditioning on unrelated text from another document adds noise to the masked language model. They present this as a conjecture and do not test the two explanations separately.
Pre-training setup and baselines
All models use the BERT large configuration and are pre-trained on BooksCorpus and English Wikipedia with cased Wordpiece tokens, implemented in fairseq. The authors' reimplementation changes several details of the original BERT pipeline: masks are drawn anew for each epoch rather than sampling ten masks per sequence, and the short-sequence strategies are removed in favour of sequences up to 512 tokens that run until a document boundary.
Each batch holds 256 sequences, and pre-training ran on 32 V100 GPUs for 15 days.
Three baselines are used: Google BERT, the released checkpoints; Our BERT, the reimplementation with the changed preprocessing and optimization; and Our BERT-1seq, the reimplementation trained on single full-length sequences without NSP.
How fine-tuning reads out each task
For extractive question answering, the passage and question are packed into one sequence, and two linear classifiers predict the start and end of the answer span. Unanswerable SQuAD 2.0 questions are assigned the special CLS token as their answer span during training and testing.
For coreference resolution, the higher-order model of Lee et al. (2018) is used with the pre-trained transformer replacing its LSTM encoder, and the document is processed in fixed-length, non-overlapping segments. For each mention, the model defines a distribution over candidate antecedent spans from pairwise scores, and the span representations combine the two endpoint outputs with an attention vector.
TACRED relation extraction masks the subject and object entities with their NER tags and adds a linear classifier on the CLS token to predict one of 42 relation types. GLUE uses nine sentence-level tasks, with WNLI left out of the reported results, and a linear classifier on the CLS token as in BERT's single-task setting.
Question answering results
The authors report a reduction in error of as much as 27% on SQuAD 1.1 relative to their tuned BERT replica.
The gain over Our BERT ranges from 2.0% on Natural Questions to 4.6% on TriviaQA.
Coreference and relation extraction results
Google BERT averages 77.1, Our BERT 78.3 and Our BERT-1seq 78.8 on the same metric.
The authors report that most of SpanBERT's gain over Our BERT on this benchmark comes from single-sequence training, with span masking and the span boundary objective contributing a smaller share. The authors compare against the BERT EM+MTB model of Soares et al. (2019), which scored 71.5 and used an intermediate matching-the-blanks pre-training on entity-linked text, so this comparison is not like-for-like.
GLUE results
On the GLUE test set, SpanBERT averages 82.8, against 80.4 for Google BERT, 81.1 for Our BERT and 81.7 for Our BERT-1seq. On SST-2, Google BERT scores 95.2 against 94.8 for SpanBERT, which is the single task where the released baseline is higher.
The RTE result is the largest gain, at 79.0 against 71.1 for Google BERT, and the authors state that it accounts for most of the rise in SpanBERT's GLUE average.
Masking schemes compared
Five masking schemes are compared with the same bi-sequence NSP setup: subword tokens, whole words, named entities, noun phrases and geometric spans. Named entities and noun phrases are each used for half of the masks, with whole words filling the rest, and each scheme masks about 15% of the subword tokens.
With the exception of coreference resolution, random span masking is preferable to the other schemes; on coreference, random subword tokens score 77.7 against 76.4 for geometric spans.
Single-sequence training and SBO ablation
Span masking under NSP scores 83.4 GLUE average and 76.4 on coreference, while single-sequence span masking scores 83.8 on GLUE and 76.3 on coreference.
Adding SBO to single-sequence span masking raises coreference from 76.3 to 79.0 and the GLUE average from 83.8 to 84.0. The authors see no adverse effects from SBO, which contrasts with the NSP objective.
Where SpanBERT sits among related pre-training work
Several methods alter BERT's masked prediction, including phrase and entity masking in ERNIE, masked sequence-to-sequence pre-training in MASS, and insertion-based filling in KERMIT. SpanBERT differs in aiming to pre-train span representations for span selection tasks, and it evaluates on English question answering, relation extraction and coreference resolution as well as GLUE.
XLNet also masks spans but predicts them autoregressively, whereas SpanBERT keeps the masked prediction framework and compares against a controlled BERT baseline. Compared with pair2vec, the authors argue that the boundary objective yields span representations that encode their context during both pre-training and fine-tuning.
Limitations
The masking-scheme results are on development sets and, as the paper states, are not directly comparable to the main test results. The masking and objective ablations use the checkpoints at 1.2M steps rather than the full 2.4M-step run.
The TACRED comparison with BERT EM+MTB is not like-for-like, because that model used entity-linked text for an intermediate pre-training stage. The single-sequence explanation is a conjecture, and the pre-training corpus is BooksCorpus and English Wikipedia only. WNLI is excluded from the GLUE results, and SST-2 is the one GLUE task where the released Google BERT scores higher.
Paper info
- Authors
- Mandar Joshi, Danqi Chen, Yinhan Liu, Daniel S. Weld, Luke Zettlemoyer, Omer Levy
- Venue
- arXiv · Preprint
- First published
- 2019-7-24
- Added
- 2026-11-12
- Updated
- 2020-1-18
- Version
- v3
- arXiv
- 1907.10529
- Category
- cs.CL · cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Mandar Joshi, Danqi Chen, Yinhan Liu, Daniel S. Weld, Luke Zettlemoyer, Omer Levy (2019). SpanBERT: Improving Pre-training by Representing and Predicting Spans. arXiv:1907.10529v3. https://arxiv.org/abs/1907.10529v3
BibTeX
@misc{joshi2019spanbert,
title = {{SpanBERT: Improving Pre-training by Representing and Predicting Spans}},
author = {Mandar Joshi and Danqi Chen and Yinhan Liu and Daniel S. Weld and Luke Zettlemoyer and Omer Levy},
year = {2019},
eprint = {1907.10529},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1907.10529v3}
}