Papers · 2018 · Reading: 23 min, plus 6 in closed details · +3h 20m of resources.
Paper · NAACL 2019 (best long paper) · arXiv 1810.04805

BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding (BERT)

Jacob Devlin, Ming-Wei Chang, Kenton Lee, Kristina Toutanova
Google AI Language · October 2018 (arXiv v1 11 October 2018; v2 24 May 2019)

In one line: Masked-LM pretraining of a deep bidirectional Transformer encoder plus per-task fine-tuning set SOTA on 11 NLP tasks and made pretrain-then-finetune the default recipe; the encoder lineage lives on in embeddings/retrieval via ModernBERT and Ettin.

80.5 GLUE score
BERT-Large on the official GLUE leaderboard
against 72.8 for OpenAI GPT: +7.7 points · §4.1
93.2 F1
SQuAD v1.1 test, BERT-Large ensemble with TriviaQA
+1.5 over the top leaderboard system; human 91.2 · Table 2
77.8 F1
SQuAD dev when the same model is pretrained left to right
against 87.9 bidirectional: the paper's core ablation · Table 5

How far to trust it: Believe the central claim: masked-LM pretraining of a deep bidirectional encoder beats the same model trained left to right, by margins many standard errors wide, and every later encoder confirmed it. Treat next sentence prediction as unproven (one run, one task outside the noise, reversed by RoBERTa) and the dev-set ablations as single, dev-selected runs. The evidence, judged.

The idea in one sentence

Hide 15% of the input words and train a deep Transformer encoder to recover them from both sides, so every layer can look left and right without the answer leaking into its own prediction; then copy that one pretrained encoder per task, add a single output layer and fine-tune everything.

New terms. Masked LM (MLM): predict hidden input words from both sides. NSP: is sentence B the real next sentence? C: the final state of [CLS]; Ti: the final state of token i. Feature-based against fine-tuning transfer: freeze the representations and feed them to a task model, or train everything.

The method at a glance

§3, Figure 1

One encoder, pretrained once with two losses, then copied and fine-tuned per task with one small output layer. The figure is the paper's Figure 1 in 3D, run on one pretraining pair of this page's toy language by the toy BERT (Run a toy BERT); drag it to turn it.

  1. One input: a pair of sentences. [CLS], sentence A (blue), [SEP], sentence B (green), [SEP], packed into one sequence. For the masked LM some word positions are hidden: here dog becomes [MASK].
  2. One deep encoder, every layer looking both ways. A stack of Transformer layers (12 in BERT-Base, 24 in Large, 2 in the toy) turns every token into a final state: C for [CLS], Ti for token i. The orange streams are the masked position gathering from both sides, in proportion to its attention weights.
  3. Loss 1: the masked LM. Ti at the masked position goes through a softmax over the vocabulary: the toy BERT puts on dog, a word it can only infer from "barked" on its right.
  4. Loss 2: next sentence prediction (NSP). C is classified IsNext or NotNext, whether sentence B really follows sentence A; for this real pair the toy says IsNext with . The two losses are added; this pretraining is done once, on unlabelled text.
  5. Copy the pretrained encoder, once per task. Every task starts from the same checkpoint in its own copy, and all of its weights will be fine-tuned.
  6. Add one small output layer each. A label from C for sentence tasks (GLUE), start and end scores over the token states Ti for a SQuAD answer span, a tag per token for NER. Everything else is the copied encoder.

After Figure 1, redrawn (the arXiv paper is not CC BY, so no image of the original); the paper's figure uses illustrative tokens, this one the toy's. The output layers in the last step are drawn, not run: the toy's own fine-tuning is measured in Run a toy BERT.

Problem

§1 Introduction, §2 Related work

By 2018, pretraining a language representation on unlabelled text and then transferring it was clearly effective: ELMo, ULMFiT and OpenAI GPT had all improved many tasks with it (§1, §2). There were two ways to transfer. The feature-based way (ELMo) feeds pretrained representations as extra features into a task-specific architecture. The fine-tuning way (GPT) adds a few task parameters and fine-tunes all the pretrained ones. Both pretrained with the same kind of objective: a unidirectional language model (§1).

That is the handicap the paper attacks. A standard language model can only be trained left to right (or right to left), because in a deep network that conditions on both sides each word could indirectly "see itself" through the higher layers (§3.1). So GPT's Transformer lets every token attend only to tokens on its left, and ELMo's two directions are separate, shallow LSTMs whose outputs are merely concatenated (§2.1, Figure 3). For sentence-level tasks this is sub-optimal; for token-level tasks such as question answering and named entity recognition, where the context on the right of a word is essential, it "could be very harmful" (§1).

The gap: a way to pretrain a genuinely deep bidirectional model on unlabelled text that transfers to many tasks, sentence-level and token-level, with minimal task-specific architecture.

Idea: hide the word, then let every layer look both ways

§3.1 Task #1: Masked LM

Why can a bidirectional model not simply be trained to predict each word? Because in a stack of self-attention layers, the state at position i in layer 2 attends to every position of layer 1, and each of those already attended to the word at i. The answer leaks into its own prediction, and the model "could trivially predict the target word" (§3.1). A left-to-right model avoids the leak by never looking right, which is exactly the handicap.

BERT's answer is the masked language model (MLM), the Cloze task of Taylor (1953): replace some input words with a [MASK] token and predict the original only at those positions, from both sides (§3.1). The word to predict is not in the input any more, so no path through the layers can carry it, and every layer may attend in both directions. The figure runs one sentence through two layers three ways; pick one, then follow its steps.

  1. Hide the word. The data generator replaces dog with [MASK]. The answer is no longer anywhere in the input.
  2. Layer 1 looks both ways. Every position attends to every position. No state can pick up the word dog: it is not there. The blue streams are the masked position gathering context from both sides.
  3. Layer 2 looks both ways. The state at the masked position gathers both sides, including barked three words to the right.
  4. Predict the hidden word. The masked-LM head reads T3, and the toy BERT gives dog . Only the context can explain the answer, so the model must learn what "barked" implies. This is the objective that makes deep bidirectionality trainable.

Two attention layers of this page's toy models (Run a toy BERT): line width and dot density are their real attention weights, heads averaged, and the probabilities are their real outputs. Orange states hold information from the word dog itself. The left-to-right model predicts the word at a position from the state one position earlier, as a language model does. "Both ways, no mask" uses the toy BERT's weights on the unmasked sentence; such a model is not trained here, since it would learn to copy.

a left-to-right model reads "the big ___" and must guess the next word; the sentence goes on "... purred at the farmer". How sure can it be that the word is cat?

Model and input

§3, Figure 2

BERT is "a multi-layer bidirectional Transformer encoder" almost identical to the original of Vaswani et al. (2017) (§3). With L layers, hidden size H and A attention heads, and the feed-forward size always 4H (footnote 3):

ModelLHAFeed-forwardParameters (paper)Recounted
BERT-Base12768123,072110M
BERT-Large241024164,096340M
OpenAI GPT12768123,072(same size)

Base recounts to 110M from the released configuration, independently; Large to 335M, not 340M (details below).

How the parameters were recounted

Recounted from the released configurations (bert-base-uncased, bert-large-uncased, vocabulary 30,522, 512 positions): embeddings (V + 512 + 2)H plus their LayerNorm, per layer 4(H² + H) + 2 · 4H² + 5H + 4H, plus the pooler H² + H. Base reproduces 110M independently; Large comes out at 335M, not 340M, and the pretraining heads add only 0.6M to 1.1M. ModernBERT's Table 2 lists BERT-Large as 330M. GPT from its configuration (vocabulary 40,478): BERT-Base "was chosen to have the same model size as OpenAI GPT" (§3), and the two differ by about 6%, all of it in GPT's larger vocabulary (40,478 entries against 30,522). The tables tab recounts every Table 6 size.

The one architectural difference from GPT is the attention mask: BERT's self-attention is bidirectional, GPT's lets each token see only its left, which is why the literature calls them a Transformer "encoder" and "decoder" (footnote 4). The input has to represent a single sentence or a pair (question and passage, say) as one sequence, where a "sentence" is any span of contiguous text (§3):

  • WordPiece tokens (Wu et al. 2016) from a 30,000-token vocabulary (the released vocabulary file has 30,522 entries).
  • Every sequence starts with [CLS]; its final hidden state C ∈ ℝH is the aggregate representation for classification. The final state of token i is Ti.
  • A pair is packed into one sequence, separated by [SEP], and each token also gets a learned segment embedding, A or B.
  • The input vector of each token is the sum of its token, segment and (learned) position embeddings (Figure 2).
  1. One sequence, two segments. "[CLS] austin smiled [SEP] i met austin [SEP]": sentence A, then sentence B, each closed by [SEP]. The word austin appears twice.
  2. Token embedding. Each token reads its row of the token table (90 words × 24 numbers in the toy, 30,522 × 768 in BERT-Base). Both austins get the same vector.
  3. Segment embedding. The segment table has two rows only: every token of sentence A gets vector A, every token of B vector B. This is how the model tells the two sentences apart.
  4. Position embedding. One learned vector per position (24 in the toy, 512 in BERT), unlike the fixed sinusoids of the original Transformer.
  5. Add them. Each token's input is the sum of its three vectors, which the model then layer-normalises before the first layer.
  6. The same word, two inputs. The two austins share their token vector but not their sums: position and segment are what tell them apart before any attention runs.

Figure 2 redrawn with the toy BERT's real learned vectors: 24 numbers each, drawn as bars (up positive, down negative, one scale for every row); the tables are the glass plates on the left. Note the segment row: two vectors only, A for the first sentence and B for the second.

Pretraining task 1: the masked LM

§3.1, Appendix A.1

The data generator picks 15% of the WordPiece positions of each sequence at random. Their final states Ti go through a softmax over the vocabulary and are trained with cross-entropy to predict the original token; unlike a denoising autoencoder, nothing else is reconstructed (§3.1; how MLM compares with causal LM, span corruption and UL2 as objectives is on Families and objectives). Masking is applied after WordPiece tokenisation, uniformly, with no special treatment of word pieces (A.2).

Whole Word Masking, released later by the authors

The authors later released Whole Word Masking models, which mask all the pieces of a word at once, because predicting one piece of a split word was "too 'easy'" (repository README, 31 May 2019).

A [MASK] token never appears at fine-tuning time, which creates a mismatch. So a chosen position is not always masked (§3.1, A.1):

Of the chosen 15%Example (the 4th token, hairy, chosen)Share of all tokens
80%: replaced by [MASK]my dog is hairy → my dog is [MASK]12%
10%: replaced by a random wordmy dog is hairy → my dog is apple1.5%
10%: left unchangedmy dog is hairy → my dog is hairy1.5%

Because the encoder does not know which words it will be asked to predict, or which were swapped, it is forced to keep "a distributional contextual representation of every input token"; keeping some words unchanged biases the representation towards the observed word, and random replacement touches only 1.5% of tokens (10% of 15%), too few to harm understanding (A.1). The price: only 15% of positions produce a loss in each batch, against every position for a left-to-right model, so MLM should need more steps. It does converge marginally slower, but its downstream accuracy overtakes the left-to-right model's almost immediately (C.1, Figure 5 below).

The masking is the paper's rule exactly as the toy was trained (at least one position, never [CLS] or [SEP]; then 80/10/10). The predictions are the toy BERT's, at every chosen position, including those it was not told were changed. The tally draws the rule 10,000 times over this pair's positions.

Pretraining task 2: next sentence prediction

§3.1 Task #2: NSP

Question answering and natural language inference turn on the relation between two sentences, which language modelling does not capture directly. So every pretraining example is a pair: 50% of the time B is the sentence that actually follows A (IsNext), 50% a random sentence from the corpus (NotNext), and C, the final [CLS] state, classifies which (§3.1). The final model gets 97% to 98% on it (footnote 5), and C is "not a meaningful sentence representation without fine-tuning, since it was trained with NSP" (footnote 6). The appendix's examples:

[CLS] the man went to [MASK] store [SEP] he bought a gallon [MASK] milk [SEP] → IsNext
[CLS] the man [MASK] to the store [SEP] penguin [MASK] are flight ##less birds [SEP] → NotNext
Appendix A.1. The total pretraining loss is the mean masked-LM likelihood plus the mean NSP likelihood (A.2).
  1. Pack a real pair. Sentence A and the sentence that really follows it in the toy's training text, as one sequence: an IsNext example.
  2. [CLS] reads the whole pair. Its final state C is built by attention over every token of both sentences; the streams are [CLS]'s real layer-2 attention weights in the toy BERT, heads averaged.
  3. C, the pooler, two classes. C goes through a dense layer with tanh (the pooler) and a two-way softmax: IsNext with for this pair.
  4. Swap B for a random sentence. Half of all pretraining pairs do this: B is drawn from elsewhere in the corpus, a NotNext example.
  5. The same weights say NotNext. IsNext falls to . In the toy this is easy, since each of its documents is about one entity and a real next sentence shares it; the 97% to 98% above is the paper's model on real text.

The paper reports NSP as "very beneficial to both QA and NLI" (§3.1); its own ablation shows a mixed effect (QNLI loses 3.5 points without it, the others 0.6 or less), and later work dropped it (How much to believe).

Earlier sentence objectives

Earlier sentence objectives (Jernite et al. 2017, Logeswaran and Lee 2018) transferred only sentence embeddings; BERT transfers all its parameters (§3.1).

Pretraining setup

§3.1 Pre-training data, Appendix A.2
  • Data: BooksCorpus (800M words) and English Wikipedia (2,500M words, text passages only, no lists, tables or headers). A document-level corpus, not shuffled sentences like the Billion Word Benchmark, is "critical" to extract long contiguous sequences (§3.1).
  • Examples: two spans sampled from the corpus, A and B, combined length at most 512 tokens, 50% IsNext (A.2).
  • Batch and steps: 256 sequences of 512 tokens ("128,000 tokens/batch"; exactly 256 × 512 = 131,072) for 1,000,000 steps, "approximately 40 epochs over the 3.3 billion word corpus" (by the paper's own arithmetic 106 × 128,000 / 3.3 × 109 = 38.8).
  • Sequence length: attention is quadratic in length, so 90% of the steps use length 128 and the last 10% length 512, "to learn the positional embeddings".
  • Optimiser: Adam, learning rate 10−4, β1 = 0.9, β2 = 0.999, L2 weight decay 0.01, warmup over the first 10,000 steps then linear decay; dropout 0.1 on all layers; GELU (Hendrycks and Gimpel 2016) instead of ReLU, following GPT.
  • Hardware: BERT-Base on 4 Cloud TPUs in Pod configuration (16 TPU chips), BERT-Large on 16 Cloud TPUs (64 chips); each took 4 days (A.2).
How many tokens the run really saw

Derived, with an assumption the paper does not state: if the batch stays 256 sequences at length 128, the run sees 0.9 × 106 × 256 × 128 + 0.1 × 106 × 256 × 512 ≈ 42.6 billion token positions, about 13 passes over 3.3 billion words rather than 40 (and WordPiece tokens outnumber words).

BERT was deliberately built as close to GPT as possible so the two could be compared, but four other things differ (A.4): more data, a bigger batch, special tokens learned in pretraining, and a per-task learning rate (numbers in the closed block). The ablations below isolate the objective from these.

The four differences from GPT, with numbers

BERT was deliberately built as close to GPT as possible so the two could be compared, but four other things differ (A.4): BERT also trains on Wikipedia (GPT: BooksCorpus only); BERT learns [SEP], [CLS] and the segment embeddings in pretraining (GPT adds them at fine-tuning); BERT's batch is 128,000 words against GPT's 32,000, both for 1M steps; and BERT picks a fine-tuning learning rate per task where GPT used 5e-5 for all.

Fine-tuning: one extra layer per task

§3.2, §4, Appendix A.3, A.5

For each task the task inputs and outputs are plugged in and all parameters are fine-tuned end to end; each task gets its own copy, initialised from the same checkpoint (§3, Figure 1). Sentence A and B become a paraphrase pair, a hypothesis-premise pair, a question-passage pair, or a text paired with nothing (classification, tagging). Encoding the concatenated pair with self-attention already includes bidirectional cross-attention between the two, which replaces the separate encode-then-cross-attend stages of earlier pair models (§3.2). The new parameters are tiny (§4, Figure 4): a K × H classifier on C for GLUE; for SQuAD a start vector S and an end vector E, with Pi = eS·Ti / Σj eS·Tj and the best span S·Ti + E·Tj, j ≥ i; under 0.001% of the encoder.

Every task's output layer and settings (SQuAD v2.0's no-answer rule, SWAG, NER)
TaskOutputNew parameters (BERT-Large)Paper's settings
GLUE classification (§4.1)W ∈ ℝK×H on C; loss log softmax(CW⊤)K × 1,024 (3,072 for MNLI's 3 labels)batch 32, 3 epochs, learning rate the best of 5e-5, 4e-5, 3e-5, 2e-5 on dev; several random restarts for Large on small sets
SQuAD v1.1 (§4.2)start vector S, end vector E; Pi = eS·Ti / Σj eS·Tj; span score S·Ti + E·Tj, best with j ≥ i2,0483 epochs, 5e-5, batch 32; question as segment A, passage as B
SQuAD v2.0 (§4.3)as v1.1, with "no answer" as a span at [CLS]: answer only if max S·Ti + E·Tj > S·C + E·C + τ, τ tuned on dev2,0482 epochs, 5e-5, batch 48, no TriviaQA
SWAG (§4.4)four sequences (sentence plus each ending); one vector scores each C, softmax over the four1,0243 epochs, 2e-5, batch 16
NER (§5.3)a classifier on each word's first sub-token, no CRFK × 1,024case-preserving WordPiece, maximal document context

New parameters counted from the output layers the paper describes (weights only), against 335M recounted for the encoder: under 0.001%.

Fine-tuning is cheap: every result in the paper "can be replicated in at most 1 hour on a single Cloud TPU, or a few hours on a GPU" from the same pretrained model; the SQuAD model trains in about 30 minutes on one Cloud TPU to 91.0 dev F1 (§3.2, footnote 7).

Fine-tuning hyperparameters that work (Appendix A.3)

Across tasks, batch 16 or 32, learning rate 5e-5, 3e-5 or 2e-5 and 2 to 4 epochs work well; data sets with 100k+ labelled examples are far less sensitive to the choice than small ones, and an exhaustive search over the grid is reasonable (A.3).

fine-tune the toy left-to-right model to tag names as person or place, keeping its left-only attention as the paper did. On names whose cue comes after them ("yesterday austin is a city"), what accuracy does it reach?

Results: eleven tasks

§4, Tables 1 to 4

BERT set a new state of the art on eleven NLP tasks (abstract, §4). Counting the tasks of section 4, they are the eight GLUE tasks reported in Table 1, SQuAD v1.1, SQuAD v2.0 and SWAG; CoNLL NER (§5.3) is not among them.

  • GLUE (§4.1, Table 1): on the official leaderboard BERT-Large scores 80.5 against GPT's 72.8 (+7.7). Table 1's Average leaves out WNLI, whose every submitted system had scored below the 65.1 majority-class baseline (BERT's submission predicted the majority class; B.1); on that average Base and Large gain 4.5 and 7.0 points over the prior best, GPT (79.6 and 82.1 against 75.1; recomputed from the nine columns, all reproduce). MNLI: 86.7%, +4.6. BERT-Base and GPT are "nearly identical in terms of model architecture apart from the attention masking", and Large beats Base on every task, most on the smallest ones.
  • SQuAD v1.1 (§4.2, Table 2): 93.2 test F1 for an ensemble of 7 fine-tuned first on TriviaQA, +1.5 over the top leaderboard system (nlnet, 91.7) and above the human 91.2. A single model with TriviaQA gets 91.8, beating the top ensemble. Without TriviaQA the loss is only 0.1 to 0.4 F1 on dev (recomputed: 0.2 single, 0.4 ensemble).
  • SQuAD v2.0 (§4.3, Table 3): 83.1 test F1, +5.1 over the previous best (78.0).
  • SWAG (§4.4, Table 4): 86.3%, +27.1 over the dataset authors' ESIM+ELMo and +8.3 over GPT; expert humans scored 85.0 and five-annotator humans 88.0 (on 100 samples).
  • CoNLL-2003 NER (§5.3, Table 7): 92.8 test F1 fine-tuned (Large), competitive with task-specific systems (CSE 93.1, CVT 92.6) rather than above them.

The headline claim is less any one number than the pattern: the same pretrained checkpoint with a one-layer head beat specialised architectures on sentence-level and token-level tasks alike (§1). Every table is sortable and rebuilt in The paper's tables, rebuilt.

One recipe, five benchmarks: large gains on GLUE, SQuAD v2.0 and SWAG, a small one on SQuAD v1.1, and level with the best on NER

Grey: the previous best the paper compares against; colour: BERT-Large (blue above, orange below). GLUE from §4.1 (official leaderboard score), SQuAD from Tables 2 and 3 (v1.1: an ensemble of 7 with TriviaQA), SWAG from Table 4, NER from Table 7. The axis starts at 70, so read the gaps, not bar lengths.

Ablations: what the gains come from

§5, Tables 5 to 8, Figure 5

Pretraining tasks (§5.1, Table 5). BERT-Base is retrained with the same data, fine-tuning and hyperparameters but no NSP, and then as a left-to-right LM with no NSP: "directly comparable to OpenAI GPT, but using our larger training dataset, our input representation, and our fine-tuning scheme". The left-only constraint is kept at fine-tuning, since removing it introduced a mismatch that hurt.

which costs more SQuAD F1: removing next sentence prediction, or switching the masked LM to left to right?

The left-to-right model is worse on every task, with large drops on MRPC (86.5 to 77.5) and SQuAD (87.9 to 77.8): its token states have no right-side context. A randomly initialised BiLSTM on top, "a good faith attempt at strengthening the LTR system", recovers 7.1 SQuAD F1 but still falls far short, and hurts GLUE.

Why not two directions concatenated, as ELMo does

Training separate left-to-right and right-to-left models and concatenating them, as ELMo does, would be twice as expensive, non-intuitive for QA (the right-to-left model cannot condition the answer on the question) and strictly less powerful than a model that uses both sides in every layer (§5.1).

Model size (§5.2, Table 6). Six sizes from 3 to 24 layers, each fine-tuned with 5 random restarts: bigger is strictly better on all four measures, even on MRPC with 3,600 labelled examples. The authors' hypothesis: fine-tuned directly with very few new parameters, even tiny tasks benefit from bigger pretrained representations.

Model size against earlier work

Earlier feature-based studies had found mixed returns (Peters et al. 2018b: two to four bi-LM layers; Melamud et al. 2016: 200 to 600 hidden units helped, 1,000 did not). For scale, the largest Transformer in Vaswani et al. was L=6, H=1024, A=16 (100M parameters in the encoder) and the largest in the literature L=64, H=512, A=2 (235M, Al-Rfou et al. 2018).

Feature-based BERT (§5.3, Table 7). Frozen features have advantages: some tasks do not fit an encoder, and an expensive representation can be computed once and reused. On NER, frozen BERT-Base features into a two-layer 768-dimensional BiLSTM do nearly as well as fine-tuning: concatenating the top four layers gives 96.1 dev F1, 0.3 behind fine-tuning's 96.4; the input embeddings alone give 91.0.

Masking procedure (C.2, Table 8). Fine-tuning is "surprisingly robust" to the 80/10/10 split (MNLI 83.6 to 84.4 across six mixes). The feature-based NER case, where the representation cannot adapt, shows the mismatch: [MASK] only drops to 94.0 against 94.9, and random only is much worse too.

Training steps (C.1, Figure 5). BERT-Base gains almost 1.0% MNLI going from 500k to 1M steps, and the masked LM, though it converges slightly slower, "begins to outperform the LTR model almost immediately".

The points of Figure 5, decoded from the figure's own vector coordinates in the arXiv HTML (exact to the plot, not read by eye; see tables.json). Read this way the left-to-right model is ahead at 30k and 50k steps (79.4 and 79.8 against 78.6 and 79.6) and the masked LM leads from 100k on; the 500k to 1M gain is 0.8 by linear interpolation between the 400k and 600k points ("almost 1.0%" in the text). The toy's own version is in Run a toy BERT.

How much of this to believe

§4, §5, Tables 1, 5 and 8, A.4

What holds up, and why. The headline results are on hidden test sets, scored by the GLUE and SQuAD servers, and BERT-Large's gains over GPT on the accuracy-scored GLUE tasks are between 4.9 and 11.9 standard errors of a difference. The core ablation changes one thing, the objective and its attention mask, with the same data and fine-tuning: going left to right costs 10.1 SQuAD F1 (Table 5). The toy on this page reproduces that direction independently (Run a toy BERT), RoBERTa's reimplementation replicated BERT-Base, and every encoder since keeps the masked LM. Beyond the paper.

The arithmetic behind "what holds up"

The headline results are on hidden test sets, scored by the GLUE and SQuAD servers, and the gains are far larger than the noise of those sets. On the GLUE tasks scored by accuracy, BERT-Large beats GPT by 4.6 points on MNLI-m (9,796 test examples), 5.3 on QNLI, 3.6 on SST-2 and 14.1 on RTE (3,000): between 4.9 and 11.9 standard errors of a difference (Table 1; binomial standard errors from the split sizes of the GLUE release, computed in recompute.py, treating the two systems' errors as independent, which overstates the noise of a paired comparison). The core ablation changes one thing, the objective and its attention mask, with the same data and fine-tuning: going left to right costs 10.1 SQuAD F1, 9.0 on MRPC (3.8 standard errors on its 408 dev examples) and 1.8 on MNLI (3.5) (Table 5). The toy on this page reproduces that direction independently (Run a toy BERT). And it replicated: RoBERTa's reimplementation of BERT-Base, with NSP, reached 90.4 SQuAD v1.1 F1 against the published 88.5, 92.9 on SST-2 against 92.8 and 84.0 on MNLI-m against 84.3 (Liu et al. 2019, Table 2), and every encoder since keeps the masked LM. Beyond the paper.

Where the evidence is weaker.

  • Next sentence prediction rests on one task. Each Table 5 row is one pretraining run. Removing NSP costs 0.5 on MNLI-m (1.0 standard error), 0.2 on MRPC and 0.1 on SST-2 (both 0.1), 0.6 SQuAD F1; only QNLI's 3.5 (5.7 standard errors) is clearly outside the noise. "Very beneficial to both QA and NLI" (§3.1) is stronger than that. RoBERTa, training on blocks of text from single documents, found the opposite, that removing NSP "matches or slightly improves" results, and suggested the original No NSP run may have dropped only the loss while keeping the paired-segment input (Liu et al. 2019, §4.2). ModernBERT also drops it, as "noticeable overhead for no performance improvement" (Warner et al. 2024, §2.2.2). This is the paper's claim that did not hold up. The toy on this page does show an NSP gain, in two pretraining seeds, but for a reason its data builds in (Run a toy BERT).
  • Single runs, no error bars, choices made on dev. No table gives a seed count or a spread. The learning rate is picked on dev, and for BERT-Large "several random restarts" are run and the best on dev kept, because fine-tuning "was sometimes unstable on small datasets" (§4.1); the ablations of Tables 5 and 8 are then reported on that same dev set, so they are best-of-several, optimistic numbers. Tables 6 and 7 do better (means of 5 restarts) but still print no spread. The instability is real: later work found that "distinct random seeds can lead to substantially different results" for BERT on GLUE, even with identical hyperparameters (Dodge et al. 2020). Beyond the paper.
  • Not like for like against GPT, and the authors say so. BERT has four times GPT's data (3.3 billion words against 0.8), four times its batch, special tokens learned in pretraining and a per-task learning rate (A.4). They state all four themselves and build the left-to-right ablation to isolate the objective, which counts in their favour; but that ablation is BERT's own recipe made left to right, not GPT rerun, so the GLUE gain over GPT mixes the objective with the data and the recipe.
Three smaller points: margins inside the noise, "above human", small disagreements with itself
  • Margins inside the noise. The masking ablation (Table 8) spans 0.8 MNLI points across six mixes, against 0.52 for the standard error of one difference: it cannot show that 80/10/10 matters for fine-tuning, and the paper only claims it is "surprisingly robust" (fair). "Roughly at expert-human level" on SWAG compares 86.3 with 85.0 from 100 samples (Table 4), whose own standard error is about 3.6 points.
  • "Above human" on SQuAD v1.1 means above one annotator: human performance is scored by treating "the second answer to each question as the human prediction" against the others (Rajpurkar et al. 2016, §6.2), and BERT's 93.2 is an ensemble of 7 with extra TriviaQA data (Table 2).
  • Small disagreements with itself. Figure 5, read from its own coordinates, has the left-to-right model ahead at 30k and 50k steps, where the text says the masked LM outperforms it "almost immediately"; the 500k to 1M MNLI gain reads 0.8, not "almost 1.0%"; BERT-Large recounts to 335M parameters, not 340M (see Ablations and Model and input). None changes a conclusion.
Verdict
Believe the central claim without reservation: a deep encoder pretrained with a masked LM beats the same model trained left to right, by margins many standard errors wide on hidden test sets, and every later encoder confirmed it. Treat next sentence prediction as unproven (one run, one task outside the noise, reversed by RoBERTa), and the dev-set ablations as single, dev-selected runs without error bars.

Why it matters (beyond the paper)

BERT ended the era of task-specific NLP architectures: after it the default recipe became "pretrain a big Transformer, fine-tune per task", and masked prediction became the canonical self-supervised objective for encoders. A family of descendants followed: RoBERTa (the same model "significantly undertrained"; trained longer on 160GB, without NSP, with dynamic masking), ALBERT, ELECTRA, DistilBERT, DeBERTa and the multilingual XLM-R. The idea leaked beyond text: masked-prediction pretraining underpins vision methods such as BEiT and MAE, and pooled [CLS]-style representations underpin embedding models (Sentence-BERT). It also cemented the GLUE and SQuAD leaderboard culture, and Table 6 was an early clean demonstration that scaling model size keeps paying even on small downstream sets.

Encoders never went away where one cheap forward pass must produce a representation or a label rather than text: embeddings and retrieval (Embedding models), rerankers and late interaction (Rerankers and late interaction), classification and NER. How the encoder, decoder and encoder-decoder families compare today is on Families and objectives.

The encoder lineage, as of 2 October 2026 (ModernBERT, Ettin)

Decoders won generation, but encoder-only models never went away where one cheap forward pass must produce a representation rather than text: BERT descendants dominate embedding and retrieval stacks (bi-encoders for vector search such as DPR, cross-encoder rerankers such as monoBERT, late interaction in ColBERT), plus classification, moderation and NER at production scale. The recipe was refreshed by ModernBERT (Answer.AI, LightOn and others, December 2024: RoPE, GeGLU, alternating local and global attention, unpadding, 8,192-token context, 2 trillion training tokens; stepped through in Then and now) and the Ettin suite (Johns Hopkins and LightOn, 2025), which trains paired encoders and decoders from 17M to 1B parameters with one recipe and finds, like earlier work, that encoders excel at classification and retrieval and decoders at generation; a 400M encoder beats a 1B decoder continued with MLM on MNLI (Weller et al. 2025). For an AI engineer today, BERT-family models are what you reach for when the task is "represent or label text" rather than "write text".

Connections

  • Attention Is All You Need (2017): BERT is the Transformer encoder stack, transplanted to transfer learning.
  • Seq vs Seq (Ettin) (2025): a modern controlled comparison of the encoder (BERT) and decoder (GPT) lineages using the ModernBERT recipe.
  • GPT-3 (2020): the rival unidirectional lineage; GPT-3 replaced fine-tuning with in-context learning, ending BERT-style per-task heads for generation tasks.
  • RAG (2020): its dense retriever (DPR) is a pair of BERT encoders; retrieval and embeddings are BERT's main living habitat.
  • RoFormer (RoPE) (2021): RoPE replaced BERT's learned absolute positions in modern encoders (ModernBERT) as well as decoders.
  • Also: T5 (masked spans in an encoder-decoder), Bitune (bidirectional attention inside a decoder), ViT (the encoder and a class token on image patches).
  • Topics: Topic: llm-training-and-post-training (pretraining objectives, transfer learning), Topic: rag-and-retrieval (embeddings, rerankers), Topic: ml-fundamentals (sequence-model history).