BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
Summary (Overview)
- Bidirectional Pre-training: Introduces BERT (Bidirectional Encoder Representations from Transformers), a model pre-trained using a novel "masked language model" (MLM) objective. Unlike previous models like OpenAI GPT, BERT is designed to pre-train deep bidirectional representations by conditioning on both left and right context in all layers.
- Fine-tuning Simplicity: Demonstrates that the pre-trained BERT model can be fine-tuned with just one additional output layer to create state-of-the-art models for a wide range of tasks (sentence-level and token-level) without substantial task-specific architectural modifications.
- State-of-the-Art Performance: Obtains new state-of-the-art results on eleven natural language processing tasks, including pushing the GLUE benchmark score to 80.5% (7.7% point absolute improvement) and SQuAD v1.1 Test F1 to 93.2.
- Model Scaling Benefits: Shows that increasing model size (to 110M and 340M parameters) leads to significant accuracy improvements even on small downstream tasks, provided the model is sufficiently pre-trained.
Introduction and Theoretical Foundation
Pre-training language models on unlabeled text has proven effective for improving many NLP tasks. Existing strategies are either feature-based (e.g., ELMo, which integrates pre-trained representations as task-specific features) or fine-tuning-based (e.g., OpenAI GPT, which minimally adapts all pre-trained parameters for downstream tasks). A key limitation of these approaches, especially for fine-tuning, is their reliance on unidirectional language models (left-to-right or right-to-left). This restricts the model's ability to incorporate context from both directions, which is suboptimal for sentence-level tasks and harmful for token-level tasks like question answering.
BERT addresses this by enabling deep bidirectional pre-training. The core innovation is the use of a Masked Language Model (MLM) objective, inspired by the Cloze task. By randomly masking tokens in the input and predicting them using their full context, BERT learns representations that fuse left and right context. Additionally, BERT uses a Next Sentence Prediction (NSP) task to jointly pre-train understanding of relationships between sentences, which is crucial for tasks like QA and NLI.
Methodology
Model Architecture
BERT's architecture is a multi-layer bidirectional Transformer encoder. Two primary model sizes are used:
- BERT<sub>BASE</sub>: (layers), (hidden size), (attention heads), Total Parameters = 110M.
- BERT<sub>LARGE</sub>: , , , Total Parameters = 340M.
Input/Output Representations
The input representation is designed to handle both single sentences and sentence pairs (e.g., <Question, Answer>).
- Uses WordPiece embeddings with a 30,000 token vocabulary.
- The first token is always the special
[CLS]token, whose final hidden state () is used for classification tasks. - Sentence pairs are separated by a special
[SEP]token. - A learned segment embedding is added to each token to indicate whether it belongs to sentence A or B.
- The input representation for a token is the sum of its token, segment, and position embeddings (see Figure 2).
Pre-training Tasks
BERT is pre-trained on two unsupervised tasks using a combination of the BooksCorpus (800M words) and English Wikipedia (2,500M words).
-
Masked LM (MLM): 15% of all WordPiece tokens in each sequence are masked at random. For a masked position :
- 80% of the time, replace with
[MASK]. - 10% of the time, replace with a random token.
- 10% of the time, keep the original token. The final hidden vector is used to predict the original token with cross-entropy loss.
- 80% of the time, replace with
-
Next Sentence Prediction (NSP): For a given sentence pair (A, B), 50% of the time B is the actual next sentence (
IsNext), and 50% it is a random sentence from the corpus (NotNext). The[CLS]token representation is used for this binary classification.
Fine-tuning Procedure
Fine-tuning is straightforward. For each downstream task, BERT is initialized with pre-trained parameters, and task-specific inputs/outputs are plugged in. All parameters are fine-tuned end-to-end.
- Classification tasks: Use the
[CLS]representation . - Token-level tasks (e.g., QA, NER): Use the token representations .
- Fine-tuning is computationally inexpensive (e.g., ~1 hour on a Cloud TPU).
Empirical Validation / Results
GLUE Benchmark Results
BERT significantly outperforms previous state-of-the-art models across all tasks in the GLUE benchmark.
Table 1: GLUE Test Results
| System | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
|---|---|---|---|---|---|---|---|---|---|
| Pre-OpenAI SOTA | 80.6/80.1 | 66.1 | 82.3 | 93.2 | 35.0 | 81.0 | 86.0 | 61.7 | 74.0 |
| OpenAI GPT | 82.1/81.4 | 70.3 | 87.4 | 91.3 | 45.4 | 80.0 | 82.3 | 56.0 | 75.1 |
| BERT<sub>BASE</sub> | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
| BERT<sub>LARGE</sub> | 86.7/85.9 | 72.1 | 92.7 | 94.9 | 60.5 | 86.5 | 89.3 | 70.1 | 82.1 |
BERT<sub>LARGE</sub> obtains a GLUE leaderboard score of 80.5, a 7.7 point absolute improvement over the previous best.
SQuAD Question Answering
BERT achieves top results on both SQuAD v1.1 and the more challenging v2.0, which includes unanswerable questions.
Table 2: SQuAD 1.1 Results
| System | Test EM | Test F1 |
|---|---|---|
| #1 Leaderboard Ensemble (nlnet) | 86.0 | 91.7 |
| BERT<sub>LARGE</sub> (Ensemble+TriviaQA) | 87.4 | 93.2 |
Table 3: SQuAD 2.0 Results
| System | Test EM | Test F1 |
|---|---|---|
| #1 Leaderboard Single (MIR-MRC) | 74.8 | 78.0 |
| BERT<sub>LARGE</sub> (Single) | 80.0 | 83.1 |
For SQuAD v2.0, a simple extension to the v1.1 model (treating no-answer as a [CLS] token span) yields a +5.1 F1 improvement over the prior best system.
SWAG Commonsense Inference
BERT*<sub>LARGE</sub>* achieves 86.3% accuracy on the SWAG dataset, outperforming the baseline ESIM+ELMo by +27.1% and OpenAI GPT by +8.3%.
Theoretical and Practical Implications
Ablation Studies on Pre-training Tasks
Ablation studies confirm the importance of both the MLM and NSP objectives.
Table 5: Ablation over Pre-training Tasks (BERT<sub>BASE</sub> Architecture)
| Model | MNLI-m (Acc) | QNLI (Acc) | MRPC (Acc) | SQuAD (F1) |
|---|---|---|---|---|
| BERT<sub>BASE</sub> (Full) | 84.4 | 88.4 | 86.7 | 88.5 |
| No NSP | 83.9 | 84.9 | 86.5 | 87.9 |
| LTR & No NSP (like GPT) | 82.1 | 84.3 | 77.5 | 77.8 |
Key Findings:
- Removing NSP hurts performance on QNLI, MNLI, and SQuAD.
- The bidirectional MLM objective (
No NSP) vastly outperforms the left-to-right (LTR) objective (LTR & No NSP), especially on MRPC and SQuAD. - Adding a BiLSTM on top of the LTR model does not recover the performance gap, demonstrating the superiority of deep bidirectional pre-training.
Effect of Model Size
Larger models lead to consistent improvements across tasks of all sizes.
Table 6: Ablation over BERT Model Size
| #L | #H | #A | LM (ppl) | MNLI-m (Acc) | MRPC (Acc) | SST-2 (Acc) |
|---|---|---|---|---|---|---|
| 12 | 768 | 12 | 3.99 | 84.4 | 86.7 | 92.9 |
| 24 | 1024 | 16 | 3.23 | 86.6 | 87.8 | 93.7 |
This demonstrates that scaling to extreme model sizes (340M parameters) yields large gains even on small-scale tasks, provided the model is sufficiently pre-trained.
Feature-based vs. Fine-tuning Approach
BERT is also effective in a feature-based setting, where its activations are used as fixed features.
Table 7: CoNLL-2003 NER Results (F1)
| Approach | System | Dev F1 | Test F1 |
|---|---|---|---|
| Feature-based | Concat Last Four Hidden Layers | 96.1 | - |
| Fine-tuning | BERT<sub>LARGE</sub> | 96.6 | 92.8 |
Concatenating token representations from the top four hidden layers performs nearly as well as fine-tuning the entire model (within 0.3 F1), validating BERT's utility for feature-based approaches.
Conclusion
BERT demonstrates that deep bidirectional pre-training of language representations is a powerful and generalizable approach. By using the MLM and NSP objectives, BERT overcomes the unidirectionality constraint of previous models. The resulting model, when fine-tuned, establishes new state-of-the-art results on a broad suite of sentence-level and token-level NLP tasks with minimal architectural changes. The findings highlight the importance of both the pre-training objectives and model scale, paving the way for more powerful and sample-efficient transfer learning in NLP.