Skip to main content
QUICK REVIEW

[Paper Review] On the Expressive Power of Self-Attention Matrices

Valerii Likhosherstov, Krzysztof Choromański|arXiv (Cornell University)|Jun 7, 2021
Gene expression and cancer classificationBiochemistry, Genetics and Molecular Biology40 references5 citations
TL;DR

This paper demonstrates that a fixed self-attention mechanism can approximate any sparse attention matrix—where each row and column has a bounded number of non-zero elements—by only modifying the input, with the hidden dimension $ d $ growing logarithmically in sequence length $ L $. The key result is a constructive proof using random projections and the Johnson-Lindenstrauss lemma, showing $ d = O(\log L) $ suffices for high-precision approximation of input-dependent sparse patterns.

ABSTRACT

Transformer networks are able to capture patterns in data coming from many domains (text, images, videos, proteins, etc.) with little or no change to architecture components. We perform a theoretical analysis of the core component responsible for signal propagation between elements, i.e. the self-attention matrix. In practice, this matrix typically exhibits two properties: (1) it is sparse, meaning that each token only attends to a small subset of other tokens; and (2) it changes dynamically depending on the input to the module. With these considerations in mind, we ask the following question: Can a fixed self-attention module approximate arbitrary sparse patterns depending on the input? How small is the hidden size $d$ required for such approximation? We make progress in answering this question and show that the self-attention matrix can provably approximate sparse matrices, where sparsity is in terms of a bounded number of nonzero elements in each row and column. While the parameters of self-attention are fixed, various sparse matrices can be approximated by only modifying the inputs. Our proof is based on the random projection technique and uses the seminal Johnson-Lindenstrauss lemma. Our proof is constructive, enabling us to propose an algorithm for finding adaptive inputs and fixed self-attention parameters in order to approximate a given matrix. In particular, we show that, in order to approximate any sparse matrix up to a given precision defined in terms of preserving matrix element ratios, $d$ grows only logarithmically with the sequence length $L$ (i.e. $d = O(\log L)$).

Motivation & Objective

  • To understand the expressive power of self-attention matrices in Transformers, particularly under practical constraints like sparsity and dynamic input dependence.
  • To determine the minimal hidden dimension $ d $ required for a fixed self-attention module to approximate arbitrary sparse attention patterns.
  • To establish theoretical bounds on approximation precision and sequence length dependence, focusing on input-dependent sparsity patterns.
  • To provide a constructive algorithm for finding inputs and fixed attention parameters that yield desired sparse attention matrices.

Proposed method

  • Uses random projection techniques to embed input tokens into a lower-dimensional space where attention patterns can be approximated.
  • Applies the Johnson-Lindenstrauss lemma to preserve pairwise distances between token representations under projection, ensuring stability in attention weight ratios.
  • Constructs a target sparse matrix $ B $ from the desired attention pattern, with bounded non-zero entries per row and column.
  • Defines a transformation of the attention matrix into a logarithmic space to control magnitude and sparsity, enabling concentration bounds.
  • Employs a union bound over all relevant token pairs to bound the probability of approximation error exceeding a threshold $ \epsilon_2 $.
  • Derives a sufficient condition on $ d $ such that the probability of successful approximation exceeds $ 1 - \delta $, leading to $ d = O(\log L) $.

Experimental results

Research questions

  • RQ1Can a fixed self-attention module with small $ d \ll L $ approximate arbitrary sparse attention matrices through input variation?
  • RQ2What is the minimal hidden dimension $ d $ required to approximate any sparse attention matrix up to a given precision?
  • RQ3How does the required $ d $ scale with sequence length $ L $ when approximating input-dependent sparse patterns?
  • RQ4Can the approximation be made constructive, with explicit algorithms for input and parameter selection?
  • RQ5Does the Johnson-Lindenstrauss lemma enable stable, low-dimensional approximation of attention matrices while preserving element-wise ratios?

Key findings

  • A fixed self-attention mechanism can approximate any sparse attention matrix with $ d = O(\log L) $, where $ d $ is the hidden dimension and $ L $ is the sequence length.
  • The approximation preserves attention weight ratios up to a user-defined precision $ \epsilon_2 $, with high probability $ \geq 1 - \delta $.
  • The required $ d $ grows logarithmically with $ L $, which is significantly more efficient than linear or polynomial scaling.
  • The proof is constructive, enabling an algorithm to compute input embeddings and fixed attention parameters that yield a desired sparse attention matrix.
  • The method relies on random projections and Johnson-Lindenstrauss-type concentration bounds to ensure stability and accuracy in the low-dimensional embedding space.
  • Empirical validation confirms that $ d $ in the range of 300–1000 suffices for $ k=2 $ and $ L $ up to several hundred, aligning with theoretical predictions.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.