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. The connection comes from viewing OLS as a similarity-based prediction rule in a learned embedding space. In this representation, least squares does not estimate coefficients per se. Instead, it selects an embedding that minimizes squared prediction error by matching training and test vectors through inner products. This maps directly onto the query-key-value structure of attention mechanisms. I then discuss extensions to dimensionality reduction, nonlinearity, and time series econometrics. Monte Carlo simulations and real-data experiments on UCI/OpenML benchmarks show that nonlinear Attention Regression performs competitively against standard machine learning baselines. In the reverse direction, I replace the attention sublayer of a transformer for tabular data with an explicit regression on polynomial features. The resulting model performs comparably to the standard transformer at a fraction of its parameter count.
Ordinary Least Squares is a Special Case of Transformer
Center for Peak Performance, Department of Psychology and Behavioral Sciences, Zhejiang University(高峰表现中心,心理学与行为科学系,浙江大学);Hangzhou Higgs Asset Management Co., Ltd.(杭州恒辉资产管理有限公司);College of Control Science and Engineering, Zhejiang University(控制科学与工程学院,浙江大学)