liveBook · Manning

Attention head

As explained in Grokking AI Algorithms, Second Edition

An attention head is an independently parameterized component of an attention layer that learns relationships among tokens from a particular perspective using its own query, key, and value matrices.

An attention head is an independently parameterized perspective within self-attention. It learns which tokens relate to one another using its own query, key, and value matrices. section 11.22

Self-attention lets every token decide how much other tokens should influence its meaning. One head might focus on adjectives, while another focuses on nouns or pronouns. section 11.17 section 11.22

Tracing relationships in a sentence

In “Alice was beginning to get very tired,” the token “tired” can look back to “Alice” to identify who is tired and to “very” to determine how tired. Different heads can learn different relationships in parallel. section 11.17 section 11.22

Multiple heads expand the model’s representational coverage:

  • Each head learns a distinct type of connection, such as grammar, pronouns, or token position. section 11.22
  • The model combines all heads’ findings into a richer representation of each token. section 11.22
  • For width 8, the design can use one 32×8 head, two 32×4 heads, or four 32×2 heads. section 11.22
Figure 11.40 An analogy of the usefulness of multiple attention heads
11_40

Use the chef analogy to visualize heads as specialists examining the same ingredients from different perspectives. section 11.22

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains specialization, independent QKV matrices, output combination, and width allocation, without deriving the full attention equations.
Examples
Uses the Alice sentence, chef analogy, grammatical specializations, and alternative head-width configurations.
What it assumes
Assumes token embeddings and self-attention context while introducing head specialization through intuitive examples.
What you can do after
Understand how multiple independently parameterized heads capture and combine different token relationships.
How it connects
Connects attention heads to self-attention, Transformers, embeddings, query matrices, key matrices, and value matrices.

Also explained in

Compare how 2 books explain attention head →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.