NEW
A parallel attention mechanism projecting queries, keys, and values into multiple subspaces within a transformer layer.
DESCRIPTION
An attention head performs scaled dot-product attention in a learned subspace, enabling transformers to focus on different aspects of the input simultaneously. By using multiple heads, models jointly attend to varied patterns across positions and representation subspaces. Heads often specialize (e.g., syntactic, positional, or long-range dependencies) and can be pruned or analyzed for interpretability. The number of heads trades off between capacity and compute, typically dividing the model dimension among them.
ALTERNATIVE DEFINITIONS
Vaswani et al. (Attention Is All You Need)
Multi-head attention allows the model to jointly attend to information from different representation subspaces at different positions.
Highlights the benefit of parallel attention across subspaces and positions.
PyTorch
MultiheadAttention allows the model to jointly attend to information from different representation subspaces.
Developer-focused API describing the multi-head attention module.
Harvard NLP (The Annotated Transformer)
Multi-head attention is simply several attention layers running in parallel.
Emphasizes the parallel composition of separate attention operations.
RELATED TERMS
Self-Attention Transformer Model Query-Key-Value Scaled Dot-Product Attention Multilayer Perceptron Positional Encoding Layer Normalization Head Pruning Residual Connection Encoder-Decoder
COMPETING TERMS
Single-Head Attention
RELATIONS
- Broader: Attention Mechanism
KNOWLEDGE AREAS
TARGET AUDIENCE
AI Engineer Data Scientist MLOps Engineer Software Developer
EXTERNAL SOURCES
- Wikipedia - Attention (machine learning)
- Vaswani et al. - Original transformer paper
- PyTorch - PyTorch multi-head attention docs
- TensorFlow - Transformer tutorial with attention
- Harvard NLP - Annotated Transformer explanation
TOP QUESTIONS
What is an Attention Head in transformers?
It is a single attention mechanism operating in a subspace, with multiple heads enabling the model to attend to different patterns simultaneously.
Category: Definition
Why use multiple Attention Heads?
Multiple heads let the model jointly capture diverse relationships and positions, improving expressiveness and representation capacity.
Category: Relevancy
How many Attention Heads should a model use?
A common heuristic is to divide the embedding dimension evenly across heads; typical ranges include 8 to 32 heads depending on scale.
Category: Requirements
Are Attention Heads interpretable?
Some heads exhibit interpretable behavior (e.g., syntax or positional focus), but interpretability varies and often requires careful analysis.
Category: Opinion
What are common mistakes with Attention Heads?
Using too many heads without sufficient dimension per head can degrade performance; poor initialization or scaling can cause training instability.
Category: Mistakes
What is a competing approach to multi-head attention?
Single-head attention simplifies computation but often reduces modeling capacity compared to multi-head architectures.
Category: Alternatives
What is currently a hot topic around Attention Heads?
Head pruning, head importance analysis, and head specialization are active areas for efficiency and interpretability.
Category: Topic
Where did Attention Heads originate?
They were introduced in the 2017 paper āAttention Is All You Needā by Vaswani et al.
Category: Origin
How do Attention Heads interact with positional encoding?
Positional information guides attention to capture order and distance, helping heads model sequence structure.
Category: Relation
How can I visualize Attention Heads?
Plot attention weight matrices per head; tools in libraries and notebooks can show token-to-token attention patterns.
Category: HowTo