# Masked Attention

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

## What is Masked Attention?

**In one sentence:** Masked attention is attention where some positions are hidden, so certain words cannot look at certain other words.

A mask is like putting a sticky note over parts of the page. It is used to block future words in causal models, to ignore padding added to make sentences the same length, or to keep separate documents from seeing each other in a batch.

![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 Masked Attention?

When two short sentences are packed into one batch, masked attention stops words from one sentence attending to the other.

## Why does Masked Attention matter?

Masks control what information a model is allowed to use.

## Related Concepts

- [Causal Attention](https://getaimath.com/dictionary/causal-attention/): Causal attention only lets each word look at the words before it, never the words after.
- [Cross-Attention](https://getaimath.com/dictionary/cross-attention/): Cross-attention lets one part of a model pay attention to a different input, like a decoder looking at an encoder's output.
- [Scaled Dot-Product Attention](https://getaimath.com/dictionary/scaled-dot-product-attention/): Scaled dot-product attention is the standard math recipe for attention: compare queries and keys, scale the results, softmax them, and mix the values.
- [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.
- [Attention Scores](https://getaimath.com/dictionary/attention-scores/): Attention scores are numbers that show how much each word should focus on every other word.
- [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.

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