IN THIS BREAKDOWN · 10 SECTIONS
You can read 23% of this breakdown.
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.
Research notes: the problem, approach and results
GLUE test average excluding WNLI, BERT-Large against OpenAI GPT
SQuAD v1.1 dev F1, left-to-right model against masked LM, same data and size (Table 5)
share of tokens predicted per sequence in pre-training, against every token for a left-to-right model
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.
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.
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.
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.
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
- ◇1 architecture diagram
- </>1 runnable code experiment
- ▦1 results table
- ?5 interview questions with answers
- 03Key takeaways
Architecture, objectives, training data, results and the misreadings to avoid
Free account - 04How it works
Input representation, both objectives, pre-training procedure and fine-tuning heads
Premium - 05The numbers that matter
GLUE by task, SQuAD, the ablations, model size and pre-training length
Premium - 06Try it yourself
Count the parameters, run the masking recipe, and redo the pre-training token arithmetic
Premium - 07Where it breaks
Generation, input length, small-data instability, ablation noise and inconsistencies
Premium - 08Using it on a deployment
Choosing and fine-tuning encoder models for a customer's text tasks
Premium - 09Interview angles
Five questions this paper prepares you for, with answer hints
Premium - 10Read next
Where to go from here on this site
Premium
