NeurIPS 2026Coming to NeurIPS in Sydney?Explore papers, orals & directions

Ordinary Least Squares as an Attention Mechanism

Philippe Goulet CoulombeNeurIPS 2026

TL;DR

What if the trendy attention mechanism powering modern Large Language Models is secretly doing something statisticians have understood for two centuries? This paper reveals that Ordinary Least Squares (OLS) linear regression is mathematically identical to a simplified attention module, where predictions are just similarity-weighted averages of training data. Understanding this bridge takes the mystery out of Transformers and unlocks super-efficient hybrid models that rival deep tabular architectures at a fraction of the size.

What Problem Does This Paper Address?

When Vaswani et al. introduced the Transformer, they framed self-attention using concepts from information retrieval: Queries ($Q$), Keys ($K$), and Values ($V$). While wildly successful in deep learning, this formulation can feel alien and opaque to researchers trained in classical, applied statistics.

Previously, researchers tried to understand attention by training massive Transformers on regression tasks to see if they learn to mimic least squares (the in-context learning literature), or by comparing softmax attention to non-parametric kernel smoothers. Author Philippe Goulet Coulombe flips the question entirely: instead of asking what regression algorithm a trained Transformer learns, what attention mechanism does plain old, unmodified OLS already contain?

Methods

The paper establishes a mathematical equivalence by reframing how OLS makes predictions, then tests the bridge in both directions.

Figure 1: Roadmap: Three equivalent views of OLS predictions. Left: Coefficient-based formulation. Middle: Similarity-based interpretation—predictions as weighted averages of training outcomes in a transformed space. Right: Restricted attention module with identity activation.
  1. The Algebraic Equivalence: Normally, we think of OLS as finding a vector of slope coefficients ($\hat{\beta}$) to multiply with new test features. By taking the eigendecomposition of the inverse covariance matrix $(\mathbf{X}_{\text{train}}'\mathbf{X}_{\text{train}})^{-1}$, the author splits the prediction formula into two identical mappings. Both training and test features are projected into an uncorrelated, orthonormal space. Here, a test prediction is simply the inner product (similarity) between the transformed test point ($Q$) and every transformed training point ($K$), multiplied by the training outcomes ($V$). Swap the Transformer's softmax for an identity activation, and OLS is cross-attention.
  2. Attention Regression (Statistics $\to$ ML): Reintroducing the softmax nonlinearity and multi-head projections turns this OLS-attention module into a flexible, non-parametric estimator. Crucially, the author uses the closed-form ridge regression embedding to warm-start (initialize) the attention heads before gradient descent.
  3. The Regression Block (ML $\to$ Statistics): Going the reverse direction, the author rips the multi-head softmax attention sublayer out of a tabular Transformer (FT-Transformer) and replaces it with explicit regression: token representations are expanded into degree-2 polynomial cross-features, compressed via frozen PCA to 200 components, and passed through a ridge-initialized linear regression layer.

Datasets

No new benchmarks are introduced; instead, the paper relies on controlled simulations and standard tabular benchmarks:

  • Simulated Data: Monte Carlo experiments across 6 standard Data Generating Processes (Linear, Friedman 1–3, Rotated Sine, and Soft Radial), varying sample sizes ($N \in \{500, \dots, 5000\}$) and signal-to-noise ratios.
  • Real Data: 8 standard UCI/OpenML tabular regression benchmarks (California, Yacht, Energy, Concrete, Airfoil, Abalone, Kin8nm, Protein), plus additional extensions to higher-dimensional datasets (up to 81 features) and 6 classification datasets.

Key Insights and Ideas

  • OLS leads a double life: We usually view linear regression as correlation-based, and $k$-Nearest Neighbors ($k$-NN) as proximity-based. In reality, OLS is a smooth proximity-based estimator operating in a decorrelated space.
  • Negative attention is a feature, not a bug: Because Transformers use softmax, attention weights are strictly positive and sum to one (making them close cousins to Random Forests). OLS, lacking softmax, happily assigns negative attention weights—meaning a training point that is the polar opposite of your test point contributes with an opposite sign. Giving up the softmax simplex constraint turns out to be surprisingly helpful on tabular data.
  • Classical tricks map directly to $W_Q W_K'$: In this framework, the product of Query and Key weight matrices acts like a precision matrix (inverse covariance). Classical statistical tools immediately gain attention counterparts: Principal Component Regression (PCR) equals low-rank attention projections (like multi-head compression), and Ridge shrinkage simply damps low-variance directions in the attention embedding.
  • Linear depth collapses: Stacking multiple linear attention layers—even with residual connections—just multiplies inputs by a chain of fixed matrices, collapsing back into a single OLS prediction at the optimum. Genuine representational power requires nonlinearities (like MLPs or polynomial expansions) between layers.

Key Results

  • Simulations: Across 96 simulated conditions, the 5-head Attention Regression model achieved an average out-of-sample $R^2$ of 0.48 (with zero per-dataset tuning), beating OLS (0.28) and Gradient Boosting (0.42), edging out Random Forests (0.45), and trailing just behind an MLP (0.52).
  • Tabular Benchmarks: The Regression Block outperformed the canonical FT-Transformer on all 8 UCI/OpenML benchmarks by small margins (e.g., reaching 0.920 vs. 0.914 $R^2$ on Kin8nm, and 0.907 vs. 0.898 on Concrete).
  • Massive Parameter Efficiency: The Regression Block achieved this while being 1 layer deep instead of 3, using roughly 30% of the parameters (~30K vs. ~100K). In extreme ablations, cutting the Regression Block down to just 7,500 parameters (7.4% of FT-Transformer) still kept it within $0.005$ mean $R^2$ of the full Transformer.

Limitations and Future Work

  • Local vs. Global Equivalence: The exact mathematical equivalence only holds for a single restricted attention module. Once you add LayerNorm and feed-forward nonlinearities in a deep Transformer, the regression interpretation becomes strictly local to the representations entering each individual block.
  • Quadratic Feature Bottleneck: The Regression Block relies on computing degree-2 polynomial cross-features across inputs. The number of cross-features grows quadratically with input dimensionality, creating a computational bottleneck when scaling well beyond standard tabular feature counts.
  • Future Directions: Viewing $W_Q W_K'$ as an inverse covariance matrix opens a rich pipeline for importing decades of high-dimensional covariance estimation techniques—such as Ledoit-Wolf linear shrinkage, thresholding/sparsification, and factor models—directly into attention initialization and regularization.

Summary updated

Abstract

I show that ordinary least squares (OLS) predictions can be rewritten as a restricted attention module, akin to those at the heart of transformer architectures. This connection emerges by reframing OLS as a similarity-based prediction rule operating in a learned embedding space. From this perspective, least squares does not estimate coefficients per se, but instead selects an embedding that minimizes squared prediction error by matching training and test vectors through inner products — mapping naturally onto the query-key-value structure of attention. I then extend the framework to dimensionality reduction, nonlinearity, and connections to time series econometrics. Monte Carlo simulations and real-data experiments on UCI/OpenML benchmarks show that a direct implementation of nonlinear Attention Regression performs competitively against standard machine learning baselines. In the other direction, within a transformer architecture for tabular data, an attention block can be replaced by an explicit regression on polynomial-expanded features, matching or exceeding the standard transformer's predictive accuracy at a fraction of its parameter count.
BibTeX
@inproceedings{coulombe2026ordinary,
  author = {Philippe Goulet Coulombe},
  title = {{Ordinary Least Squares as an Attention Mechanism}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=MRyrIW18CW},
}
Figure