Paper Breakdowns  /  BERT
Paper 02~12 min readNAACL 2019worked math + runnable code
Paper Breakdown

BERT,
explained.

One year after the Transformer, a Google team asked a stubborn question: why should a model only read a sentence left to right? BERT let it read both directions at once — and by teaching a model to fill in the blanks across a billion words, it made "pre-train once, fine-tune anywhere" the default recipe for modern NLP.

01

The one-way problem

The Transformer had already shown that attention could replace recurrence. But the language models built on it still read like someone with a piece of paper covering the rest of the page: strictly left to right, one word at a time, predicting the next word from everything before it.

That one-way habit throws away half the clues. Take the word "bank" in "I went to the bank to deposit my" — you can't be sure it's a riverbank or a money bank until you read the word that comes after it. A left-to-right model, by design, never gets to peek forward. The meaning it builds is always half-blind.

02

The big idea: read both ways at once

BERT's bet was simple to state and awkward to pull off: let every word see the words on both sides of it, simultaneously. That's what the "B" stands for — Bidirectional Encoder Representations from Transformers.

The catch is a chicken-and-egg problem. If you train a model to predict the next word while also letting it look ahead, it can just read the answer — the future word it's supposed to guess is sitting right there. True bidirectional context and next-word prediction can't coexist. So BERT threw out next-word prediction entirely and invented a different game.

03

Masked language modeling: fill in the blank

Instead of predicting the next word, BERT plays fill-in-the-blank. Take a sentence, randomly hide about 15% of its words behind a [MASK] token, and train the model to recover what was hidden — using every other word, on both sides, as evidence. This is masked language modeling (MLM).

Masked language modeling
[CLS] the cat sat on the [MASK] → mat

Because the answer is now hidden rather than sitting one step ahead, the model is free to use the future as well as the past. To guess "mat," it leans on "cat," "sat," and "on" all at once. Do this across billions of words and the model is forced to learn deep, two-sided representations of meaning.

Worth knowing

A subtlety: the [MASK] token never appears at fine-tuning or inference time, which would create a mismatch. BERT hedges — of the 15% chosen words, 80% become [MASK], 10% are swapped for a random word, and 10% are left unchanged — so the model can't assume a masked slot is always literally [MASK].

04

Next-sentence prediction

Filling in words teaches BERT about individual sentences. But many real tasks — question answering, natural-language inference — hinge on the relationship between two sentences. So BERT added a second pre-training task: next-sentence prediction (NSP). Show the model two sentences and ask a yes/no question — did B actually follow A in the original text, or is it a random impostor pulled from somewhere else?

Half the training pairs are genuine neighbors, half are random. Learning to tell them apart nudges BERT toward understanding discourse and coherence, not just word-level patterns. (Later work — RoBERTa — showed NSP was largely unnecessary, but it was part of the original recipe.)

05

Tokens, [CLS], and [SEP]

BERT wraps its input in a few special tokens. Every sequence starts with [CLS] — a slot whose final vector becomes a summary of the whole input, perfect to hang a classifier on. Two sentences are divided by a [SEP] separator, and each token also carries a segment embedding marking whether it belongs to sentence A or B.

Words themselves are split into WordPiece sub-word units, so rare words like "tokenization" become "token" + "##ization" — a fixed 30,000-token vocabulary that never hits an unknown word. Each token's final embedding is the sum of three signals: what the word is, which segment it's in, and where it sits.

06

The recipe: pre-train once, fine-tune anywhere

This is BERT's real gift to the field. Pre-training — the expensive part — happens once: MLM plus NSP over BooksCorpus and English Wikipedia, days of compute on a big cluster. The result is a model that already understands language in general.

Then, for any specific task, you fine-tune: bolt a tiny task-specific layer onto the [CLS] output (or every token, for tagging), and train briefly on a small labeled dataset. Sentiment, question answering, named-entity recognition — same pre-trained body, different lightweight head, a few hours each. Teams that couldn't dream of training a language model from scratch could now reach state-of-the-art by fine-tuning BERT.

The shift

Before BERT, most NLP models were trained from scratch per task. After BERT, "download a pre-trained model and fine-tune it" became the default. That transfer-learning mindset is the through-line from BERT to every large model since.

07

110M and 340M, derived by hand

The two model sizes aren't arbitrary — they fall straight out of the architecture with the same napkin formula that sizes every Transformer (≈12·d² weights per layer, plus the embedding matrix):

BERT-base:  12·12·768² + 30522·768 + 512·768 ≈ 108.8M ≈ 110M ✓
BERT-large: 12·24·1024² + 30522·1024 + 512·1024 ≈ 333.8M ≈ 340M ✓

(30,522 is the WordPiece vocabulary; 512 the max positions.) The masking recipe is just as concrete. For every training sequence, 15% of tokens are selected for prediction — but only 80% of those become [MASK]; 10% are swapped for a random word and 10% left untouched:

Per 1,000 tokensCountWhy
Selected for prediction (15%)150enough signal per pass without destroying context
→ replaced with [MASK] (80%)120the core fill-in-the-blank task
→ swapped for a random token (10%)15model can't trust that visible words are real — must model everything
→ left unchanged (10%)15[MASK] never appears at fine-tune time; this closes the mismatch

That 80/10/10 hedge looks fussy until you see the failure it prevents: a model trained only on literal [MASK] slots learns "the interesting positions are the masked ones" — and at fine-tune time there are no masks, so the signal vanishes. The hedge forces every position to carry a real representation.

RUN IT YOURSELF

The masking recipe & the napkin math

BERT's exact 15% / 80-10-10 masking procedure on real text, plus the parameter derivation for both model sizes — running in your browser through WebAssembly. Run it, check the proportions land where the paper says, then change MASK_RATE to 30% and think about what that does to the training signal (this exact question produced several follow-up papers).

CPython · WebAssembly
08

The real results

BERT didn't just edge ahead — it swept. On the GLUE benchmark of nine language-understanding tasks, BERT-large pushed the score to 80.5%, a 7.7-point jump over the previous best. On SQuAD v1.1 question answering it reached 93.2 F1 — past the 91.2 human baseline — and it set new records on eleven tasks at once.

ModelGLUE scoreNote
Pre-BERT best (ELMo-era)72.8previous state of the art
OpenAI GPT (left-to-right)75.1one-directional
BERT-base (110M params)79.612 layers
BERT-large (340M params)80.524 layers

The two sizes tell their own story: BERT-large, with 24 Transformer-encoder layers and 340M parameters, beat BERT-base everywhere — an early, clear signal that with the right pre-training, bigger keeps helping.

09

Why it still matters

BERT is the encoder half of the family tree. Where GPT took the Transformer's decoder and ran toward generation, BERT took the encoder and ran toward understanding — and for years, if you were classifying, retrieving, or extracting, you reached for BERT or one of its descendants (RoBERTa, DistilBERT, ELECTRA, DeBERTa). Its sentence embeddings still power a huge share of search and retrieval systems today.

More than any single benchmark, BERT's legacy is the recipe it normalized: pre-train a Transformer on oceans of unlabeled text, then fine-tune. That idea — not the specific masking trick — is what every model after it inherited.

Worth knowing

When you build semantic search or a RAG retriever, the embedding model turning your text into vectors is very often a BERT descendant. Understanding BERT is understanding the retrieval side of modern AI.

Frequently asked

Quick answers

What is BERT?

A 2018 Google model that pre-trains a Transformer encoder on massive unlabeled text, then fine-tunes per task. Its signature is reading text bidirectionally — both left and right context at once.

What is masked language modeling?

Hide ~15% of a sentence's words and train the model to predict them from the words on both sides. That forces deeply bidirectional understanding, unlike left-to-right prediction.

How is BERT different from GPT?

BERT is an encoder built for understanding (classification, QA, tagging), read bidirectionally and fine-tuned per task. GPT is a decoder built for generation, read left-to-right.

What does pre-train then fine-tune mean?

Learn general language once from huge unlabeled data (expensive), then cheaply adapt that model to each specific task with a small labeled dataset and a lightweight head.

Why does BERT still matter?

Its descendants power much of today's search, retrieval, and embedding — including RAG retrievers — and it normalized the pre-train-then-fine-tune recipe used by every large model since.

Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns

Cite this page

Reference it in your work, paper or an AI's context window.

APASingh, S. (2026). BERT. Vibe Engines. https://vibeengines.com/paper/bert
MLASingh, Saurabh. “BERT.” Vibe Engines, 2026, vibeengines.com/paper/bert.
BibTeX
@online{vibeengines-bert,
  author       = {Singh, Saurabh},
  title        = {BERT},
  year         = {2026},
  organization = {Vibe Engines},
  url          = {https://vibeengines.com/paper/bert}
}