Abstract
We introduce "talking-heads attention" - a variation on multi-head attention which includes linear projections across the attention-heads dimension, immediately before and after the softmax operation. While inserting only a small number of additional parameters and a moderate amount of additional computation, talking-heads attention leads to better perplexities on masked language modeling tasks, as well as better quality when transfer-learning to language comprehension and question answering tasks.
Introduction
In standard Transformer architectures, multi-head attention splits the model's hidden state into multiple independent "heads." Each head learns to attend to different parts of the input. To maintain computational efficiency, increasing the number of heads necessitates a decrease in the dimensionality of the keys and queries within each head. However, this approach faces a fundamental limitation: as head dimensionality shrinks, the dot-product matching function loses its capacity to represent complex relationships, often leading to performance degradation at high head counts.
Talking-Heads Attention (THA) addresses this by breaking the isolation between heads. By allowing heads to "talk" to each other through linear projections, the model can pool representational power across the heads dimension, maintaining high performance even with extremely low-dimensional keys and queries.
The Talking-Heads Mechanism
The core innovation of THA is the insertion of two learned linear projections into the attention mechanism:
- Logits Projection ($P_l$): This is applied across the attention-heads dimension immediately before the softmax operation. It transforms the raw attention scores (logits) from $h_k$ input heads into $h$ "talking" heads.
- Weights Projection ($P_w$): This is applied immediately after the softmax. It transforms the attention weights from $h$ heads into $h_v$ output heads, which are then used to weight the value vectors.
This structure ensures that each attention function depends on a linear combination of all queries and keys across all heads, rather than just a single pair. This allows the model to scale effectively to a large number of heads, even down to a head dimension of 1.
Experimental Evaluation
The researchers evaluated THA across several major NLP benchmarks using T5, BERT, and ALBERT architectures. Pre-training was conducted on the C4 dataset for T5, and English Wikipedia and BookCorpus for BERT and ALBERT. Downstream performance was measured on GLUE, SuperGLUE, SQuAD (v1.1 and v2.0), and the RACE reading comprehension dataset.
T5 Results
THA consistently outperformed standard multi-head attention in T5 models. While standard multi-head attention saw performance plateau or degrade when moving from 24 to 48 heads, THA continued to improve. As shown in the results, THA achieved superior perplexity and SQuAD scores compared to both standard multi-head and more complex general bilinear attention mechanisms.
ALBERT and BERT Scaling
Similar gains were observed with the ALBERT architecture. A 48-head THA model significantly outperformed the standard 12-head baseline across a wide range of tasks, achieving a higher overall average score of 81.44 compared to 80.32.
Furthermore, scaling experiments with BERT demonstrated that THA quality continues to improve even when pushed to the extreme of 768 heads with a key/query dimensionality of just 1. This confirms that the information exchange facilitated by the projections is highly effective at low dimensions.
Key Insights
- Information Exchange: Visualization of the learned projection matrices reveals they are neither diagonal nor sparse, confirming that the model actively moves significant data across attention heads.
- Efficiency: THA adds a negligible number of parameters and only a moderate amount of computation, providing a cost-effective way to boost model quality.
- Robustness to Scaling: Unlike standard multi-head attention, THA thrives as the number of heads increases, allowing for finer-grained attention patterns without losing representational power.
Conclusion and Future Work
Talking-Heads Attention provides a simple yet powerful modification to the Transformer architecture. By enabling inter-head communication, it overcomes the limitations of standard multi-head attention at high head counts. Future work includes optimizing hardware for the small-dimension matrix operations required by THA and exploring its synergy with other architectural innovations like local or memory-compressed attention mechanisms.
Summary updated