Anisotropy Is Inherent to Self-Attention in Transformers

Nathan Godey, Éric de la Clergerie, Benoît Sagot · DOI

Abstract

Transformer-based models frequently exhibit "anisotropy," a state where hidden representations are highly correlated and cluster within a narrow cone. While previous research attributed this to training objectives or data distributions, this study reveals that anisotropy is an inherent feature of the self-attention mechanism. By examining models across text, vision, and speech, we demonstrate that anisotropy arises as a functional byproduct of the model's requirement for sharp attention patterns.

Introduction: The Representation Degeneration Problem

In an ideal representation space, a model would utilize all available dimensions to distinguish between diverse concepts. However, many Transformer models suffer from representation degeneration, where hidden vectors show high cosine similarity even for unrelated inputs.

Average cosine similarity across layers for standard Transformer-based language models, illustrating the prevalence of anisotropy.

The prevailing theory suggested that optimizing cross-entropy loss on long-tailed word distributions forced representations into a single direction. This paper challenges that view, asking if anisotropy is instead "baked into" the Transformer architecture itself.

Methodology

The researchers employed a three-pronged empirical approach:

  1. Cross-Modality Survey: Measuring anisotropy in character-based NLP models (e.g., CANINE, ByT5), speech models (wav2vec 2.0), and vision models (ViT).
  2. Untrained Block Analysis: Investigating how untrained Transformer blocks respond to input "drift" or constant bias.
  3. Training Dynamics: Tracking the evolution of Query ($Q$) and Key ($K$) distributions during training using Singular Value Decomposition (SVD) on the MultiBERT suite.

Key Insights: Beyond Language and Words

The study's findings suggest that anisotropy is a fundamental architectural trait rather than a data-driven artifact.

It’s Not Just About Words

Anisotropy persists in character-level models and non-linguistic modalities like audio and images. This indicates that the "rare token" theory is insufficient.

The "Sharpness" Trade-off

The paper establishes a link between anisotropy and the "sharpness" of attention. For a Transformer to focus intensely on a specific token (low entropy), the dot products in the self-attention mechanism ($QK^T$) must be large. To achieve this, the distributions of Queries and Keys naturally drift in coordinated directions during training.

Architectural Bias vs. CNNs

Interestingly, most CNN-based vision models remain isotropic throughout their layers, contrasting sharply with Transformers.

Average cosine similarity in vision models. Unlike Transformers, CNN-based architectures like ConvNeXt and VAN maintain low similarity (isotropy).

This divergence suggests that anisotropy is a specific quirk of self-attention layers rather than deep learning in general.

Results and Discussion

The empirical results show that almost every Transformer model tested exhibited significant anisotropy. In MultiBERT, the alignment between $Q$ and $K$ distributions occurs very early in training, often within the first few thousand steps. As training progresses, the entropy of attention distributions decreases while anisotropy increases, reinforcing the functional link between the two.

While anisotropy appears necessary for sharp attention in current architectures, it distorts the geometry of hidden representations. Future research should focus on designing attention mechanisms that can achieve high focus without compromising the isotropic nature of the representation space, potentially leading to more efficient and semantically precise models.

Summary updated

BibTeX
@inproceedings{godey2024anisotropy,
  author = {Nathan Godey and Éric de la Clergerie and Benoît Sagot},
  title = {{Anisotropy Is Inherent to Self-Attention in Transformers}},
  booktitle = {EACL},
  year = {2024},
  url = {https://openreview.net/forum?id=IYO6MBlfLv},
}
Figure