Sparse Attention as Compact Kernel Regression
Saul Santos, Nuno Gonçalves, Daniel C. McNamee, André F. T Martins
TL;DR
This work reframes self-attention in transformers as a kernel-regression problem, showing that standard softmax attention corresponds to a Gaussian kernel while sparse attention can be realized with compact-support kernels. It develops a unified theory in which Epanechnikov, biweight, and triweight kernels map to α-entmax variants (α = 1 + 1/r), with top- extit{k} methods interpreted as data-adaptive truncations, and introduces ReLUmax as a max-anchored Epanechnikov variant. The authors instantiate Memory Mosaics, a kernel-regression–based transformer with contextual and persistent memories, and demonstrate that adaptive, compact kernels yield competitive or superior performance on language modeling, in-context learning, and length generalization. This framework provides a principled approach to designing attention mechanisms with controllable sparsity and locality, bridging theory, architecture, and empirical evaluation.
Abstract
Recent work has revealed a link between self-attention mechanisms in transformers and test-time kernel regression via the Nadaraya-Watson estimator, with standard softmax attention corresponding to a Gaussian kernel. However, a kernel-theoretic understanding of sparse attention mechanisms is currently missing. In this paper, we establish a formal correspondence between sparse attention and compact (bounded support) kernels. We show that normalized ReLU and sparsemax attention arise from Epanechnikov kernel regression under fixed and adaptive normalizations, respectively. More generally, we demonstrate that widely used kernels in nonparametric density estimation -- including Epanechnikov, biweight, and triweight -- correspond to $α$-entmax attention with $α= 1 + \frac{1}{n}$ for $n \in \mathbb{N}$, while the softmax/Gaussian relationship emerges in the limit $n \to \infty$. This unified perspective explains how sparsity naturally emerges from kernel design and provides principled alternatives to heuristic top-$k$ attention and other associative memory mechanisms. Experiments with a kernel-regression-based variant of transformers -- Memory Mosaics -- show that kernel-based sparse attention achieves competitive performance on language modeling, in-context learning, and length generalization tasks, offering a principled framework for designing attention mechanisms.
