Dictionary of Applied Machine Learning
Typeset PDF version — the authoritative form of this entry
Many machine learning (ML) applications involve data points whose features form numeric arrays. Examples include the color intensities of image pixels and the amplitudes at regular intervals of a sensor signal. Another example is the embeddings of tokens used by large language models (LLMs). These numeric arrays can be naturally represented by vectors in some vector space. Many ML methods rely on measuring the similarity between vectors that represent data points. Each neuron of an artificial neural network (ANN) matches its input against a learned template. The attention unit of an LLM compares the query vector of a token with the key vector of another token. An inner product is a precise mathematical formalization of a notion of similarity between two vectors in a vector space.
Consider a vector space $\vecspace$ over the field of real numbers $\reals$. An inner product in $\vecspace$ is a function \[ \innerprod{\cdot}{\cdot}: \vecspace \times \vecspace \to \reals \] that satisfies the following properties for all $\vu, \vv, \vw \in \vecspace$ and all scalars $\expcoeff \in \reals$ (Axler, 2015, Ch. 6):
For the Euclidean space $\vecspace = \reals^{\featuredim}$, the standard inner product, also called the dot product, is $\innerprod{\featurevec}{\featurevec'} = \featurevec^{\top} \featurevec' = \sum_{\featureidx=1}^{\featuredim} \feature_{\featureidx} \feature'_{\featureidx}$ (Strang, 2016, Sect. 1.2). Geometrically, the inner product determines orthogonal projections: the orthogonal projection of $\featurevec'$ onto the direction of a nonzero vector $\featurevec$ has the signed length $\innerprod{\featurevec}{\featurevec'} / \norm{\featurevec}$ (Axler, 2015, Ch. 6) (see Fig. 1).
The inner product also defines the angle $\theta$ between two nonzero vectors $\featurevec, \featurevec' \in \reals^{\featuredim}$, via $\cos \theta \defeq \innerprod{\featurevec}{\featurevec'} / \big( \norm{\featurevec} \norm{\featurevec'} \big)$. The Cauchy-Schwarz inequality ensures that this ratio lies in $[-1, 1]$ (Axler, 2015, Ch. 6). For the Euclidean plane $\reals^{2}$, the angle defined in this way agrees with the elementary geometric angle between the two vectors (Strang, 2016, Sect. 1.2).
It is important to note that there are also other choices for an inner
product on the Euclidean space $\reals^{\featuredim}$ (Axler, 2015, Ch. 6).
As a case in point, each symmetric and positive definite matrix
$\mA \in \reals^{\featuredim \times \featuredim}$
induces an inner product $\innerprod{\featurevec}{\featurevec'} \defeq \featurevec^{\top} \mA \featurevec'$.
Different choices of an inner product result in different notions of
similarity and, in turn, different notions of nearest neighbors
(a numerical example is given in pythondemos/innerproduct.py).
pythondemos/innerproduct.py
In machine learning (ML), an inner product serves as a measure of similarity. An embedding encodes the meaning of a text block as a vector in a vector space. The alignment of two text blocks is measured by an inner product of their corresponding embeddings (Goodfellow et al., 2016, Sect. 15.4). Each neuron of an artificial neural network (ANN) matches its input vector against a vector of learned model parameters (Goodfellow et al., 2016, Ch. 6). Attention scores in a large language model (LLM) are scaled inner products between query and key vectors (Vaswani et al., 2017).
These examples share a common pattern: many ML methods access the feature vectors of data points only through inner products. For a linear model, each hypothesis is of the form \[ \hypothesis(\featurevec) = \innerprod{\weights}{\featurevec} \text{,} \] which is the same template matching that a neuron applies to its input. The empirical risk minimization (ERM) objective function, the average loss on a training set $\trainset = \big\{ \big(\featurevec^{(\sampleidx)}, \truelabel^{(\sampleidx)}\big) \big\}_{\sampleidx=1}^{\samplesize}$, therefore depends on the feature vectors only through the inner products $\innerprod{\weights}{\featurevec^{(\sampleidx)}}$. A linear classifier such as the support vector machine (SVM) computes its prediction from the inner product $\innerprod{\weights}{\featurevec}$ between the model parameters and the feature vector, and kernel methods extend linear models to arbitrary feature spaces by evaluating inner products between transformed feature vectors via a kernel (Schölkopf and Smola, 2002). For all these ML methods, the choice of the inner product determines the notion of similarity in use and, in turn, the hypothesis learned from a training set.
Synonyms: scalar product, dot product.
See also: field, norm, vector, Hilbert space, orthogonality condition, metric space, Euclidean space, Cauchy-Schwarz inequality, kernel, neuron, attention, principal component analysis, $k$-nearest neighbors.
@misc{dictml_innerproduct,
author = {Jung, Alexander},
title = {inner product},
howpublished = {Dictionary of Applied Machine Learning (course edition)},
year = {2026},
doi = {10.5281/zenodo.21569296},
note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-08-06},
url = {https://dictionaryofml.org/terms/innerproduct.html}
}