Analyzing Multi-Head Self-Attention: Specialized Heads Do the Heavy Lifting, the Rest Can Be Pruned

TL;DR

LRP and Hard Concrete pruning show that retaining 10 of 48 encoder heads cuts WMT En–Ru BLEU by only 0.15.

cs.CL 🟡 Intermediate 2019-05-23 27 views
Elena Voita David Talbot Fedor Moiseev Rico Sennrich Ivan Titov
Transformer self-attention NMT structured pruning interpretability

Key Findings

Methodology

The study first applies Layer-wise Relevance Propagation (LRP) to estimate each encoder head’s contribution to the top-1 output logit, and defines confidence as the average maximum attention weight. It then tests positional, syntactic, and rare-word functions. For pruning, each head receives a learned stochastic gate and the Hard Concrete relaxation of the L0 penalty from Louizos et al. Training minimizes translation cross-entropy plus the expected number of active gates.

Key Results

  • Important heads are concentrated and interpretable: positional heads assign their maximum weight to one relative position at least 90% of the time, with average maximum attention above 0.8; syntactic heads beat positional baselines on nsubj, dobj, amod, and advmod relations.
  • On WMT English–Russian, the 48 encoder heads can be reduced to 10, removing 38 heads, for only a 0.15 BLEU drop. On 6m-sentence OpenSubtitles English–Russian, retaining only 4 of 48 heads costs about 0.25 BLEU.
  • When all attention types are gated, encoder self-attention is pruned first, whereas decoder–encoder attention is most important. WMT baseline BLEU is 29.6; retaining 14/31/30 heads across encoder, decoder self-attention, and cross-attention yields 29.62.

Significance

The paper overturns the assumption that all attention heads contribute equally. Translation quality is carried disproportionately by a small set of specialized heads, while many others are redundant after training. Because the heads that look linguistically structured are also the last to disappear under learned pruning, the work links interpretability to functional importance. For production translation, this suggests reductions in memory, computation, and serving cost without proportional quality loss.

Technical Contribution

The central contribution is a differentiable structured-sparsity objective. With a gate gi on head i, the model uses Concat(gi·headi)WO. The inaccessible L0 count is replaced by LC(φ)=Σi(1−P(gi=0|φi)), using Hard Concrete gates with probability mass at zero and one. The objective is L=Lxent+λLC, optimized with reparameterization. Gates converge near closed or open states, enabling discrete inference. Decoder parameters are frozen in encoder-only pruning, preventing functional migration from obscuring head importance.

Novelty

Unlike analyses that average attention weights or inspect only maxima, this work combines LRP attribution, confidence, dependency evaluation, and learned structural pruning. The novel evidence is behavioral: specialized heads are not merely visually interpretable; they survive the optimization pressure to remove components. Pruning therefore serves both as compression and as a test of functional necessity.

Limitations

  • The experiments cover Transformer NMT for English–Russian, English–German, and English–French, plus an English–Russian subtitle domain. Generalization to larger architectures, low-resource languages, other tasks, or contemporary large language models is untested.
  • Syntactic labels come from CoreNLP parses and a hand-defined 10% improvement over positional baselines. Parsing errors and positional confounds may therefore inflate or distort the apparent linguistic specialization.
  • Pruning starts from a converged dense model. Training the same sparse configurations from random initialization performs worse, so the method exploits redundancy created during dense optimization rather than proving that sparse training is equally effective.

Future Work

The authors explicitly propose comparison with alternative NMT compression methods. Further work should test dynamic input-dependent gates, larger and multilingual models, joint pruning of feed-forward blocks, and causal interventions on head functions. Practical studies should measure wall-clock latency, memory, energy, and hardware-specific sparse-kernel support rather than head counts alone.

AI Executive Summary

Transformers often contain many attention heads, yet it has been unclear whether they make comparable contributions to translation. Earlier analyses typically averaged heads or inspected only the largest attention weights, obscuring both specialization and redundancy. Voita and colleagues instead ask which heads actually influence predictions and which can be removed.

They rank encoder heads with Layer-wise Relevance Propagation, measuring contribution to the top-1 output logit, and compare this with confidence, defined by average maximum attention. The strongest heads commonly have recognizable roles: attending to adjacent tokens, tracking dependency relations such as subjects and objects, or locating rare words. The authors then attach stochastic Hard Concrete gates and optimize cross-entropy plus a differentiable relaxation of the L0 penalty.

The result is a highly uneven division of labor. In WMT English–Russian, 38 of 48 encoder heads can be pruned with only a 0.15 BLEU loss; on OpenSubtitles, retaining four heads costs about 0.25 BLEU. Across all attention types, encoder self-attention is most redundant, while decoder–encoder attention is most essential. The study offers a compactness result and an interpretability result: specialized heads do the heavy lifting, and pruning provides a practical way to reveal them.

Deep Analysis

Background

The Transformer of Vaswani et al. replaced recurrence with stacked self-attention and feed-forward layers, becoming dominant in neural machine translation. Multi-head attention improved capacity; eight heads reportedly beat a same-sized single-head model by nearly one BLEU. Yet prior attention analyses often averaged heads or selected maxima, leaving individual causal contribution unresolved. This paper focuses primarily on encoder self-attention.

Core Problem

The study asks whether translation depends on every encoder head, whether important heads learn stable linguistic functions, which attention type and decoder layer matter most, and whether heads can be removed safely. The challenge is methodological: attention weights are not direct measures of predictive contribution, while the ideal L0 objective counts active components but is nondifferentiable.

Innovation

The paper makes three advances. First, LRP ranks heads by relevance to a model prediction. Second, it operationalizes positional, syntactic, and rare-word functions and evaluates them against dependency and positional baselines. Third, Hard Concrete stochastic gates provide a trainable L0-style structural-pruning mechanism. This unifies analysis and compression: heads that are interpretable and functionally necessary should remain active under sparsity pressure.

Methodology

  • �� Attention uses Attention(Q,K,V)=softmax(QKᵀ/√dk)V; each head is projected and concatenated.
  • �� A scalar gate gi multiplies each head before output projection: Concat(gi·headi)WO.
  • �� LRP propagates relevance from the top-1 logit to heads; confidence is the average maximum weight excluding EOS.
  • �� Positional heads select one relative position at least 90% of the time. Syntactic heads are tested on nsubj, dobj, amod, and advmod, allowing both directions.
  • �� Hard Concrete gates approximate L0 with Σ(1−P(gi=0)); the objective is translation cross-entropy plus λ times this penalty.
  • �� Gates are resampled per batch, trained by reparameterization, and discretized at test time. Encoder-only pruning freezes the decoder.

Experiments

The authors use 2.5m parallel sentences for each WMT English–Russian, English–German, and English–French setting, matching the English–Russian training size, plus 6m OpenSubtitles2018 English–Russian sentences. Evaluation includes 50,000 held-out WMT sentences. Models share Transformer parameter settings. BLEU measures translation quality. Experiments compare dense models, fine-tuned pruned models, and randomly initialized models with matching sparse configurations, while gating encoder, decoder self-attention, and decoder–encoder attention separately or jointly.

Results

The WMT English–Russian dense model scores 29.6 BLEU. Reducing encoder self-attention from 48 to 10 heads loses only 0.15 BLEU. On OpenSubtitles, four retained encoder heads lose about 0.25 BLEU. With all attention types gated, a WMT model retaining 14/31/30 encoder, decoder self-attention, and cross-attention heads reaches 29.62 BLEU, versus 29.47 when the same structure is trained from scratch. Cross-attention is retained longest; decoder self-attention matters more for long WMT sentences.

Applications

The method can compress trained translation systems by identifying and deleting redundant attention-head blocks. It also supports model auditing: LRP highlights influential components, while dependency and positional tests characterize their behavior. Translation providers could use this workflow before deployment, but should benchmark actual latency and memory on target hardware because reducing head count alone does not guarantee proportional speedups.

Limitations & Outlook

The evidence is limited to several English-centered translation settings and relatively standard Transformers. CoreNLP parses and threshold-based criteria are imperfect proxies for learned syntax. Freezing the decoder improves attribution but does not characterize fully joint network reorganization. Sparse models trained from scratch underperform pruned dense models, revealing dependence on dense-training redundancy. Future work should compare compression methods, test dynamic gates and larger models, and report end-to-end speed, energy, and kernel efficiency.

Plain Language Accessible to non-experts

Imagine a large restaurant kitchen preparing translations. Every attention head is a cook who examines the sentence and passes useful clues to the final dish. Some cooks always check neighboring ingredients, some determine who did what, and one may search for the rarest ingredient on the table. If we only watched the average activity of the whole kitchen, we would not know who truly matters.

The researchers first trace which cooks affect the final meal most. Then they give each cook a switch and repeatedly turn off less useful workers while trying to preserve the dish’s quality. In the English–Russian experiment, the kitchen had 48 encoder cooks, but 38 could leave with only a 0.15 BLEU decrease. In the subtitle setting, just four cooks were enough to lose roughly 0.25 BLEU.

The lesson is not that extra cooks are useless during training. They may provide backup and make learning easier. But after the recipe is learned, a small group performs the essential work. This makes the translation system smaller and offers clues about how it organizes information.

ELI14 Explained like you're 14

Picture a translation game with 48 tiny teammates. Each teammate watches words in a different way and sends hints to the final translator. One notices nearby words, another spots who is doing an action, and another hunts for weird or uncommon words. Are all 48 equally important? The researchers decided to test it instead of guessing!

They gave every teammate an on/off switch. During training, the system tried shutting down teammates while keeping the translation score high. On the English–Russian task, it could switch off 38 of 48 encoder teammates and lose only 0.15 BLEU. In the subtitle version, only four teammates were needed, with about a 0.25 BLEU loss. That is like winning the same game with a much smaller squad!

The coolest part is that the specialists were the last to be removed. The teammate who always tracks subjects and verbs is like the player who knows the key strategy. Several ordinary teammates may be doing overlapping jobs, so turning one off barely matters.

This could help phone translation run faster and use less memory. But there is a catch: the experiment tested particular languages and models. A trick that works for one game level may fail on another, so researchers must retest it on new languages, bigger models, and real devices.

Glossary

Multi-Head Self-Attention

A mechanism in which multiple attention heads independently compute token-to-token relations and then combine their outputs. Different heads can learn different patterns or roles.

The paper primarily analyzes encoder self-attention heads.

Layer-wise Relevance Propagation (LRP)

An attribution method that propagates a prediction’s relevance backward through network layers. Higher relevance indicates a larger estimated contribution to the selected output.

It ranks heads by contribution to the top-1 predicted logit.

Hard Concrete

A stochastic gate distribution with probability mass at zero and one, making discrete pruning trainable through a differentiable relaxation. It is obtained by stretching and rectifying a Concrete distribution.

It controls whether an attention head remains active.

L0 Regularization

A penalty on the number of nonzero components rather than their magnitudes. It directly encourages a smaller active architecture but is normally nondifferentiable.

The paper approximates it with the expected number of nonzero gates.

BLEU

An automatic machine-translation metric based mainly on n-gram overlap between a system output and reference translations. Higher scores generally indicate closer reference matching.

It measures quality before and after head pruning.

Cross-Attention

Decoder attention whose queries come from the target-side decoder while keys and values come from the encoder. It connects generated words to the source sentence.

The study finds decoder–encoder attention is pruned less readily than encoder self-attention.

Open Questions Unanswered questions from this research

  • 1 Do specialized heads remain stable in much larger Transformers, low-resource languages, and large language models? The present evidence is limited to English-centered NMT and a few domains.
  • 2 Do syntactic heads perform genuine structural reasoning or exploit positional and corpus correlations? Causal interventions, controlled stimuli, and head replacement experiments are needed.
  • 3 Does pruning produce real device-level acceleration? Head counts do not automatically translate into faster kernels, so hardware-aware latency and energy studies remain necessary.

Applications

Immediate Applications

Machine-translation compression

A translation provider can train a dense Transformer, optimize Hard Concrete gates, and export a model with redundant head blocks removed. The WMT English–Russian result suggests that retaining 10 of 48 encoder heads can preserve near-baseline BLEU, subject to hardware validation.

Model behavior auditing

Researchers can use LRP to locate influential heads, then test whether they track adjacency, dependency relations, or rare words. This creates a practical diagnostic for domain shifts and for checking whether a model relies on linguistically plausible signals.

Long-term Vision

Interpretable dynamic Transformers

Future systems could activate different specialized heads for different inputs, combining conditional computation with transparent routing. Obstacles include stable gate learning, multilingual transfer, sparse-kernel support, and preventing quality loss on unusual sentences.

Abstract

Multi-head self-attention is a key component of the Transformer, a state-of-the-art architecture for neural machine translation. In this work we evaluate the contribution made by individual attention heads in the encoder to the overall performance of the model and analyze the roles played by them. We find that the most important and confident heads play consistent and often linguistically-interpretable roles. When pruning heads using a method based on stochastic gates and a differentiable relaxation of the L0 penalty, we observe that specialized heads are last to be pruned. Our novel pruning method removes the vast majority of heads without seriously affecting performance. For example, on the English-Russian WMT dataset, pruning 38 out of 48 encoder heads results in a drop of only 0.15 BLEU.

cs.CL