MLCrack

    LLMS & TRANSFORMERS · INTERVIEW QUESTION

    How does multi-head attention differ from single-head attention? Why use multiple heads?

    🟡 intermediate · Transformer Architecture

    Hint: Think about attending to different representation subspaces.

    Answer

    Single-head attention computes one set of attention weights. Multi-head attention runs h parallel attention operations with separate learned projections (W_Q^i, W_K^i, W_V^i). Each head can attend to different positions and capture different types of relationships (syntactic in one head, semantic in another). Outputs are concatenated and linearly projected: MultiHead(Q,K,V) = Concat(head_1,...,head_h)W_O.

    Benefits:

    1. Richer representations from different subspaces
    2. More stable gradients
    3. Parallel computation. Typically h=8 or h=16 with d_model/h dimensions per head. Grouped Query Attention (GQA) in modern LLMs shares K,V heads across query heads to reduce KV-cache memory.