Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Models and algorithms

Masked Language Model (MLM)

About 3464 characters Updated Nov 30, 2026 21 views AI wiki

A masked language model is a self-supervised pretraining objective that randomly masks some tokens in the input and has the model restore them from context. It is the core training task of BERT and the foundational design of understanding-oriented language models.

Core principles

A traditional language model can only predict the next word from left to right, so each position sees only information to its left. The masked language model breaks this limitation: since what must be guessed is a gap in the middle, the model has to consult both left and right sides at once, achieving bidirectional encoding.

The specific process has three steps. First, randomly select a certain proportion of tokens in the input sequence as masking targets, with BERT adopting a default proportion of fifteen percent. Second, perturb these selected positions rather than uniformly replacing them with a special token. Third, the model outputs a representation for each position and predicts the original word through an output layer of the same dimension as the vocabulary, trained with cross-entropy loss.

The reason not to replace all selected positions with the mask token is to alleviate the mismatch between pretraining and downstream fine-tuning: mask tokens never appear in downstream tasks, and if the model only applies effort when it sees the token, bias arises. Adding a proportion of random replacements and of unchanged originals keeps the model alert at every position.

This training lets the encoder fuse contextual information at every layer, and the resulting representations are sensitive to word order, syntax and coreference, making them especially suitable for understanding tasks such as classification, extraction and question answering.

Key points

The eighty-ten-ten strategy is standard practice. Among the selected tokens, eighty percent are replaced with the mask token, ten percent with a random word from the vocabulary, and ten percent left unchanged. Ablation experiments in the original paper showed this combination beats replacing or keeping everything.

The fifteen percent masking ratio is an empirical value. Too low and the training signal is sparse and converges slowly; too high and the context is too mutilated for the model to restore. Later work such as RoBERTa tried higher ratios and dynamic masking, indicating that the value must match the data scale.

Dynamic masking beats static masking. The static approach fixes mask positions once during preprocessing, so multiple epochs see the same occlusions; the dynamic approach resamples every epoch, effectively enlarging the training data.

Masked language models are poor at generating long text. Because they never learn left-to-right word-by-word output during training, using them directly for continuation works badly; this is the fundamental division of labor with autoregressive models.

Derived variants are plentiful. Whole-word masking, entity masking, span masking and sentence order prediction all improve on the original framework, and the Chinese setting especially values whole-word masking.

Common misconceptions

First, assuming a higher masking ratio is better. Too high a ratio degrades the task into a fill-in-the-blank game where the model depends on local cues rather than global understanding.

Second, assuming the mask token itself has no effect. The mask token participates in attention computation and, when it appears in large numbers, may interfere with representations, which is why some studies exclude it from attention.

Third, conflating the masked language model with denoising autoencoders. The two are close in form, but denoising objectives usually target contiguous spans and sequence-to-sequence structures, with clearly different design details.

Application scenarios

Text classification and sentiment analysis, named entity recognition, extractive question answering, semantic similarity matching, dense vector representations in information retrieval, Chinese word segmentation and error correction, and pretraining of code understanding models.