# Attention Mask

- **Canonical URL:** https://getaimath.com/dictionary/attention-mask/
- **Topics:** [Transformer Architecture](https://getaimath.com/dictionary/category/transformer-architecture/)
- **Last updated:** 2026-11-25

## What is Attention Mask?

**In one sentence:** An attention mask is a pattern that tells the model which positions it may or may not attend to.

It is a grid of allowed and blocked spots. Blocked spots get a huge negative score before softmax, so they end up with almost zero attention. Masks are used for causal generation and to skip padding tokens.

![Transformers & Attention: The Smart Highlighter — Simple cartoon diagram showing how a Transformer reads a whole sentence at once and shines a bright highlighter beam from the word "IT" back to "trophy" so it knows what "IT" means.](https://getaimath.com/diagrams/transformer-architecture.png)
*Napkin Diagram (Transformer Architecture): Older AI read word-by-word and often lost track of earlier words; a Transformer highlights which words connect to which.*

## What is an example of Attention Mask?

If a sentence is padded with empty tokens to fit a batch, the attention mask makes sure the model ignores them.

## Why does Attention Mask matter?

Attention masks keep models from seeing things they should not see.

## Related Concepts

- [FlashAttention](https://getaimath.com/dictionary/flashattention/): FlashAttention is a clever way to compute attention on GPUs that is much faster and uses much less memory, while giving the same results.
- [Positional Encoding](https://getaimath.com/dictionary/positional-encoding/): Positional encoding adds information about word order, so the model knows which word came first, second, and so on.
- [Grouped-Query Attention (GQA)](https://getaimath.com/dictionary/grouped-query-attention-gqa/): Grouped-query attention is a middle ground where groups of heads share keys and values, balancing speed and quality.
- [Rotary Positional Embedding (RoPE)](https://getaimath.com/dictionary/rotary-positional-embedding-rope/): RoPE is a popular way to tell a model about word positions by rotating its query and key numbers by an angle based on position.
- [Multi-Query Attention (MQA)](https://getaimath.com/dictionary/multi-query-attention-mqa/): Multi-query attention is a faster type of attention where all heads share one set of keys and values but keep separate queries.
- [ALiBi](https://getaimath.com/dictionary/alibi/): ALiBi is a simple way of handling word position by adding a penalty to attention scores based on how far apart two words are.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/attention-mask/)
