Transformers as Support Vector Machines

Davoud Ataee Tarzanagh, Yingcong Li, Christos Thrampoulidis, Samet Oymak

TL;DR

This paper establishes a formal mathematical equivalence between the self-attention mechanism in transformers and hard-margin Support Vector Machines (SVMs). It demonstrates that training attention layers with gradient descent implicitly biases the model toward sparse token-selection solutions, where over-parameterization (a large embedding dimension) acts as a crucial catalyst for reaching globally optimal configurations.

What Problem Does This Paper Address?

Despite the ubiquity of transformers, our theoretical understanding of why their core component—self-attention—works so effectively remains incomplete. Specifically, researchers have struggled to characterize the optimization landscape of attention and the "implicit bias" of gradient descent (GD). Implicit bias refers to the tendency of an optimization algorithm to converge to specific types of solutions among the many that could technically fit the training data.

In linear classification, it is well-known that GD on logistic loss converges toward the hard-margin SVM solution. The authors ask: Does the softmax-based attention layer exhibit a similar geometric bias? How does the layer decide which tokens to "select" and "compose" when trained?

Figure 3: Implicit biases of the atten- tion layer and logistic regression.

Methods

The authors bridge the gap between deep learning and classical learning theory by establishing a formal equivalence between the optimization of a 1-layer transformer and a new problem they call Att-SVM.

Key methodological steps include:

  • SVM Formalism: They define a convex hard-margin SVM problem that separates "optimal" tokens (those that contribute most to the correct prediction) from "non-optimal" tokens using linear constraints on the outer products of token pairs.
  • Regularization Path (RP) Analysis: They study the directional convergence of attention weights as the regularization vanishes (or as training time goes to infinity).
  • Parameterization Comparison: They distinguish between directly parameterizing the combined weight matrix $W$ versus the standard transformer approach of using separate Key ($K$) and Query ($Q$) matrices ($W = KQ^\top$).
  • Geometric Analysis: They identify specific conditions (like token score gaps and initial gradient directions) that guarantee gradient descent will find the globally optimal token-selection direction.

Datasets

The paper primarily utilizes synthetic datasets to rigorously verify its theoretical claims. This approach allows the authors to precisely control variables like:

  • Embedding dimension ($d$): To study the effects of over-parameterization.
  • Sequence length ($T$): To test long-range dependency handling.
  • Number of samples ($n$): To evaluate feasibility under different data regimes.

Tokens are typically sampled from unit spheres or IID isotropic distributions, with binary labels assigned based on token scores. The authors also provide code for these experiments on GitHub.

Key Insights and Ideas

  • Attention as Token Selection: The "aha moment" is viewing attention not just as a weighting mechanism, but as a margin-maximization engine. The layer is essentially trying to find a hyperplane that separates the "best" token in a sequence from all others by the largest possible margin.
  • The Low-Rank Bias of (K, Q): The authors prove that the standard $(K, Q)$ parameterization leads to a nuclear-norm SVM objective, which naturally encourages low-rank solutions. In contrast, directly parameterizing $W$ leads to a Frobenius-norm objective. This formally explains why transformers are naturally biased toward low-rank attention patterns.
  • Over-parameterization is a Catalyst: In many models, having too many parameters leads to overfitting. Here, a large embedding dimension $d$ actually helps by ensuring the SVM problem is feasible and by "cleaning up" the optimization landscape, removing spurious local minima that could trap gradient descent.
  • Hard vs. Soft Attention: The theory shows that linear prediction heads lead to "hard attention" (selecting one token). However, they generalize the theory to show that non-linear heads (like MLPs) necessitate "soft attention," where the model must compose multiple tokens to minimize loss.

Key Results

  • Global Convergence: The authors prove that under mild conditions, GD iterates converge in direction to the globally optimal SVM solution. Experimental results in Figure 2 show that as the dimension $d$ increases, the probability of reaching this global solution approaches 100%.
Figure 1: GD convergence during training of cross-attention weight W or (K, Q) with data. Teal and yellow markers represent tokens from X1 and X2, while stars mark optimal tokens. Solid lines in Figures (a) and (b) depict Att-SVM and Att-SVM⋆directions mapped to z1 (red) and z2 (blue), respectively. Arrows illustrating GD trajectories converging towards these SVM directions. Red and blue dotted lines represent the corresponding separating hyperplanes.
  • Rank Boundedness: They prove (and experimentally validate in Figure 4) that the rank of the resulting attention SVM solution is bounded by the number of samples $n$, providing a theoretical rationale for why transformers work well even when the embedding dimension is much larger than the number of training sequences.
  • Non-linear Generalization: Their generalized SVM formulation for non-linear heads (MLPs) shows a remarkably high correlation (>0.99) with the actual solutions found by GD in high-dimensional settings.

Limitations and Future Work

  • 1-Layer Limitation: The current proof focuses on 1-layer transformers. While the authors hypothesize that multi-layer transformers act as a "hierarchy of SVMs," the formal proof for deep architectures remains an open challenge.
  • Fixed Prediction Heads: Most of the theoretical analysis assumes a fixed prediction head $h(\cdot)$. In practice, the attention weights and the prediction head are optimized jointly, which adds another layer of complexity to the optimization landscape.
  • Asymptotic Nature: The results characterize directional convergence as weights grow very large ($R \to \infty$). Characterizing the non-asymptotic convergence rates (how fast it gets there) is a suggested area for future research.

Summary updated

BibTeX
@inproceedings{tarzanagh2023transformers,
  author = {Davoud Ataee Tarzanagh and Yingcong Li and Christos Thrampoulidis and Samet Oymak},
  title = {{Transformers as Support Vector Machines}},
  booktitle = {M3L @ NeurIPS},
  year = {2023},
  url = {https://openreview.net/forum?id=gLwzzmh79K},
}
Figure