Attention Intuition › Attention vs Pooling
Language AI HandbookAll chapters Attention Intuition › Attention vs PoolingOne section · Sections in this chapter9 / 20 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Before attention became widespread, sequence models often used pooling operations to aggregate information. Mean pooling averages all hidden states, while max pooling takes the element-wise maximum. Understanding how attention differs from these simpler approaches clarifies exactly what attention adds.
Mean pooling treats all positions equally by computing a simple average:
where:
- : the aggregated context vector, the same dimension as hidden states
- : the number of positions in the sequence
- : the hidden state at position
Each position receives weight , regardless of content. This works when all parts of the input contribute equally to the output, but fails when relevance varies. In sentiment analysis, the phrase "not good" carries more weight than "the movie was", yet mean pooling gives them equal importance.
Max pooling extracts the strongest signal at each dimension independently:
where:
- : the -th dimension of the aggregated vector
- : the -th dimension of the hidden state at position
- : the maximum value across all positions
This captures salient features by selecting the most activated value for each dimension. However, it loses information about which positions contributed and cannot combine graded contributions from multiple positions.
Attention provides learned, context-dependent weighting:
where the weights are computed dynamically based on what the model needs at each step . Unlike mean pooling's uniform weights or max pooling's binary selection, attention learns which positions matter most for the current prediction.
Consider the sentence "The movie was absolutely terrible" for sentiment classification. The comparison below shows how mean pooling and a trained attention mechanism would weight each word:
| Word | Mean Pooling | Attention |
|---|---|---|
| The | 0.20 | 0.02 |
| movie | 0.20 | 0.08 |
| was | 0.20 | 0.03 |
| absolutely | 0.20 | 0.12 |
| terrible | 0.20 | 0.75 |
The contrast is stark. Mean pooling treats "The" and "terrible" as equally important, diluting the sentiment signal. Attention learns to focus on "terrible" and to a lesser extent "absolutely", producing a context vector that emphasizes the words driving the classification.
| Method | Weights | Context-dependent | Interpretable |
|---|---|---|---|
| Mean pooling | Uniform () | No | No |
| Max pooling | Binary (0 or 1) | No | Partial |
| Attention | Learned | Yes | Yes |
One more consideration separates attention from both pooling methods: attention is query-dependent. The same input sequence produces different context vectors at different decoding steps, because the query (decoder state) changes. Mean pooling and max pooling produce the same aggregation regardless of what you are trying to do with it. Attention adapts. When generating "chat" (cat), the attention mechanism focuses on the source position for "cat." When generating "noir" (black), it shifts focus to "black." This step-specific adaptation is something that pooling simply cannot provide.