Concept icon
Concept

Multi-Head Attention Mechanism

Instead of executing a single attention function using queries, keys, and values of the model dimension dmodeld_{\text{model}}, Multi-Head Attention linearly projects QQ, KK, and VV with hh separate learned projections to dimensions dkd_k, dkd_k, and dvd_v, respectively. Applying attention across each of these projected versions in parallel produces dvd_v-dimensional output values that are concatenated and projected once again to form the final values:

MultiHead(Q,K,V)=Concat(head1,,headh)WO\text{MultiHead}(Q, K, V) = \text{Concat}(\text{head}_1, \dots, \text{head}_h)W^O

where headi=Attention(QWiQ,KWiK,VWiV)\text{where } \text{head}_i = \text{Attention}(QW_i^Q, KW_i^K, VW_i^V)

The projections are parameter matrices WiQRdmodel×dkW_i^Q \in \mathbb{R}^{d_{\text{model}} \times d_k}, WiKRdmodel×dkW_i^K \in \mathbb{R}^{d_{\text{model}} \times d_k}, WiVRdmodel×dvW_i^V \in \mathbb{R}^{d_{\text{model}} \times d_v}, and WORhdv×dmodelW^O \in \mathbb{R}^{h d_v \times d_{\text{model}}}. In the base model, h=8h = 8 parallel attention heads are used with dk=dv=dmodel/h=64d_k = d_v = d_{\text{model}} / h = 64 for dmodel=512d_{\text{model}} = 512.

Multi-head attention allows the model to jointly attend to information from different representation subspaces at different positions simultaneously. In contrast, a single attention head averages attention-weighted positions, which inhibits this capability. Because the dimensions of each head are reduced, the total computational cost remains similar to that of full-dimensionality single-head attention.

0

1

Concept icon
Updated 2026-09-07

Tags

Prep Sessions

Foundational Deep Learning Architectures: Transformers and Residual Networks @ University of Michigan - Ann Arbor

Ch.1 Transformer Architecture and Components - Foundational Deep Learning Architectures: Transformers and Residual Networks @ University of Michigan - Ann Arbor

Multi-Head Attention - Foundational Deep Learning Architectures: Transformers and Residual Networks @ University of Michigan - Ann Arbor