Introduction: structuring the data space
So far, we've manipulated vectors and matrices. But to truly understand what ML models do, you need to understand the space in which these vectors live.
A vector space is a mathematical framework that defines the rules of the game: which vectors exist, how you can combine them, which operations are allowed. It's the underlying structure that gives meaning to embeddings, projections, and the very notion of "proximity" between data points.
Vector space: intuitive definition
A vector space is a set of vectors that you can add together and multiply by scalars, and the result always stays in the set.
Formally, a vector space over satisfies:
- Closure under addition: if , then
- Closure under scalar multiplication: if and , then
- Plus some natural properties (associativity, commutativity, existence of a zero vector, etc.)
The most common example: , the set of all vectors with real components. That's the space your data lives in when you have features.
But vector spaces aren't limited to lists of numbers. The set of continuous functions, the set of polynomials of degree at most , the set of matrices, these are all vector spaces. This abstraction allows transposing the same mathematical tools to very different contexts.
Basis and dimension
Linear combination
A vector is a linear combination of vectors if it can be written as:
for some scalars .
Linear independence
Vectors are linearly independent if none of them can be expressed as a linear combination of the others. In other words: no vector is redundant, each one brings a new direction.
Basis
A basis of a vector space is a set of vectors that are:
- Linearly independent (no redundancy)
- Spanning (every vector in can be written as a linear combination of the basis)
The most well-known basis of is the standard basis:
But there are infinitely many possible bases. Each basis offers a different "viewpoint" on the same data. PCA, for instance, finds the basis that maximizes variance along each axis.

Dimension
The dimension of a vector space is the number of vectors in any basis. has dimension . All bases of the same space have the same number of vectors, that's a fundamental theorem.
In ML, when we say an embedding is "dimension 768," it means each vector lives in , a space with 768 independent axes.
Subspaces
A subspace is a subset of a vector space that is itself a vector space. It must contain the zero vector and be closed under addition and scalar multiplication.
Examples:
- In , a line through the origin is a 1-dimensional subspace
- A plane through the origin is a 2-dimensional subspace
- The set is a 0-dimensional subspace
In ML
-
The column space of a matrix (the set of all vectors ) is a subspace. It's the set of possible outputs of the transformation.
-
The null space of (the set of such that ) is a subspace. These are the inputs that the transformation crushes to zero, the lost information.
-
In PCA, you project the data onto a lower-dimensional subspace. The "principal components" form the basis of this subspace.
Dot product and orthogonality
Dot product
The dot product (or inner product) of two vectors is:
It's a single number that measures how much the two vectors "point in the same direction." Geometrically:
Where is the angle between the two vectors.
The dot product is at the heart of the attention mechanism in Transformers. The attention score between a query and a key is , a dot product that measures their similarity.
Orthogonality
Two vectors are orthogonal if their dot product is zero: . They are perpendicular, totally independent in terms of direction.
An orthonormal basis is a basis whose vectors are pairwise orthogonal and have unit norm. It's the "cleanest" possible basis, no correlation between axes.
Orthogonal matrices () preserve distances and angles. They are pure rotations, with no distortion.
Orthogonal projection
The idea
Projecting a vector onto a subspace means finding the point in the subspace closest to . It's the shadow of on the subspace, as if the light came from perpendicular above.

Projection onto a vector
The projection of onto the direction of is:
If has unit norm, it simplifies to .
Projection onto a subspace
If you have a matrix whose columns form an orthonormal basis of the subspace, the projection is:
The matrix is a projection matrix. It's idempotent: projecting twice gives the same result ().
Attention as projection
In a Transformer, the attention mechanism can be seen as a weighted projection. Queries and keys compute attention weights (via the dot product), then these weights are used to make a linear combination of values. The result is a kind of "soft" projection of information onto directions deemed relevant by the model.
This geometric view helps understand why attention works: it selects and combines the most relevant information for each position, exactly as a projection selects the useful component of a vector.
The curse of dimensionality
The problem
In ML, you often work in very high dimensions: thousands, even millions of features. The geometric intuition built in 2D and 3D no longer works.
Here are some counterintuitive phenomena in high dimensions:
-
Volume concentrates in the corners: in dimension , the volume of a hypersphere inscribed in a hypercube tends toward 0 as increases. Almost all the volume is in the "corners" of the cube.
-
All points are far apart: the distance between two random points in a -dimensional hypercube concentrates around the same value. The notions of "close" and "far" lose their discriminating power.
-
Data is sparse: to uniformly sample a -dimensional hypercube with reasonable density, you need a number of points exponential in . With 100 dimensions, even a billion points is ridiculously few.

Consequences in ML
-
Algorithms based on distance (k-NN, clustering) struggle in high dimensions because distances become uninformative.
-
Overfitting is easier when is large relative to the number of examples: the model has too much freedom to fit the noise.
-
Dimensionality reduction (PCA, t-SNE, UMAP, autoencoders) is often essential to bring data into a space where geometry makes sense.
-
Modern embeddings work precisely because they project very high-dimensional data (50,000-word vocabulary) into a reasonably-dimensional space (256-1024) where distances are meaningful.
Why this matters for AI
Vector spaces provide the theoretical framework in which ML data and models live:
- Embeddings are vectors in a learned space
- Projections are at the heart of attention and PCA
- Subspaces explain what a model can and cannot represent
- Dimensionality dictates the difficulty of the problem and the techniques needed
Without these concepts, you manipulate matrices without understanding their geometry. With them, you see that ML is fundamentally a science of high-dimensional geometry.
Where this is used. The dot product and the notion of direction in a space are what give word vectors their meaning.