# Uwaga wielogłowicowa (multi-head attention)

EN: **Multi-head attention** · id `multihead` · aliases: MHA, multi-head attention, uwaga wielogłowicowa, attention heads, głowice uwagi

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 wielogłowicowa (multi-head attention)

## Description

- PL: Równoległe wykonanie h niezależnych operacji scaled dot-product attention na różnych rzutowaniach zapytań, kluczy i wartości, z konkatenacją i rzutowaniem wyniku.
- EN: Running h independent scaled dot-product attention operations in parallel on different projections of queries, keys and values, then concatenating and projecting the result.

## In one sentence

- PL: Model patrzy na ten sam tekst kilkoma równoległymi „parami oczu”, z których każda śledzi inny rodzaj powiązań między słowami.
- EN: The model looks at the same text through several parallel "pairs of eyes", each tracking a different kind of link between words.

## Problem it solves

- PL: Jedno spojrzenie na zdanie nie uchwyci naraz gramatyki, odniesień do wcześniejszych słów i sensu całości.
- EN: A single look at a sentence cannot catch grammar, references to earlier words and overall meaning all at once.

## What it does

- PL: Jak zespół korektorów: jeden sprawdza interpunkcję, drugi fakty, trzeci styl, a na koniec łączą uwagi w jedną poprawkę.
- EN: Like a team of proofreaders: one checks punctuation, another facts, a third style, and then they merge their notes into one edit.

## Everyday example

- PL: Gdy w zdaniu pada „ona”, jedna część modelu szuka, o kogo chodzi, a inna pilnuje zgodności czasu i liczby.
- EN: When a sentence says "she", one part of the model looks for who is meant while another keeps tense and number consistent.

## This concerns you if you…

- PL: chcesz zrozumieć, co jest w środku dużego modelu językowego
- PL: czytasz o tym, co robią poszczególne głowice uwagi
- EN: want to understand what is inside a large language model
- EN: read about what individual attention heads do

## Keywords

scaled dot-product attention · attention heads · head pruning · induction heads · grouped-query attention · PyTorch MultiheadAttention · scaled_dot_product_attention

## How it works

- PL: Zapytania, klucze i wartości przechodzą przez h osobnych, uczonych rzutowań o wymiarze d_model/h. Każda głowica liczy softmax(QKᵀ/√d_k)V; wyniki skleja się i przepuszcza przez rzutowanie wyjściowe. Koszt jest zbliżony do jednej pełnowymiarowej głowicy, a głowice mogą specjalizować się w różnych zależnościach.
- EN: Queries, keys and values pass through h separate learned projections of size d_model/h. Each head computes softmax(QKᵀ/√d_k)V; outputs are concatenated and passed through an output projection. Cost is close to one full-width head, and heads can specialise in different dependencies.

## Limits

- PL: Wiele głowic okazuje się redundantnych i da się je przyciąć bez dużej straty. Cache kluczy i wartości rośnie z liczbą głowic, stąd warianty współdzielące klucze. Interpretacja pojedynczych głowic bywa myląca, bo funkcje rozkładają się na wiele głowic.
- EN: Many heads turn out redundant and can be pruned with little loss. The key-value cache grows with head count, hence key-sharing variants. Interpreting single heads can mislead, since functions spread across many heads.

## Key terms

- PL: **głowica (head)**: Jedna z równoległych kopii uwagi z własnymi rzutowaniami.
- PL: **rzutowanie liniowe**: Mnożenie przez uczoną macierz przenoszące wektory do innej przestrzeni.
- PL: **d_k**: Wymiar kluczy w głowicy; przez jego pierwiastek skaluje się wyniki.
- EN: **head**: One of the parallel copies of attention with its own projections.
- EN: **linear projection**: Multiplying by a learned matrix to move vectors into another space.
- EN: **d_k**: Key dimension per head; scores are scaled by its square root.

## Know first

- [Mechanizm self-attention (zapytania, klucze, wartości) (Self-attention (queries, keys, values))](https://aiatlasgraph.com/t/selfattention.md)
- [Algebra liniowa: wektory i macierze (Linear algebra: vectors and matrices)](https://aiatlasgraph.com/t/linearalgebra.md)

## Related topics

Untyped, symmetric "see also" links.

- [Oszczędne warianty uwagi (MQA, GQA, MLA) (Memory-efficient attention variants (MQA, GQA, MLA))](https://aiatlasgraph.com/t/attnvariants.md)

## Sources

- [Dive into Deep Learning — 10.5. Multi-Head Attention](<https://classic.d2l.ai/chapter_attention-mechanisms/multihead-attention.html>) `d2l-multihead-attention` · by Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola
- [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/multihead · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-11-05
