Benign Overfitting in Single-Head Attention

Roey Magen, Shuning Shang, Zhiwei Xu, Spencer Frei, Wei Hu, Gal Vardi

Introduction

In classical statistics, overfitting is traditionally viewed as a fundamental flaw: if a model fits the training data too perfectly—memorizing the noise alongside the signal—its performance on unseen data will inevitably suffer. However, modern deep learning models routinely break this rule, achieving 100% training accuracy on noisy datasets while still generalizing remarkably well. This phenomenon is known as benign overfitting.

While benign overfitting has been mathematically proven for linear models and simple convolutional networks, it has remained a mystery for Transformers. Given that Transformers dominate modern artificial intelligence, understanding whether their fundamental building block—the attention mechanism—shares this property is crucial. This paper provides the first theoretical proof that a single-head attention model exhibits benign overfitting, demonstrating that it can perfectly memorize noisy training data while maintaining near-optimal generalization, provided the signal-to-noise ratio (SNR) is sufficiently high.

Methods and Experimental Setup

The authors analyze a single-head softmax attention model, the basic unit used to process sequences in Transformer architectures. They focus on a binary classification task where each data point consists of multiple "tokens": one signal token (carrying the true label) and several noise tokens (random Gaussian noise).

The study investigates two primary learning scenarios:

  1. Gradient Descent (GD): Jointly optimizing the attention weights and the classification head using a standard logistic loss.
  2. Max-Margin/Min-Norm Interpolators: Finding the solution that fits the data with the largest possible "margin," which is often the implicit goal of training with weight decay.

The researchers define a critical metric for their analysis: the Signal-to-Noise Ratio (SNR), calculated as the ratio between the norm of the signal tokens and the noise tokens.

Datasets

The paper relies primarily on synthetic datasets designed to isolate the interaction between signal and noise. In these sets, labels are "flipped" with a certain probability ($\eta$) to simulate noisy real-world data. To ensure their theoretical findings translate to practice, the authors also conducted experiments on binary versions of MNIST and CIFAR-10 with added label noise to test the SNR thresholds predicted by their mathematics.

Key Insights

  • The Two-Step Memorization: One of the most striking findings is that benign overfitting can happen in just two iterations of gradient descent. In the first step, the model learns the signal. In the second step, it adjusts its attention to "hide" the noisy, mislabeled examples in the noise tokens, allowing it to fit the noise without corrupting the signal it already learned.
  • The $1/\sqrt{n}$ Threshold: The researchers identified a "phase transition" for overfitting. If the SNR is at least $\Omega(1/\sqrt{n})$ (where $n$ is the number of samples), the overfitting is benign. If the signal is weaker than this, the overfitting becomes harmful, and test accuracy plummets.
  • Attention as a Dynamic Filter: The model doesn't just learn a static weight for features; it learns to dynamically shift its attention. For clean examples, it focuses on the signal token. For noisy (mislabeled) examples, it learns to focus on the noise tokens to satisfy the training requirement without affecting how it treats new, clean data.

Key Results

  • Theoretical Guarantee: The authors prove that under high-dimensional conditions, Gradient Descent achieves 100% training accuracy and near-optimal test accuracy simultaneously.
  • Tightness of the Bound: The mathematical proofs show that the SNR requirement is "tight." If the SNR falls below the $1/\sqrt{n}$ threshold, the model reliably exhibits harmful overfitting.
  • Empirical Validation: Experimental heatmaps perfectly match the theoretical curve, showing a sharp boundary between generalization and failure based exactly on the predicted SNR and sample size.
Heatmap demonstrating the phase transition between harmful and benign overfitting based on SNR and sample size.

Limitations and Future Work

While this research is a significant step forward in understanding Transformer generalization, the authors acknowledge several limitations:

  • Model Complexity: The study focuses on a single-head, single-layer attention model. Real-world Transformers use hundreds of heads and dozens of layers. While the authors include some multi-head/multi-layer experiments in the appendix, a full theoretical proof for deep architectures is still needed.
  • Data Assumptions: The proofs rely on the assumption that noise tokens are nearly orthogonal, which typically requires very high-dimensional input ($d \gg n^2$). Empirical results suggest benign overfitting happens even at lower dimensions, indicating the current mathematical assumptions might be stricter than necessary.
  • Token Structure: The data model assumes a clear separation between "signal" and "noise" tokens, whereas in natural language, signal and noise are often intertwined within the same tokens.

Future research will likely investigate how these dynamics change in multi-layer "deep" Transformers and whether these SNR thresholds can be leveraged to better regularize models during training.

Summary updated

BibTeX
@inproceedings{magen2025benign,
  author = {Roey Magen and Shuning Shang and Zhiwei Xu and Spencer Frei and Wei Hu and Gal Vardi},
  title = {{Benign Overfitting in Single-Head Attention}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=ud7VVZ693U},
}
Figure