From EM to Transformers: How Inference Evolved from Discrete States to Continuous Energy Fields
1. Introduction — A Hidden Continuum
Every model that performs inference — from the Gaussian Mixture Model of the 1990s to the modern Transformer — is trying to answer the same fundamental question:
“Given what I observe, what is the hidden structure that best explains it?”
The story of this question is the story of how machine learning moved from discrete latent states to continuous relational fields.
The Expectation–Maximization (EM) algorithm and the attention mechanism, though decades apart, are connected by a deep principle:
Inference is energy minimization.
And the Transformer — today’s most powerful architecture — can be understood as a continuous, hierarchical energy minimizer, generalizing EM’s discrete belief updates into smooth, learnable energy flows.
2. EM: Inference in Discrete Latent Space
The Expectation–Maximization (EM) algorithm is a cornerstone of probabilistic inference.
It assumes that observed data arises from a set of hidden discrete states — like cluster identities in a Gaussian Mixture Model.
EM alternates between two steps:
- E-step (Expectation):
- M-step (Maximization):
At convergence, the algorithm finds parameters and posteriors that best explain the data — a low-energy configuration in probabilistic space.
The process minimizes the variational free energy:
3. Energy Minimization as the Foundation of Inference
From physics to probabilistic modeling, energy functions encode preference:
low-energy states correspond to high-probability configurations.
Inference, in this view, is a relaxation process:
the system descends the energy landscape toward equilibrium.
In EM:
- The latent variable distribution minimizes free energy with respect to beliefs.
- The parameters minimize free energy with respect to model fit.
This is a discrete relaxation process — belief updates happen step by step, hopping between discrete latent configurations until convergence.
4. The Gibbs Connection: Softmax as Energy Distribution
IIn self-attention, we compute:
Define an energy between token and token :
Then attention weights become:
This is the Gibbs (Boltzmann) distribution, ubiquitous in statistical physics — where acts as the inverse temperature.
Thus:
Attention weights are Gibbs-distributed latent beliefs over continuous energy.
Low-energy (high-similarity) pairs get high probability.
The softmax normalization performs instantaneous energy minimization — computing an equilibrium distribution rather than iterating toward it.
5. EM vs. Attention: Two Forms of Free-Energy Minimization
| Concept | EM | Attention |
|---|---|---|
| Latent variable | Discrete cluster ID | Continuous relational weight |
| Energy function | ||
| Distribution | ||
| Optimization | Alternating E/M | One-step Gibbs equilibrium |
| Dynamics | Iterative, discrete | Continuous, differentiable |
EM and attention minimize the same type of free energy —
EM does it over discrete latent assignments,
while attention does it over continuous relations.
6. Group Attention: Differentiable EM in Continuous Space
Group or Slot Attention bridges these worlds.
It introduces explicit latent nodes — continuous embeddings that aggregate information from tokens.
This can be seen as minimizing the energy functional:
Group attention is EM reborn — but differentiable, parallelized, and continuous.
7. Transformers: Deep Energy Relaxation Systems
Each Transformer layer performs a small step of energy descent:
- Self-attention computes the Gibbs distribution of pairwise energies.
- Feed-forward layers update embeddings along the gradient of that energy.
- Residual connections ensure stability (momentum across steps).
- Layer normalization controls temperature (stabilizing energy flow).
If you interpret Transformer depth as time, the network performs a continuous relaxation:
This is the Neural ODE view of Transformers — a continuous-time energy diffusion process in latent space.
8. From Discrete Latent States to Continuous Fields
The shift from EM to Attention is more than an algorithmic upgrade —
it’s a phase transition in the nature of latent representation.
| Stage | Model | Latent Representation | Inference Mechanism |
|---|---|---|---|
| Discrete | EM | Categorical latent states | Alternating E/M, free-energy descent |
| Structured Continuous | Group / Slot Attention | Continuous latent nodes | Iterative differentiable relaxation |
| Continuous Relational | Self-Attention | Continuous relation field | One-step Gibbs equilibrium |
| Hierarchical Continuous | Transformer | Layered latent energy fields | Deep unrolled energy flow |
9. The Graph Perspective: Clusters Become Nodes
Rendering diagram...
10. Laplacian, Diffusion, and Energy Continuity
The graph Laplacian bridges discrete inference and continuous diffusion.
Both Laplacian diffusion and attention can be written as energy minimization:
Rendering diagram...
11. Unified Continuum
Rendering diagram...
✅ Summary in one sentence:
The EM algorithm, Laplacian diffusion, and Transformer attention are all instances of the same principle — free-energy minimization — evolving from discrete latent state updates to continuous energy field dynamics.