Ordinary Least Squares as an Attention Mechanism

Philippe Goulet Coulombe
4/13/2025
cs.LGecon.EMmath.ST
transformer-attention

No confident code implementation found for this paper.

Abstract

I show that ordinary least squares (OLS) predictions can be rewritten as the output of a restricted attention module, akin to those forming the backbone of large language models. This connection offers an alternative perspective on attention beyond the conventional information retrieval framework, making it more accessible to researchers and analysts with a background in traditional statistics.

Show full abstract

It falls into place when OLS is framed as a similarity-based method in a transformed regressor space, distinct from the standard view based on partial correlations. In fact, the OLS solution can be recast as the outcome of an alternative problem: minimizing squared prediction errors by optimizing the embedding space in which training and test vectors are compared via inner products. Rather than estimating coefficients directly, we equivalently learn optimal encoding and decoding operations for predictors. From this vantage point, OLS maps naturally onto the query-key-value structure of attention mechanisms. Building on this foundation, I discuss key elements of Transformer-style attention and draw connections to classic ideas from time series econometrics.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{coulombe2025ordinary,
  title  = {Ordinary Least Squares as an Attention Mechanism},
  author = {Philippe Goulet Coulombe},
  year   = {2025},
  eprint = {2504.09663},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2504.09663v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2504.09663.svg)](https://codeofpaper.com/paper/2504.09663)

Discussion