Energy-Based Models (EBMs) offer a fundamentally different approach to generative modeling than the more common Variational Autoencoders (VAEs) or Generative Adversarial Networks (GANs). Instead of learning a mapping from a latent space to data, an EBM learns to assign a single scalar value—an "energy"—to every possible configuration of the input.
In this framework, low energy corresponds to high probability, and high energy corresponds to low probability. This allows for extreme architectural flexibility: any neural network that outputs a scalar can, in theory, be an EBM. However, as noted by Yang Song and Diederik P. Kingma in How to Train Your Energy-Based Models, this flexibility comes at a steep price: the partition function.
The Partition Function Bottleneck
To transform an energy function $E_\theta(x)$ into a valid probability distribution $p(x)$, we must normalize it using the Boltzmann distribution:
$$p_\theta(x) = \frac{\exp(-E_\theta(x))}{Z(\theta)}$$
The denominator, $Z(\theta) = \int \exp(-E_\theta(x)) dx$, is the partition function. For high-dimensional data like images or text, calculating this integral is computationally impossible because it requires summing over every possible state in the input space. As Kevin Swersky and Nando de Freitas highlight in On Autoencoders and Score Matching for Energy Based Models, this intractability prevents us from using standard maximum likelihood estimation, which requires knowing the exact value of $p(x)$.
The history of EBM research is essentially a history of clever mathematical "shortcuts" designed to learn the shape of the energy landscape without ever having to calculate $Z(\theta)$.
Score Matching: Looking at the Slope
One of the most successful ways to bypass the partition function is Score Matching. Instead of trying to model the probability density itself, we model the score function—the gradient of the log-density with respect to the input:
$$\nabla_x \log p_\theta(x) = -\nabla_x E_\theta(x) - \nabla_x \log Z(\theta)$$
Because $Z(\theta)$ does not depend on the input $x$, its gradient $\nabla_x \log Z(\theta)$ is zero. This realization is transformative: it means we can train a model to match the "slope" of the data distribution using only the energy function. Arash Mehrjou and Saeed Saremi demonstrate in Deep Energy Estimator Networks that by optimizing a denoising objective, we can learn these gradients directly, creating a stable path for training deep energy functions in high dimensions.
Contrastive Learning: Pushing and Pulling
Another intuition for training EBMs is the "push-pull" dynamic. If we want the model to assign low energy to real data, we must also ensure it assigns high energy to everything else.
Traditional methods like Contrastive Divergence use Markov Chain Monte Carlo (MCMC) to generate "fake" samples from the current model. The training objective then "pushes down" the energy of real data points and "pushes up" the energy of the generated samples. However, MCMC is notoriously slow and unstable.
To address this, Taesup Kim and Yoshua Bengio in Deep Directed Generative Models with Energy-Based Probability Estimation proposed using a directed generator (like a GAN) to provide these contrastive samples, effectively using one model to help another avoid the partition function. More recently, Lantao Yu and Stefano Ermon introduced Pseudo-Spherical Contrastive Divergence, which uses specialized scoring rules to bypass the need for finicky adversarial optimization entirely.
Bridging Physics and Machine Learning
Recent breakthroughs have looked toward non-equilibrium thermodynamics for answers. The Jarzynski Equality provides a way to relate the free energy difference between two states to the work done during a transition between them.
In Efficient Training of Energy-Based Models Using Jarzynski Equality, researchers show that by assigning dynamic weights to "walkers" (samples) as they move through the energy landscape, we can compute exact gradients for the cross-entropy loss. This approach, further analyzed by Davide Carbone in Jarzynski Reweighting and Sampling Dynamics for Training Energy-Based Models, allows for the correction of discretization errors in sampling, leading to unbiased training of models like Restricted Boltzmann Machines (RBMs).
Beyond Sampling: Stein Discrepancy
A final powerful alternative is to use the Stein Discrepancy. This framework allows us to compare two distributions—the data distribution and the model distribution—using only the score function of the model.
As Will Grathwohl and colleagues explain in Learning the Stein Discrepancy for Training and Evaluating Energy-Based Models without Sampling, this method "cuts out the middle-man." By avoiding MCMC sampling entirely, Stein-based objectives like ASTRAGEM (Adversarial Stein Training for Graph Energy Models) by Shiv Shankar provide a faster, more stable way to train EBMs on complex structures like graphs.
By shifting the focus from absolute probabilities to local gradients, contrastive samples, or thermodynamic work, these researchers have turned the "impossible" partition function into a solvable optimization problem, enabling EBMs to capture the intricate structures of images, speech, and even protein conformations.