
What is Latent Space?
Latent space is the internal representation space that a neural network learns — a compressed, abstract mathematical space where data points are mapped to coordinates (vectors) that capture their essential features and relationships. It's where a model's "understanding" lives.
Why It Matters
Latent space is the key to how AI models represent and reason about the world. Embeddings, which power semantic search and RAG, are points in latent space. Diffusion models generate images by navigating latent space. Understanding latent space explains why similar concepts cluster together in LLMs and why models can generalize to new inputs.
How It Works
When a neural network processes data, it transforms raw inputs (pixels, words, audio) through successive layers into increasingly abstract representations. The intermediate representation — often the output of an encoder or hidden layer — lives in latent space.
Properties of latent space:
- Dimensionality — typically has hundreds or thousands of dimensions (e.g., 768 or 1536 for text embeddings)
- Semantic structure — similar concepts are close together. "King" and "queen" are near each other; both are far from "banana."
- Arithmetic — meaningful operations are possible: king − man + woman ≈ queen (the famous Word2Vec example)
- Continuity — small movements in latent space produce small changes in the output, enabling smooth interpolation
Applications:
- Embeddings — text/image latent representations used for search and retrieval
- Diffusion models — Stable Diffusion operates in a compressed latent space (hence "latent diffusion")
- Autoencoders — compress data to latent space and reconstruct it
- Interpolation — generate smooth transitions between images or concepts by moving through latent space
Example
In Stable Diffusion, images are encoded into a low-dimensional latent space (64×64 instead of 512×512 pixels). The diffusion process adds and removes noise in this latent space, which is computationally much cheaper than working with full-resolution images. The decoder then maps the latent representation back to a full image.