When an attention head decides how strongly one token should read another, it takes a dot product of two vectors and treats the result as a similarity score. That is the smallest possible version of an idea that is sixty-two years old and that predates transformers, support vector machines, and even the perceptron's mainstream success: the kernel trick. It says that an algorithm which needs nothing more than inner products between data points can be run in a feature space it never constructs, a space that may have thousands or infinitely many dimensions. The model gets the geometry without paying for the coordinates.
This explainer covers what the trick is, where it came from, why it lost to deep learning, and why it never actually left the transformers you use today.
The trick in one paragraph
Suppose you want a linear classifier for data that is not linearly separable in its own coordinates. The classic fix is to map every point into a richer space where a straight line (more precisely, a hyperplane) can separate the classes. A two-dimensional point might go to three or more dimensions, quadratic terms and cross terms included.
Here is the catch. The linear algorithm never needs to see those coordinates. It only ever needs pairwise inner products between points. And in many cases, the inner product in the lifted space can be computed as a simple function of the original inputs. Squaring the dot product of two vectors, for example, equals the inner product of the two vectors after they have been mapped into the space of all their pairwise products. You get a degree-2 polynomial model while computing nothing more expensive than a dot product.
The function that returns the lifted inner product without the lift is the kernel. The move of substituting k(x, y) for the raw dot product of the mapped vectors, and never materializing the feature map, is the kernel trick. When you hear a kernel like the radial basis function written as k(x, y) = exp(-||x - y||^2 / 2*sigma^2), read it as a compressed description of an infinite-dimensional feature space. The mathematical guarantee that such functions correspond to genuine inner products is Mercer's theorem, published in 1909 by the English mathematician James Mercer, decades before anyone thought of using it in machine learning.

Moscow, 1964, and the potential method
The trick first appears as an algorithm, not a theorem. In 1964 the Soviet control theorists Mark Aizerman, Emmanuel Braverman and Lev Rozonoer published "Theoretical Foundations of the Potential Function Method in Pattern Recognition Learning" in the journal Automation and Remote Control. Their potential function algorithm learned by placing a bump function, a kernel, on every misclassified example and summing the bumps; convergence was proved by interpreting those sums as inner products in an abstract space. That is the kernel trick in its earliest published form, per Helmut Hofmann's survey of kernel methods, which credits Aizerman and colleagues with bringing the notion of kernels as Hilbert-space inner products into machine learning. A second, independent origin came from statistics: in 1971 George Kimeldorf and Grace Wahba showed that an infinite-dimensional smoothing problem over all functions has its optimum inside the span of kernel functions centered at the training points. That result, generalized as the representer theorem, is the reason kernel machines are always finite combinations of data points, no matter how large the feature space.
The support vector machine years
The trick became a household algorithm in 1992, when Bernhard Boser, Isabelle Guyon and Vladimir Vapnik presented an optimal-margin classifier at the COLT workshop. The insight was that the perceptron's training solution could be rewritten so that the input vectors appear only inside inner products. Replace those with a kernel and you get a learner that draws maximum-margin boundaries in polynomial or radial-basis feature spaces while computing nothing but similarity scores. The training data entering the final model as a weighted sum are the support vectors, the examples closest to the boundary. Cortes and Vapnik's 1995 journal version extended it to noisy, non-separable data and launched the field: the 1992 paper has close to 20,000 citations, and throughout the late 1990s SVMs beat neural networks on real tasks like handwritten digit recognition.
The theory underwriting that confidence was Vapnik's own statistical learning theory, which bounds generalization error using the capacity of the hypothesis class rather than its parameter count. Neural networks were losing the 1990s in part because they had no comparable story.
The cost, and the retreat
Kernels have a structural bill. Fitting one means forming the Gram matrix of pairwise similarities for every training point: n squared entries for n examples, and the solve itself is worse. On modern datasets that is the bottleneck, not the memory of the feature map, which the trick never actually materializes. Rahimi and Recht's random features paper from NeurIPS 2007 was the direct answer: approximate a shift-invariant kernel by explicit random feature vectors so you can use fast linear solvers again. It reframed the trick in the other direction, from never building coordinates to building cheap ones.
Then gradient descent on deep networks got cheaper, GPUs scaled, and around 2012 the kernel paradigm quietly stopped being the frontier. The standard account is that the kernel trick lost the marketing war while keeping the substance: almost every modern architecture is doing something that a kernel person would recognize.
Attention is (literally) a kernel machine

The cleanest result in that direction is Transformer Dissection by Yao-Hung Hubert Tsai and colleagues at EMNLP 2019, which reformulated attention as a kernel smoother over inputs, the attention weights being kernel evaluations between tokens. The mechanism is easier to see in its simplest form. Softmax attention computes a weighted average of value vectors, the weights proportional to exp(q · k / sqrt(d)). That is exactly the Nadaraya-Watson estimator of kernel regression, independently proposed by Eugene Nadaraya and Geoffrey Watson in 1964: predict by averaging nearby training outputs, weighted by a similarity kernel. Goel and Bartlett proved in 2023 that a self-attention block can represent a Nadaraya-Watson estimator with a Gaussian kernel exactly. Read that alongside the modern Hopfield-network account of attention and the picture is consistent: every forward pass through a transformer is doing nonparametric regression over the key-value pairs currently in the context window, with an exponential kernel in place of a Gaussian one.
This reframing gives in-context learning a precise meaning. The model's weights store no fact about the example that just appeared in the prompt; the attention mechanism performs a kernel-smoothing lookup over it at inference time, no gradient update required.
The engineering lineage matters too. Choromanski and colleagues' Performer (2020) showed that the softmax kernel in attention can be approximated by random feature maps, which is straight out of Rahimi and Recht, and in exchange removes the quadratic memory of exact attention. The whole modern linear-attention and state-space line, the one that leads to Mamba and today's hybrid models, is an argument about which kernel approximation is cheapest at scale.
The kernel theory that survived in the limits
One kernel descendant lives on in mainstream scaling research. Jacot, Gabriel and Hongler showed in 2018 that a neural network, trained by gradient descent in the limit of infinite width, does not behave like a network at all. Its function updates follow a fixed kernel regression, the neural tangent kernel. For that special case the training dynamics are analytically tractable and the network is a kernel machine. Real networks are far from that limit, and the claim that deep learning is secretly kernel regression in practice is not settled science; the honest version is that the NTK gives theorists a solvable model of what width buys, and it remains a standard tool in generalization analysis.
Why anyone still uses kernels directly
Outside transformers, kernel methods never went away where their strengths matter: small data, strict guarantees, and explicit uncertainty. Gaussian processes are kernel regression with calibrated error bars by construction, which is why Bayesian optimization, the standard way to tune expensive experiments, runs on kernels. scikit-learn still ships SVC as a supported classifier, and gradient-boosted trees have largely taken the tabular space where kernels once stood.
The trick's real legacy is conceptual. It taught the field that what a learning algorithm needs from a representation is not coordinates but a similarity function, and once you accept that, you can work in spaces you never build. That is a sentence that describes attention as precisely as it describes a support vector machine, sixty-two years apart.
Sources
- Aizerman, Braverman, Rozonoer, "Potential Functions in Mathematical Pattern Recognition" (IEEE reference to the 1964 Avtomatika i Telemekhanika paper)
- Hofmann, Schölkopf, Smola, "Kernel Methods in Machine Learning" (Statistics and Computing survey)
- Mercer, "Functions of Positive and Negative Type", Phil. Trans. R. Soc. A, 1909
- Kimeldorf and Wahba, "Some results on Tchebycheffian spline functions", JMAA 1971
- Boser, Guyon, Vapnik, "A training algorithm for optimal margin classifiers", COLT 1992
- Cortes and Vapnik, "Support-vector networks", Machine Learning 20, 1995
- Rahimi and Recht, "Random Features for Large-Scale Kernel Machines", NIPS 2007
- Tsai et al., "Transformer Dissection: A Unified Understanding of Transformer's Attention via the Lens of Kernel", EMNLP 2019
- Nadaraya, "On Estimating Regression", Theory of Probability and Its Applications 9, 1964
- Watson, "Smooth regression analysis", Sankhya 26, 1964
- Goel et al., "Can a Transformer Represent a Kalman Filter?", 2023
- Ramsauer et al., "Hopfield Networks is All You Need", 2020
- Choromanski et al., "Rethinking Attention with Performers", 2020
- Jacot, Gabriel, Hongler, "Neural Tangent Kernel: Convergence and Generalization in Neural Networks", 2018
- scikit-learn SVC documentation
