Subscribe
AI
6 min read

What Is Masked Language Modeling? The Fill-in-the-Blank Game Behind BERT

Masked language modeling trained BERT and still runs most embedding pipelines. How the fill-in-the-blank objective works, where it cracked within two years, and why only the autoregressive lineage survived the chatbot era.

What Is Masked Language Modeling? The Fill-in-the-Blank Game Behind BERT

Every chatbot you use predicts the next word. Most of the AI you use without noticing, from the embedding pipeline behind your company's search box to the classifier sorting support tickets, was trained a different way: it was taught to fill in blanks. That training objective is called masked language modeling, or MLM, and in 2018 it produced BERT, the model that briefly rewrote the rules of practical NLP.

This is an explainer of how MLM works, why Google's researchers designed it that way, what cracks showed up within a year, and why the generative side of the field abandoned it while the understanding side never did.

A test from a 1953 readability study

The name for the fill-in-the-blank exercise predates the machine learning by 65 years. In "Cloze Procedure: A New Tool for Measuring Readability" (Journalism Quarterly, 1953), Wilson L. Taylor proposed deleting every fifth or tenth word of a passage and asking readers to restore them. Guessing the missing words correctly, Taylor argued, demonstrated comprehension of the text. The method became a standard tool in reading research.

Masked language modeling is a cloze test run at industrial scale. Instead of students restoring words for a teacher's grade, a neural network restores millions of words per second to minimize a loss function, and the effort of getting them right is what shapes the model.

How MLM actually trains a model

BERT stands for Bidirectional Encoder Representations from Transformers. The paper, by Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova, took the encoder half of the Transformer architecture and pre-trained it on unlabeled text: the BooksCorpus (800 million words) and English Wikipedia (2,500 million words).

The procedure, as the paper specifies it:

  • Take each input sequence and randomly select 15% of its WordPiece tokens for corruption. The other 85% keep their original values and are not predicted.
  • Of the selected tokens, replace 80% with a special [MASK] symbol, swap 10% for a random word from the vocabulary, and leave 10% unchanged.
  • Train the model to predict the original token at every selected position, using the full surrounding context, left and right.

The bidirectional part is the point. A next-word model can only ever look backward, because at every step only the past exists. MLM frees each position to attend in both directions: to guess whether "she poured the ___ into the cup" ends in water or wine, the model must read past the blank. BERT's abstract frames this as the difference from prior systems: it pre-trains "deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers."

The payoff was large and immediate. BERT-Large, with 340 million parameters (BERT-Base had 110 million), pushed the GLUE benchmark average to 80.5%, a 7.7-point absolute improvement over the previous state of the art, lifted MultiNLI accuracy to 86.7%, and took SQuAD v1.1 question answering to 93.2 F1. One pre-trained model, plus a thin output layer per task, beat years of task-specific engineering.

A passage with scattered blank slots, context arrows flowing into each slot from both sides

The fine print of the blank

Two details in the recipe are load-bearing, and the paper is candid about why they exist.

The 80/10/10 split is a patch for a defect of the method itself. If the model only ever saw [MASK] symbols during training, it would learn to rely on a marker that never appears at test time. As the paper puts it, "the purpose of the masking strategies is to reduce the mismatch between pre-training and fine-tuning, as the [MASK] symbol never appears during the fine-tuning stage." By sometimes corrupting words with random tokens and sometimes leaving them intact, the model learns to check every position, not just the marked ones. The 15% rate itself was chosen empirically as a trade-off: higher masking gives fewer training targets per batch but starves the model of context.

The cracks were structural. In 2019 and 2020, three papers documented them.

The RoBERTa paper (Yinhan Liu et al., Meta) reran BERT with more compute, more data, and a longer schedule and found that "BERT was significantly undertrained," meaning much of what looked like architecture was actually budget. It also quietly dropped one of BERT's two training objectives, the next sentence prediction task, noting it among the changes that mattered, alongside training on longer sequences and dynamically re-choosing the mask pattern each epoch instead of freezing it.

The XLNet paper (Zhilin Yang et al.) named the mechanical problems: by masking several positions inside one window, "BERT neglects dependency between the masked positions and suffers from a pretrain-finetune discrepancy." XLNet's fix was to predict tokens in random orders rather than replacing them with blanks, keeping autoregressive factorization while still seeing both directions. It reported beating BERT on 20 tasks.

The ELECTRA paper (Kevin Clark et al.) attacked the economics. A masked model only learns from the 15% of tokens selected for prediction, so most of each batch carries no gradient signal. ELECTRA's "replaced token detection" asks the model to judge whether every token in a corrupted input is original or replaced, a task "more efficient than MLM because the task is defined over all input tokens rather than just the small subset that was masked out."

Why the generative world moved on

None of the fixes made MLM the winner of the pre-training race, because the market that grew huge wanted models that write, and MLM models fundamentally cannot. A masked model predicts independent blanks, not a sequence. Generation was bolted on or avoided entirely.

Autoregressive training, where every token in the batch is a prediction target and no special [MASK] fiction is required, scales cleanly and produces text as a side effect of its objective. The GPT-3 paper (Tom Brown et al.) made the case with a 175-billion-parameter decoder-only model that performed tasks from translation to arithmetic "without any fine-tuning," given only a prompt. That inverted the BERT workflow, which needed labeled examples and a fine-tuned head per task. By 2022 the default choice for anything generative was decoder-only, and new encoder variants mostly stopped shipping.

Two diverging paths from one source: one road lined with finished documents, one road of scattered blank tiles

Where MLM still runs your software

The understanding jobs never fully migrated. Encoder models descended from BERT dominate the embedding and classification layer of production AI. Sentence-BERT (Nils Reimers and Iryna Gurevych, 2019) showed how to adapt a pre-trained BERT into a siamese network that maps sentences into dense vectors comparable by cosine similarity, which is exactly the operation every semantic search and RAG retrieval system performs before it shows you anything. The MTEB benchmark (Niklas Muennighoff et al.) later standardized how those vectors are graded, spanning 8 embedding task types, 58 datasets and 112 languages, and its verdict was that no single embedding method dominates everywhere.

So when you evaluate a stack, the split to keep in mind is this. The model that writes your drafts is autoregressive, trained to predict the next token. The model that ranks, embeds, routes and classifies around it is most likely a masked-language-model descendant, still doing the cloze exercise from a 1953 readability study, 500 million times a second.

Sources

AILLMeducational