AI Glossary / Generative AI and language / Intermediate
Attention head
Definition
An attention head is one attention computation within a multi-head attention mechanism. In a standard Transformer, each head uses learned projections to form queries, keys and values, combines information through its own attention weights, and contributes an output that is mixed with the outputs of other heads.
What it means
A single attention operation produces one pattern of weighted information combination for each query. Multiple heads allow several learned combinations to operate in parallel, potentially capturing different relationships or aspects of the representations.
A head is not a separate chatbot, agent or human-like specialist. Its apparent role emerges from training, and it may be distributed, redundant or difficult to describe in ordinary language. One head can behave differently across inputs.
The word head also appears in task-specific output heads, such as a classification layer attached to a backbone. That is a different use. An attention head operates inside an attention module; a task head commonly converts model features into a task's final prediction.
How it works
For each standard attention head, learned matrices project input representations into query, key and value spaces. Query-key compatibility scores are scaled and normalized over the allowed positions. Those weights combine the value vectors.
Each head produces an output vector for each query position. In the original multi-head Transformer formulation, the head outputs are concatenated and transformed through an output projection. They are not simply asked to vote on a final answer.
A common design divides the total representation width among the heads, so more heads at fixed width can mean a smaller vector dimension per head. Exact dimensions and sharing arrangements depend on the architecture; head count alone does not define model capacity or inference cost.
Researchers can inspect patterns or remove heads to study their contribution. Some studies find specialized or redundant heads in particular models. These findings do not establish a universal rule that every head has one fixed linguistic job or that a head removable in one setting is unnecessary everywhere.
Three practical examples
- A translation researcher inspects whether selected heads show consistent relationships between nearby or grammatically related tokens.
- An optimization team tests head pruning while measuring the effect on task performance and actual runtime cost.
- A model developer compares multi-head configurations under a fixed representation width rather than assuming that doubling head count doubles model size.
Think of it this way
Think of several filters examining the same collection of signals through different learned lenses. Their outputs are combined into a richer working representation.
The lenses are not independent experts with opinions. Their internal coordinates may not have simple names, and the final model mixes information across heads and layers. The analogy describes multiple views, not a committee reasoning in human terms.
Worked example
Two heads preserve different mixtures
For a teaching example, imagine two heads attending over the same two scalar values, 2 and 10. Head A uses weights 0.75 and 0.25, giving output 4. Head B uses weights 0.25 and 0.75, giving output 8.
Concatenating these outputs produces the two-component representation (4, 8). A simplified output projection with coefficients (1, -0.5) produces 4 - 4 = 0.
This shows why attention heads cannot be interpreted as independent final answers. Their contributions can be combined in ways that amplify or cancel components. Real heads normally have separate value projections and multidimensional outputs; the shared scalar values here isolate the combining arithmetic rather than reproduce a complete Transformer layer.
Illustrative case study
A fictional document-search team, Rowan Retrieval, notices a head that often places large weights on section titles. It labels the head the topic detector and considers using its weights as a direct explanation for search results.
Further examples show that the pattern is inconsistent on tables and short documents. Removing the head also has different effects depending on which other heads remain active. The team replaces the fixed label with a narrower description of the observed pattern and tests the behavior across representative inputs.
It retains the visualization for research but does not present it as a complete explanation of ranking. The case illustrates the difference between recognizing a suggestive pattern and establishing a stable functional role.
Common misconceptions and mistakes
More heads do not automatically mean better predictions. Width, depth, training and task design interact, and redundant heads may add little useful behavior.
Do not equate an attention head with one word, one topic or one output class. A head computes attention for multiple query positions and can participate in different patterns.
A visually sharp attention pattern is not proof of causal importance. Conversely, a diffuse pattern is not proof of uselessness. Head-removal experiments are informative but describe an intervention on a particular trained system and dataset, with possible interactions among components.
Business use
Attention-head details are mainly useful for model engineering, resource planning and careful inspection. For a business decision, evaluate the whole model on the required tasks rather than comparing head counts as if they were quality ratings.
If pruning is proposed to reduce costs, measure the exported model's real latency and memory as well as predictive behavior. Removing mathematical components does not always yield proportional runtime savings in a particular implementation. Preserve the tested configuration and monitor important scenarios that an overall benchmark average could hide.
People also ask
Does each head learn a unique role?
Not necessarily. Some heads show recurring patterns, while others overlap or have roles that depend on context.
Are attention heads trained separately?
They are typically trained jointly as parts of the overall model through the task's optimization process.
Is an attention head the same as a classification head?
No. The former combines representations within attention; the latter usually maps model features to output classes.
Check your understanding
A model has eight attention heads in a layer. Does this mean it generates eight independent answers and chooses the majority answer?
Answer: No. The heads produce intermediate representations that are combined by the network. They are not eight independent answer-generating agents.
Related terms
- Attention
- Multi-head attention
- P-value
- Transformer
- Model Interpretability
- query
- key
- value
- output projection
- head pruning
- classification head
Learn next
Work through two attention calculations with different weights and combine their outputs. Then inspect how a standard layer divides its representation width across heads. When studying a real head, compare patterns across inputs and use controlled interventions before assigning it a functional label.
More in Generative AI and language
- Adaptive sampling - Adaptive sampling is an approach in which information from earlier samples influences which samples are selected next or how sampling effort is allocated.
- Adaptive Synthetic Sampling - Adaptive Synthetic Sampling, usually abbreviated ADASYN, is an oversampling method for imbalanced classification.
- AI slop - AI slop is an informal, critical term for low-quality AI-generated content produced with an emphasis on quantity rather than usefulness, accuracy or...
- Attention mask - An attention mask specifies which positions may participate in an attention calculation.
- Attribute sampling - Attribute sampling is a decision-tree training technique that randomly selects a subset of input features to consider when choosing a split.
- Autoencoder - An autoencoder is a neural network trained to reconstruct an input from an internal representation of that input.
Sources
Sources: Vaswani and colleagues, Attention Is All You Need, multi-head attention: https://arxiv.org/abs/1706.03762 Voita and colleagues, Analyzing Multi-Head Self-Attention: https://aclanthology.org/P19-1580/ Jain and Wallace, Attention is not Explanation: https://aclanthology.org/N19-1357/ Hugging Face, model backbones and task heads: https://huggingface.co/docs/transformers/main/en/glossary
Previous: Attention coverage mechanism Next: Attention mask