Home Glossary Attention Mask

Attention Mask

An attention mask is a control structure used in transformer models to limit which tokens participate in attention calculations. A padding mask prevents artificial padding tokens from affecting a sequence, while a causal mask blocks a token from seeing future positions during autoregressive generation. Other masks can enforce local attention, protect segments, or represent task-specific relationships. The mask is commonly stored as a binary or additive tensor that modifies attention scores before normalization. Incorrect masking can leak future information during training, make padded batches behave inconsistently, or cause generated text to fail. Attention masks shape information flow for a specific input; they do not change the model’s learned parameters.

Related News