# Cross-Attention

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

## What is Cross-Attention?

**In one sentence:** Cross-attention lets one part of a model pay attention to a different input, like a decoder looking at an encoder's output.

In self-attention, words look at their own sentence. In cross-attention, the queries come from one source and the keys and values come from another. This is how a model connects two things, such as a sentence being written and the sentence being translated, or text and an image.

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

In image generation, cross-attention lets the picture being drawn focus on the words in your prompt, like "red balloon."

## Why does Cross-Attention matter?

Cross-attention is how models combine different inputs, such as text and images.

## Related Concepts

- [Masked Attention](https://getaimath.com/dictionary/masked-attention/): Masked attention is attention where some positions are hidden, so certain words cannot look at certain other words.
- [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.
- [Causal Attention](https://getaimath.com/dictionary/causal-attention/): Causal attention only lets each word look at the words before it, never the words after.
- [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.
- [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.
- [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.

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