GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
NAACL 2019

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

Select 15% of tokens for prediction, train a Transformer encoder with context from both sides, then fine-tune for each task. BERT set records on eleven language benchmarks.

Breakdown by FDE Interviews · 10 min read · Updated

About the original · 2018
AUTHORS
Devlin, Chang, Lee, Toutanova
FROM
Google AI Language
PUBLISHED
Oct 2018 · NAACL 2019
CITED BY
122,869Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 23% of this breakdown.

01

The paper in one minute

By 2018, pre-training a language model on unlabeled text and then adapting it to a task had proven itself. OpenAI's GPT trained a Transformer left to right and fine-tuned it; ELMo trained separate left-to-right and right-to-left models and fed their features into task-specific networks. Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova at Google argued both were limited by unidirectionality: a left-to-right model's representation of a word cannot use the words that follow it.

You cannot train an ordinary language model in both directions at once, because each word would indirectly see itself. BERT (Bidirectional Encoder Representations from Transformers) avoids this with a masked language model: pick 15% of the tokens in a sequence, hide them, and train the model to predict the originals from everything else. To reduce the mismatch with fine-tuning, where no tokens are hidden, a chosen token is replaced with [MASK] 80% of the time, a random token 10% of the time, and left unchanged 10% of the time. A second task, next sentence prediction (NSP), gives the model two text spans and asks whether the second really followed the first (half the time) or was drawn at random.

Inputs are WordPiece tokens with a [CLS] token at the start and [SEP] between and after the two spans; each position adds a token embedding, a segment embedding (A or B) and a position embedding. BERT-Base has 12 layers and 110M parameters, matched to GPT's size; BERT-Large has 24 layers and 340M. Both were pre-trained on BooksCorpus and English Wikipedia (3.3 billion words).

For a task, add one output layer and fine-tune every weight: a classifier on the [CLS] vector for sentence or pair classification, or start and end vectors over token outputs for question answering. With that recipe BERT set new best results on eleven tasks.

THE IDEA, VISUALLY
ONE INPUT SEQUENCE (FIGURE 2) [CLS] my dog is cute [SEP] he likes play ##ing [SEP] + token WordPiece, 30,000 vocab + segment A A A A A A B B B B B + position 0 1 2 3 ... 10 PRE-TRAINING: TWO TASKS AT ONCE Masked LM predict 15% of tokens from both sides: 80% [MASK], 10% random, 10% unchanged Next sentence is B the real next sentence? 50/50 real or random; uses the [CLS] vector BooksCorpus 800M words + Wikipedia 2,500M words; 1M steps FINE-TUNING: ONE NEW LAYER Classify softmax(C·Wᵀ) on the [CLS] vector Answer span start vector S, end E; best span maximizes S·Tᵢ + E·Tⱼ Base: 12 layers, 768 hidden, 110M; Large: 24, 1024, 340M All weights are updated for each task. GLUE TEST AVERAGE, EXCLUDING WNLI (TABLE 1) BiLSTM+ELMo+Attn 71.0 Pre-OpenAI best 74.0 OpenAI GPT 75.1 BERT-Base 79.6 BERT-Large 82.1 axis starts at 60; official GLUE score 80.5 includes WNLI PRE-TRAINING ABLATION, BERT-BASE DEV (TABLE 5) MNLI QNLI SQuAD F1 BERT-Base 84.4 88.4 88.5 no NSP 83.9 84.9 87.9 left-to-right, no NSP 82.1 84.3 77.8 + BiLSTM on top 82.1 84.1 84.9 MODEL SIZE, DEV, 5 RESTARTS (TABLE 6) 3 layers, H 768 MNLI 77.9 6 layers, H 768 MNLI 81.9 12 layers, H 768 MNLI 84.4 12 layers, H 1024 MNLI 85.7 24 layers, H 1024 MNLI 86.6 axis starts at 70
BERT trains a Transformer encoder to recover hidden words from both directions and to tell whether two passages are consecutive, then fine-tunes all weights with one output layer per task. Bidirectionality mattered most in its ablations; next-sentence prediction moved most tasks by less than a point.
Research notes: the problem, approach and results
82.1 vs 75.1

GLUE test average excluding WNLI, BERT-Large against OpenAI GPT

77.8 → 88.5

SQuAD v1.1 dev F1, left-to-right model against masked LM, same data and size (Table 5)

15%

share of tokens predicted per sequence in pre-training, against every token for a left-to-right model

THE PROBLEM

Pre-trained language models of 2018 were left-to-right (GPT) or glued together separate left-to-right and right-to-left models (ELMo). A left-to-right model cannot use the words after a position, which hurts tasks like question answering where the answer depends on context on both sides.

THE IDEA

Train a Transformer encoder with a masked language model: hide 15% of tokens and predict them from the full context. Add a next-sentence prediction task for sentence pairs. Fine-tune the whole model per task with one new output layer, using the first token's vector for classification and start/end vectors for answer spans.

THE RESULT

BERT-Large (340M parameters) set new best results on eleven tasks: GLUE score 80.5 (+7.7), MultiNLI 86.7%, SQuAD v1.1 test F1 93.2 and SQuAD v2.0 test F1 83.1 (+5.1). Ablations showed the bidirectional objective accounted for most of the gain over a GPT-style model.

02

Why it matters to an FDE

Generative models get the attention, but BERT-style encoders still do much of the quiet work in production: embedding models for search, rerankers, classifiers for routing and moderation, named-entity taggers.

Encoders are cheap and fast. A 110M-parameter encoder classifies or embeds text in milliseconds on a CPU. For high-volume routing, tagging or deduplication, it often beats calling a large model on cost and latency.

Fine-tuning needs little data. The paper's results include tasks with a few thousand labeled examples, fine-tuned in under an hour on one accelerator. A customer with 3,000 labeled tickets can train a solid classifier.

Know what the [CLS] vector is not. The authors note the vector is not a meaningful sentence representation without fine-tuning. Using raw BERT outputs as search embeddings works poorly; use a model trained for embeddings.

Small-data fine-tuning is unstable. The authors ran several random restarts for BERT-Large on small datasets and kept the best on the dev set. Budget for multiple runs and a held-out test set.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 99 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦1 results table
  • ?5 interview questions with answers
  1. 03Key takeaways

    Architecture, objectives, training data, results and the misreadings to avoid

    Free account
  2. 04How it works

    Input representation, both objectives, pre-training procedure and fine-tuning heads

    Premium
  3. 05The numbers that matter

    GLUE by task, SQuAD, the ablations, model size and pre-training length

    Premium
  4. 06Try it yourself

    Count the parameters, run the masking recipe, and redo the pre-training token arithmetic

    Premium
  5. 07Where it breaks

    Generation, input length, small-data instability, ablation noise and inconsistencies

    Premium
  6. 08Using it on a deployment

    Choosing and fine-tuning encoder models for a customer's text tasks

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →