BERT: Why Deep Bidirectional Masked Pretraining Made Fine-Tuning a General NLP Recipe
Bert: Pre-training of deep bidirectional transformers for language understanding
BERT is a language representation model that pre-trains deep bidirectional Transformers using masked language modeling and next sentence prediction on unlabeled text, then fine-tunes a single architecture for many NLP tasks. The paper reports state-of-the-art results on eleven tasks, including a GLUE score of 80.5 percent and SQuAD v1.1 Test F1 of 93.2.
Core Overview
BERT's central claim is that the most important missing ingredient in earlier language representation pretraining was not another architecture trick, but a pretraining objective that forces a deep bidirectional Transformer to build token representations from both sides at every layer. The paper achieves this by masking 15 percent of WordPiece tokens and asking the model to recover the original vocabulary IDs, while also adding a simple next sentence prediction task that teaches the model to use paired inputs. The result is a single encoder that can be fine-tuned for sentence classification, natural language inference, question answering, named entity recognition, and commonsense reasoning with only minimal task output layers. The empirical payload is unusually broad: Table 1 reports BERTLARGE reaching an average GLUE score of 82.1 under the paper's WNLI-excluded metric and an official leaderboard score of 80.5, while Table 2 and Table 3 push SQuAD v1.1 Test F1 to 93.2 and SQuAD v2.0 Test F1 to 83.1.
This paper sits at a historical inflection point rather than as a small incremental benchmark update. Before BERT, the two dominant transfer strategies were the feature-based contextual embedding model ELMo and the fine-tuning autoregressive model OpenAI GPT. Figure 3 makes the distinction concrete: BERT is the only one of the three whose representations are jointly conditioned on both left and right context in all layers, and it is also a fine-tuning model rather than a feature extractor. That combination gives BERT a general recipe: pretrain a massive bidirectional encoder on unlabeled text, then attach almost no task machinery and adapt all parameters. The paper's contribution is therefore conceptual and architectural at the same time.
Problem and Motivation
The starting problem is that standard conditional language models are unidirectional by construction. If one tries to make a Transformer fully bidirectional while predicting every token given its context, the target token leaks into its own input and the model can trivially copy it. This is the mechanism that makes ordinary left-to-right or right-to-left language modeling the natural choice for autoregressive pretraining. OpenAI GPT accepted this constraint and used a left-to-right Transformer where every token attends only to previous tokens. ELMo avoided the same problem by concatenating independently trained left-to-right and right-to-left LSTM representations, but that concatenation remains shallow: each token's left and right contexts are learned separately and merged at the input, not fused inside every encoder layer.
For sentence-level tasks, a shallow asymmetry can still be useful. OpenAI GPT was strong on GLUE because many tasks can be solved from a single aggregate sentence representation built from left-to-right context. The harder failure mode appears in token-level tasks such as question answering. Section 5.1 states directly that a left-to-right model performs poorly on SQuAD because token-level hidden states have no right-side context. In an extractive question answering span, the word at the beginning of the answer needs evidence from the following words; the word at the end needs evidence from the preceding words; and both need access to the question. A representation that never sees future text is structurally handicapped before fine-tuning begins.
BERT's authors turn this limitation into a design insight. Instead of asking the model to generate every next token, ask it to recover only a corrupted subset. A model that must reconstruct a masked token from its surrounding text has no reason not to attend to both sides, and the bidirectionality can be repeated in every Transformer layer. This is not just engineering intuition. The paper supports it with controlled ablations in Table 5, where the same data, fine-tuning scheme, and hyperparameters are used to compare masked bidirectional pretraining with left-to-right pretraining. The result is not a minor ranking difference: removing bidirectional conditioning causes severe degradation on MRPC and SQuAD, which is exactly the set of tasks where token-level future context matters.
Core Chapter: The Bidirectional Masked Transformer Recipe
1. The Baseline Constraint and Why It Blocks Deep Bidirectionality
The pre-BERT landscape can be understood as two compromises around a single mathematical obstruction: a generative language model needs a direction. A left-to-right model predicts from through , and a right-to-left model predicts a token from the suffix. Both are valid supervised objectives over unlabeled text, but both prevent the representation at from containing the future text and beyond in the same encoder pass. ELMo's concatenated bidirectional language models solve part of the symptom by giving downstream systems both past and future views, yet the fusion happens at the representation level, not inside a deep conditional model. GPT solves the opposite part by using a Transformer encoder and allowing full fine-tuning, but its self-attention is constrained by an autoregressive mask, so the same deep bidirectional fusion is absent.
This is where BERT's architecture choice becomes meaningful. The model is a multi-layer bidirectional Transformer encoder with two main variants: BERTBASE uses , , , and 110 million total parameters, while BERTLARGE uses , , , and 340 million parameters. The paper intentionally makes BERTBASE comparable in size to OpenAI GPT, which isolates the effect of the pretraining objective rather than confounding it with a much larger model. The critical asymmetry between BERT and GPT is therefore not parameter count but attention masking: BERT uses bidirectional self-attention, while GPT uses constrained self-attention where each token sees only its left context.

2. Masked Language Modeling, Next Sentence Prediction, and a Unified Fine-Tuning Interface
BERT's first pretraining task is the masked language model. The generator selects 15 percent of token positions in each sequence. When the -th token is selected, it is replaced by the special MASK token 80 percent of the time, by a random token 10 percent of the time, or left unchanged 10 percent of the time. The model then uses the final hidden vector at that position to predict the original token through a softmax over the vocabulary. This is not denoising the whole sequence: the paper predicts only the corrupted positions. The random replacement and unchanged-token strategies mitigate the fact that the MASK token never appears during fine-tuning, while the 15 percent rate creates enough corrupted targets to force the encoder to keep a context-sensitive representation of every input token.
The paper does not display a full formal equation for the masked language modeling loss, but it describes the mechanism clearly: the final hidden vectors corresponding to masked positions are fed into an output softmax over the vocabulary and trained with cross entropy. The deeper point is that the objective changes which attention pattern is trainable. Once the model is not required to predict every token autoregressively, it can learn from bidirectional attention without trivially seeing the target. The cost is a distributional mismatch: pretraining sees corrupted tokens, fine-tuning sees clean tokens. Section 3.1 addresses this directly with the 80, 10, 10 masking policy, and Appendix C.2 tests the choice in Table 8.
BERT's second task is next sentence prediction. For each pretraining example, two contiguous text spans are sampled; 50 percent of the time sentence B is the actual next sentence and 50 percent of the time it is random. The final hidden vector corresponding to the first CLS token is used to classify the pair as IsNext or NotNext. This task matters because many downstream tasks are not single-sentence classification but relationship prediction: question and passage, premise and hypothesis, sentence and paraphrase. By pretraining on sentence pairs, BERT learns an interface for concatenating two sequences with SEP separators and segment embeddings, which is then reused across GLUE, SQuAD, and SWAG.

For classification tasks, the paper uses the final hidden state of the CLS token as the aggregate sequence representation and introduces only a task classifier:
where is the final hidden vector for the first input token, contains the new classification weights, and is the number of labels. The formula's role is not to introduce a complicated loss but to define the minimal interface between a pretrained encoder and a supervised task. Compared with task-specific architectures that add attention layers, encoders, decoders, or span matching modules, this objective treats the downstream task as a linear head over a learned representation. If were removed, the model could only produce hidden vectors without task decision values; if the entire encoder were retrained from scratch, the small number of downstream parameters would not suffice for many tasks. The point is that most of the expressive burden is transferred from task architecture to pretraining.
The same minimal-interface principle appears in extractive question answering. For SQuAD, BERT encodes the question as sentence A and the passage as sentence B. Fine-tuning adds only a start vector and an end vector . The probability that token is the answer start is
where is the final hidden vector for input token , and the denominator sums over candidate tokens in the paragraph. This expression shows why BERT's input representation is so tightly coupled to its transfer strategy. The task does not require a new matching network; it asks whether a learned span boundary is encoded in each token's hidden vector. The softmax over turns dot products into a relative position distribution, and the same mechanism predicts the end position. In a left-to-right model, however, for an early answer token lacks right-side passage context, which is why Section 5.1's ablation reports a dramatic SQuAD drop when BERT is changed to left-to-right pretraining.
The candidate span score is then defined by combining start and end evidence:
where enforces that the end position does not precede the start position. The score factorizes a span into two independent boundary decisions. This is both powerful and limited: it is simple, differentiable, and can be reused across answer extraction tasks, but it cannot explicitly represent complex answer spans or generate new text. In the BERT paper this limitation is acceptable because SQuAD is extractive. The formula also clarifies what fine-tuning learns: not a whole answer parser, but two vectors that calibrate the pretrained token embeddings toward start and end semantics.
SQuAD v2.0 adds unanswerable questions by treating the null answer as a span at the CLS token:
where is the CLS hidden vector. A non-null span is predicted only if the best valid span score exceeds this null score by a threshold :
with selected on the development set to maximize F1. This small extension is a good test of the paper's unified architecture claim. The same hidden states used to encode token positions are reused to encode the absence of an answer. If BERT's representations were only useful for sentence-level classification, this trick would be less natural; because the model already fuses question, passage, segment identity, and position information, the CLS vector can serve as an "outside-the-passage" anchor.

The input representation itself is as important as the pretraining objective. BERT uses WordPiece embeddings with a 30,000 token vocabulary. Every token's input embedding is the sum of a token embedding, a segment embedding, and a positional embedding. Sentence pairs are separated by SEP, and segment embeddings mark whether a token belongs to sentence A or sentence B. This gives the Transformer a single unambiguous sequence format for single-sentence classification, two-sentence entailment, question-passage QA, and degenerate text-empty pairs. The unified input format lets pretraining and fine-tuning share the same attention mechanism, which in turn lets the paper argue that task-specific architecture is often unnecessary.
3. Design Rationale, Ablations, and the Price of Bidirectionality
The paper's key design rationale is tested in Section 5.1. Table 5 compares BERTBASE with three variants trained on the same data and fine-tuned with the same scheme: No NSP, a model trained without next sentence prediction; LTR and No NSP, a left-to-right masked-free baseline comparable to GPT; and plus BiLSTM, which adds a randomly initialized BiLSTM to the left-to-right model to strengthen the baseline. The results support the bidirectional hypothesis directly. BERTBASE scores 88.4 on QNLI, 84.4 on MNLI-m, 86.7 on MRPC, 92.7 on SST-2, and 88.5 on SQuAD F1. Removing NSP lowers QNLI to 84.9, a 3.5 point drop, and lowers MNLI-m by 0.5 and SQuAD by 0.6. More importantly, the LTR and No NSP model falls to 82.1 on MNLI-m, 84.3 on QNLI, 77.5 on MRPC, 92.1 on SST-2, and 77.8 on SQuAD. The SQuAD gap of 10.7 F1 points is the clearest signal that left-side-only hidden states cannot represent answer spans properly.
The paper acknowledges that one could add a BiLSTM after a left-to-right encoder, and Table 5 shows this improves SQuAD from 77.8 to 84.9. Yet it remains 3.6 F1 points below BERTBASE, while hurting some GLUE tasks. This is a useful boundary condition: post hoc context fusion cannot fully compensate for representations that were never trained with deep bidirectional access. The paper also contrasts BERT with ELMo-style concatenated bidirectional LMs and gives three reasons why a single deeply bidirectional model is preferable: it is cheaper than maintaining two full models, it is more intuitive for QA because the answer can condition on the question in a single encoder pass, and it is strictly more expressive than shallow concatenation because both contexts are available at every layer. This argument is not backed by a formal theorem, but it is empirically instantiated by the attention differences in Figure 3 and the controlled ablations in Table 5.
Table 6 addresses a different design question: does scale help downstream tasks, even tiny ones? As the number of layers and hidden size increases, language modeling perplexity falls from 5.84 at three layers to 3.23 at twenty-four layers, while MNLI-m accuracy rises from 77.9 to 86.6, MRPC accuracy rises from 79.8 to 87.8, and SST-2 accuracy rises from 88.4 to 93.7. The notable claim is not that bigger models have lower perplexity, which is familiar, but that bigger pretrained models help small datasets such as MRPC with only about 3,600 labeled examples when all parameters are fine-tuned. Section 5.2 hypothesizes that fine-tuning allows downstream models to exploit expressive pretrained representations in a way that feature-based approaches could not. That claim is supported by Table 7, where feature-based BERT is strong but generally below full fine-tuning.
Pretraining cost is nontrivial. Appendix A.2 states that BERT uses a batch size of 256 sequences with each sequence up to 512 tokens, meaning 128,000 tokens per batch, trained for 1,000,000 steps for about 40 epochs over a 3.3 billion word corpus. BERTBASE was trained on 4 Cloud TPUs and BERTLARGE on 16 Cloud TPUs, each taking 4 days. The fine-tuning side, however, is cheap: Section 3.2 says all paper results can be replicated in at most 1 hour on a single Cloud TPU or a few hours on a GPU. This asymmetry is central to the method's practical value: expensive one-time representation learning amortizes into many inexpensive task adaptations.
Experiments and Evidence
The strongest evidence for BERT as a general transfer model is Table 1. The table reports GLUE test results under the paper's average metric excluding WNLI. BERTBASE reaches an average of 79.6, while BERTLARGE reaches 82.1. OpenAI GPT's average is 75.1, and the pre-OpenAI state of the art is 74.0. The gains are distributed, not concentrated in one task: MNLI-m and MNLI-mm rise from GPT's 82.1 and 81.4 to 86.7 and 85.9, QNLI rises from 87.4 to 92.7, and CoLA rises from 45.4 to 60.5. The official leaderboard numbers cited in the introduction make the same point with the benchmark's own scoring: BERTLARGE obtains 80.5, compared with 72.8 for OpenAI GPT at the time of writing.
Table 1: GLUE test results, scored by the evaluation server, excluding WNLI in the average column
| Method | MNLI match | MNLI mismatch | QQP F1 | QNLI Acc | SST-2 Acc | CoLA | STS-B | MRPC F1 | RTE Acc | Average |
|---|---|---|---|---|---|---|---|---|---|---|
| Pre-OpenAI SOTA | 80.6 | 80.1 | 66.1 | 82.3 | 93.2 | 35.0 | 81.0 | 86.0 | 61.7 | 74.0 |
| BiLSTM plus ELMo plus Attention | 76.4 | 76.1 | 64.8 | 79.8 | 90.4 | 36.0 | 73.3 | 84.9 | 56.8 | 71.0 |
| OpenAI GPT | 82.1 | 81.4 | 70.3 | 87.4 | 91.3 | 45.4 | 80.0 | 82.3 | 56.0 | 75.1 |
| BERTBASE | 84.6 | 83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
| BERTLARGE | 86.7 | 85.9 | 72.1 | 92.7 | 94.9 | 60.5 | 86.5 | 89.3 | 70.1 | 82.1 |
The reading of Table 1 is that BERT's improvements are not solely due to the large model. BERTBASE is intentionally close in size to GPT, yet it beats GPT on every listed task. This isolates the contribution of the objective and input representation rather than raw scale. BERTLARGE then compounds those gains, and the paper notes that larger models help especially on low-resource tasks. Still, the GLUE evidence should be read with the authors' own protocol in mind: for GLUE, BERT uses batch size 32, 3 epochs, task-specific learning rates among 5e-5, 4e-5, 3e-5, and 2e-5, and for BERTLARGE it sometimes uses random restarts selected on the dev set. These choices favor strong final numbers, but they are not exotic; they are the same kind of hyperparameter tuning common in fine-tuning.
Question answering provides the strongest support for the bidirectional argument. Table 2 shows SQuAD v1.1 results: the BERTLARGE ensemble with TriviaQA augmentation reaches Test EM 87.4 and Test F1 93.2. The top published system R.M. Reader ensemble is at Test F1 88.5, while the human test score is 91.2. Section 4.2 says the best performing system outperforms the top leaderboard system by +1.5 F1 in ensembling and that a single system still outperforms the top ensemble system. This matters because SQuAD cannot be solved adequately by a model that ignores the passage to the right of the candidate answer. The QA equations also show that only start and end vectors are added, reinforcing the claim that the representation already encodes answer boundaries.
For SQuAD v2.0, Table 3 gives BERTLARGE Test EM 80.0 and Test F1 83.1, compared with the top single system MIR-MRC at Test F1 78.0 and the second single system nlnet at 77.1. The paper states a +5.1 F1 improvement over the previous best system. The human performance reported in that table is 89.5 Test F1, so the system still trails the human ceiling, but it clears prior model systems substantially. Table 4 then extends the pattern to SWAG: BERTLARGE reaches 86.3 test accuracy, versus 59.2 for the ESIM and ELMo baseline and 78.0 for OpenAI GPT. The paper describes these gaps as +27.1 and +8.3 respectively, which are among the most visible single-dataset improvements in the paper.
A second important piece of evidence is that BERT is not only a fine-tuning model. Table 7 compares BERT on CoNLL-2003 named entity recognition using full fine-tuning and feature-based methods. The full BERTLARGE model gets Test F1 92.8, while BERTBASE gets 92.4. The best feature-based variant concatenates the top four hidden layers and reaches Dev F1 96.1. The paper states that this is only 0.3 F1 behind fine-tuning the entire model when comparing with the corresponding BERTBASE development setting. This supports the claim that the learned contextual features are useful even when the pretrained parameters are frozen, but the full fine-tuning path is still generally stronger, especially on token-level sequence tagging.
Table 5: Ablation over pretraining tasks using the BERTBASE architecture
| Pretraining configuration | MNLI-m accuracy | QNLI accuracy | MRPC accuracy | SST-2 accuracy | SQuAD F1 |
|---|---|---|---|---|---|
| BERTBASE | 84.4 | 88.4 | 86.7 | 92.7 | 88.5 |
| No NSP | 83.9 | 84.9 | 86.5 | 92.6 | 87.9 |
| LTR and No NSP | 82.1 | 84.3 | 77.5 | 92.1 | 77.8 |
| LTR plus BiLSTM | 82.1 | 84.1 | 75.7 | 91.6 | 84.9 |
Table 5 is the paper's cleanest causal experiment. Because the same pretraining data, fine-tuning scheme, and hyperparameters are used, the comparison is not about training scale. The QNLI drop when NSP is removed shows that sentence-relationship pretraining matters for QA-derived inference tasks. The SQuAD collapse under left-to-right pretraining shows that bidirectional access is not a stylistic preference. The partial recovery from adding a BiLSTM shows that future context can help, but not as well as a model whose every layer learned to use future context.
The evidence quality is high but bounded by the era's data and task choices. BERT is pretrained on BooksCorpus and English Wikipedia, and most results are on English GLUE and SQuAD-like tasks. The SQuAD system uses TriviaQA fine-tuning for best leaderboard numbers, though Section 4.2 says removing that augmentation loses only 0.1 to 0.4 F1. BERTLARGE fine-tuning can be unstable on small datasets, and the authors use dev-selected random restarts, so some reported numbers are optimized through model selection rather than fixed hyperparameters. Appendix C.2 also shows that the exact masking policy matters mainly in the feature-based setting: for NER feature-based performance, the paper's 80, 10, 10 strategy reaches Dev F1 94.9, while using only MASK drops to 94.0. Fine-tuning is surprisingly robust, but the mismatch problem is real when parameters are frozen.
Deep Insights and Summary
The durable lesson from BERT is that transferable representations are shaped as much by the self-supervised task as by the architecture. A Transformer encoder can attend left and right, but a full generative language model cannot use that freedom without leaking the target. By turning pretraining into reconstruction of masked tokens plus sentence-pair discrimination, BERT makes bidirectional attention trainable at scale. The architecture then becomes a shared substrate for sequence tagging, classification, entailment, QA, and common-sense reasoning. Figure 1, Table 5, Table 2, and Table 1 together make a simple argument: deep bidirectionality plus end-to-end fine-tuning reduces the need for heavily engineered task-specific models.
The limitations are concrete. The masked language model introduces a train-time mismatch because MASK appears only in pretraining, and the 80, 10, 10 mitigation is heuristic, supported empirically but not theoretically proven. The next sentence prediction task is a coarse proxy for discourse and sentence-pair semantics; Section 5.1 shows it helps QNLI, but the gain on other tasks varies and later work would question its necessity. BERTLARGE's strongest numbers rely on dev-selected random restarts and sometimes auxiliary datasets such as TriviaQA. Finally, the model size study in Table 6 establishes that scale helps within this framework, but it does not establish whether the same scaling behavior holds across multilingual text, multimodal inputs, or longer contexts without architectural changes.
The future direction implied by this paper is clear but nontrivial: preserve the generality of a bidirectional encoder while reducing the mismatch between corrupted pretraining and clean adaptation, while making sentence-pair objectives more fine-grained and making scaling efficient for longer contexts. BERT showed that the pretraining objective, the attention mask, and the unified interface jointly determine whether a language model can become a broad platform. That was not merely a benchmark win; it was a change in what counted as the right way to prepare a neural language model for many downstream tasks.
