# Uwaga krzyżowa (cross-attention)

EN: **Cross-attention** · id `crossattention` · aliases: cross-attention, encoder-decoder attention, uwaga krzyżowa, uwaga enkoder–dekoder

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Sieci i modele generatywne](https://aiatlasgraph.com/t/neural.md) › [Transformery i attention](https://aiatlasgraph.com/t/transformers.md) › Uwaga krzyżowa (cross-attention)

## Description

- PL: Wariant uwagi, w którym zapytania pochodzą z jednej sekwencji (np. dekodera lub obrazu), a klucze i wartości z innej (np. enkodera lub tekstu warunkującego).
- EN: An attention variant where queries come from one sequence (e.g. a decoder or image) and keys and values from another (e.g. an encoder or conditioning text).

## In one sentence

- PL: Mechanizm, którym model przy tworzeniu wyniku zagląda do innego źródła: tekstu oryginału, opisu obrazka czy nagrania.
- EN: The mechanism a model uses to look into another source while producing output: the original text, an image description or a recording.

## Problem it solves

- PL: Przy tłumaczeniu czy rysowaniu według opisu model musi stale sprawdzać materiał wejściowy, a nie tylko to, co sam już napisał.
- EN: When translating or drawing from a description, the model must keep checking the input, not just what it has already written.

## What it does

- PL: Jak tłumacz, który pisząc każde zdanie zerka z powrotem do oryginału, szukając fragmentu potrzebnego właśnie teraz.
- EN: Like a translator who, writing each sentence, glances back at the original for the passage needed right now.

## Everyday example

- PL: Generator obrazów rysuje czerwony rower, bo przy każdym kroku sprawdza, które słowa twojego opisu dotyczą danego miejsca obrazu.
- EN: An image generator draws a red bicycle because at each step it checks which words of your description apply to each part of the picture.

## This concerns you if you…

- PL: używasz tłumacza maszynowego lub generatora obrazów z opisu
- PL: chcesz zrozumieć, jak model łączy tekst z obrazem
- EN: use machine translation or a text-to-image generator
- EN: want to understand how a model links text and images

## Keywords

encoder-decoder attention · text conditioning · Perceiver · U-Net cross-attention · prompt-to-prompt · T5 · Flamingo

## How it works

- PL: W bloku dekodera zapytania Q liczy się z bieżących stanów, a K i V z wyjścia enkodera albo z osadzeń warunku (tekstu, obrazu, dźwięku). Softmax(QKᵀ/√d)V wnosi do każdej pozycji informację z drugiego źródła. Tak działa oryginalny transformer do tłumaczenia oraz warunkowanie tekstem w wielu modelach dyfuzyjnych.
- EN: In a decoder block, queries Q come from current states while K and V come from the encoder output or condition embeddings (text, image, audio). Softmax(QKᵀ/√d)V brings information from the second source into each position. The original translation transformer and text conditioning in many diffusion models work this way.

## Limits

- PL: Koszt rośnie z iloczynem długości obu sekwencji. Modele wyłącznie dekoderowe zwykle zastępują ją wspólną uwagą po sklejonym kontekście. Mapy uwagi krzyżowej nie zawsze wiernie pokazują, na czym model oparł decyzję.
- EN: Cost grows with the product of both sequence lengths. Decoder-only models usually replace it with joint attention over a concatenated context. Cross-attention maps do not always faithfully show what the model relied on.

## Key terms

- PL: **enkoder–dekoder**: Układ z częścią czytającą wejście i częścią tworzącą wynik.
- PL: **warunkowanie**: Sterowanie generacją dodatkową informacją, np. opisem tekstowym.
- PL: **mapa uwagi**: Tabela pokazująca, na które elementy źródła patrzy model.
- EN: **encoder–decoder**: A design with one part reading input and another producing output.
- EN: **conditioning**: Steering generation with extra information such as a text prompt.
- EN: **attention map**: A table showing which source elements the model looks at.

## Know first

- [Mechanizm self-attention (zapytania, klucze, wartości) (Self-attention (queries, keys, values))](https://aiatlasgraph.com/t/selfattention.md)

## Related topics

Untyped, symmetric "see also" links.

- [Dyfuzja w przestrzeni ukrytej (Stable Diffusion) (Latent diffusion (Stable Diffusion))](https://aiatlasgraph.com/t/latentdiffusion.md)
- [Tłumaczenie maszynowe (Machine translation)](https://aiatlasgraph.com/t/machinetranslation.md)

## Sources

- [Attention Is All You Need](<https://arxiv.org/abs/1706.03762>) `vaswani-attention-2017` · by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, Illia Polosukhin

---

AI Atlas revision 129 (2026-11-05) · HTML: https://aiatlasgraph.com/t/crossattention · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-11-05
