How to Train Your Energy-Based Models

Yang Song, Yang Song 0011, Diederik P. KingmaarXiv 2021

Abstract

Energy-Based Models (EBMs) provide a flexible framework for representing complex probability distributions by assigning a scalar energy value to each input. Unlike traditional probabilistic models, EBMs do not require a tractable normalizing constant, allowing for greater architectural freedom. However, this flexibility introduces significant training challenges. This paper synthesizes modern training strategies for EBMs, including MCMC-based Maximum Likelihood, Score Matching, and Noise Contrastive Estimation. We discuss the theoretical connections between these methods and their role in the recent success of score-based generative models.

1. Introduction

In probabilistic modeling, the "double-edged sword" of tractability often dictates architectural choices. Standard models, such as autoregressive or flow-based models, require a tractable likelihood to facilitate training via Maximum Likelihood Estimation (MLE). This requirement imposes strict constraints: autoregressive models must factorize the distribution, and flow-based models must maintain invertibility.

Energy-Based Models (EBMs) circumvent these restrictions. An EBM defines a probability density $p_\theta(x)$ as:

$$p_\theta(x) = \frac{\exp(-E_\theta(x))}{Z(\theta)}$$

where $E_\theta(x)$ is the energy function and $Z(\theta) = \int \exp(-E_\theta(x)) dx$ is the partition function. Because $E_\theta(x)$ can be any non-linear function (e.g., a deep neural network), EBMs offer unparalleled flexibility. The primary difficulty lies in the partition function $Z(\theta)$, which is generally intractable, making standard MLE impossible. This paper serves as a tutorial on the workarounds that allow us to train these non-normalized models effectively.

2. Training Methodologies

To train non-normalized models, several paradigms have emerged that bypass the need to compute $Z(\theta)$ directly.

2.1 Maximum Likelihood with MCMC

While the likelihood itself is inaccessible, its gradient can be estimated. The gradient of the log-likelihood with respect to model parameters $\theta$ involves a "push-pull" dynamic: the gradient pushes the energy down on real data and pulls it up on samples generated from the model. Generating those samples typically requires Markov Chain Monte Carlo (MCMC) methods like Langevin Dynamics, which use the gradient of the energy function to navigate the data space.

2.2 Score Matching (SM)

Score matching avoids the partition function by focusing on the "score"—the gradient of the log-density with respect to the input $x$:

$$\psi(x; \theta) = \nabla_x \log p_\theta(x) = -\nabla_x E_\theta(x)$$

Since $Z(\theta)$ is independent of $x$, it vanishes during differentiation. Training involves matching the model's score to the data's score. The paper details Denoising Score Matching (DSM) for robustness and Sliced Score Matching (SSM) for computational efficiency in high-dimensional spaces.

2.3 Noise Contrastive Estimation (NCE)

NCE reformulates density estimation as a supervised classification problem. The model is trained to distinguish between real data and samples from a known "noise" distribution. In this framework, the normalizing constant $Z(\theta)$ can be treated as a simple learnable parameter. NCE-trained models can become "self-normalized," where the model learns to approximate the partition function so well that the constant effectively becomes 1.

2.4 Adversarial Training

Similar to Generative Adversarial Networks (GANs), adversarial EBM training uses a "minimax" objective. A generator (or "neural sampler") attempts to produce samples that have low energy according to the EBM, while the EBM tries to assign higher energy to those samples than to real data.

3. Key Insights and Unified Theory

A critical contribution of recent research is the realization that these seemingly disparate methods are deeply connected. For instance, Score Matching can be viewed as a special case of Contrastive Divergence (an MCMC-based method) in the limit of a very short MCMC chain.

Furthermore, the authors address the "Mode-Weight Problem," where score matching alone struggles to learn the relative weights of different data clusters if they are separated by wide valleys of low density. The solution—perturbing data with multiple levels of noise—"bridges" these isolated modes. This insight is the foundation for the recent explosion in diffusion and score-based generative models.

4. Applications and Results

EBMs have demonstrated success across various domains without the need for new benchmarks, leveraging existing state-of-the-art architectures:

  • Images: High-resolution generation (up to 1024x1024) that rivals or exceeds GANs in quality and stability.
  • Graphs and Molecules: Utilizing Graph Neural Networks (GNNs) as energy functions.
  • Natural Language and Audio: Success in density estimation and generative modeling.

5. Limitations and Future Directions

Despite their potential, EBMs face several hurdles:

  • Computational Bottlenecks: MCMC-based training is expensive and requires careful tuning of step sizes and chain lengths.
  • High-Dimensional Scaling: Standard Score Matching requires computing the trace of a Hessian matrix, which scales at $O(d^2)$. While Sliced Score Matching reduces this to $O(d)$, it remains a research frontier.
  • Noise Selection: The performance of NCE depends heavily on choosing a noise distribution close to the real data distribution.

Future exploration into EBMs with latent variables remains a significant area for research not covered in depth in this tutorial.

6. Conclusion

Energy-Based Models offer a powerful alternative to restricted probabilistic architectures. By focusing on the energy function and its gradients (the score), researchers can bypass the impossible task of calculating normalizing constants. As training techniques like multi-scale noise perturbation continue to mature, EBMs are becoming a backbone of modern generative AI.

Summary updated

BibTeX
@misc{song2021how,
  author = {Yang Song and Yang Song and Diederik P. Kingma},
  title = {{How to Train Your Energy-Based Models}},
  year = {2021},
  eprint = {2101.03288},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2101.03288},
}
Figure