What is Masked Language Modeling?
Hide words in a sentence and let a bidirectional model guess them back. Click any token to mask it, then watch the model score candidates using context from both sides.
Hide words in a sentence and let a bidirectional model guess them back. Click any token to mask it, then watch the model score candidates using context from both sides.
Masked Language Modeling (MLM) is the pretraining objective behind BERT and its descendants. The recipe is deceptively simple: take ordinary text, hide a fraction of the tokens, and train the model to reconstruct exactly what was hidden. No human labels required — the text supplies its own answer key.
A causal model reads left to right and predicts what comes next, so it can never look ahead. MLM has no such restriction: the blank sits in the middle, and the model is free to use every token on both sides at once.
Mask soft in "the cat sat on the ___ mat" and the left context narrows it to a modifier while the right context (mat) rules out most adjectives. Neither side alone is enough. That is why MLM produces such strong understanding representations — and why it cannot be used to generate text.
BERT masks about 15% of tokens, but does not always insert a literal [MASK]. Of the chosen positions:
The reason is a train/test mismatch: [MASK] never appears during fine-tuning or inference. If every masked slot were a literal mask token, the model would learn features that only activate on a symbol it will never see again.
Mask too little and each sentence teaches the model almost nothing — training is slow because most positions carry no loss. Mask too much and you destroy the very context needed to make a prediction. Around 15% is the long-standing sweet spot, though later work has shown much higher rates can work with large enough models. Drag the rate slider and watch the sentence degrade: at 50% the remaining context often cannot pin the answer down.
Predictions come from a small context-scoring model built live in your browser from the demo corpus shown in the vocabulary count — it ranks candidate words by how often they co-occur with the surviving context. It is a genuine calculation, not a canned list, but it is far simpler than a transformer: treat the shape of the results as the lesson, not the exact percentages.
MLM turns any raw text into supervised training data by deleting parts of it. Because the blank is surrounded rather than trailing, the model learns deep bidirectional understanding — ideal for classification, retrieval and question answering, and unsuitable for generation. That generative job belongs to causal models, which predict strictly forward.
Hide words in a sentence and let a bidirectional model guess them back. Click any token to mask it, then watch the model score candidates using context from both sides.