Masking means deliberately hiding some positions from a model. The word covers two related jobs in modern machine learning, and it helps to keep them apart.
Masks that control attention
In a transformer, self-attention lets every token look at every other token. An attention mask switches some of those connections off, in practice by setting their attention scores to minus infinity before the softmax so they receive zero weight.
- A causal mask stops each position from seeing the positions after it. The original transformer used this in its decoder so that predicting the next word can’t cheat by looking ahead, and every GPT-style model relies on it.
- A padding mask tells the model to ignore the filler tokens added to make sequences in a batch the same length.
Here masking doesn’t change the data; it changes what the model is allowed to use.
Masks that create a training task
The second job hides part of the input on purpose and trains the model to reconstruct it, which turns unlabeled data into a supervised task. Masked language modeling, introduced with BERT, hides 15% of the tokens in each sequence and asks the model to predict them from context on both sides; see the BERT paper. Vision borrowed the idea: masked autoencoders hide 75% of an image’s patches and learn by filling them back in.
The difference that matters
A causal mask makes a model generative: it can only use the past, so it can write text one token at a time. A fill-in-the-blank objective with bidirectional attention makes a model a strong reader but not a natural writer. That split is much of the difference between GPT-style and BERT-style models.