Learning Objectives¶
Fitting \(p_\theta(x) \propto e^{-E_\theta(x)}\) by maximum likelihood gives the gradient
a push-down on data and a push-up on model samples. Every objective in torchebm.losses is a different answer to the hard part, the expectation under the model itself. The shipped family, generated from the installed package at build time:
graph TD
BaseContrastiveDivergence(["BaseContrastiveDivergence"])
BaseLoss(["BaseLoss"])
BaseScoreMatching(["BaseScoreMatching"])
BaseContrastiveDivergence --> ContrastiveDivergence
BaseLoss --> BaseContrastiveDivergence
BaseScoreMatching --> DenoisingScoreMatching
BaseLoss --> BaseScoreMatching
BaseLoss --> EnergyMatchingLoss
BaseLoss --> EquilibriumMatchingLoss
BaseContrastiveDivergence --> ParallelTemperingCD
BaseContrastiveDivergence --> PersistentContrastiveDivergence
BaseScoreMatching --> ScoreMatching
BaseScoreMatching --> SlicedScoreMatching MCMC-based: contrastive divergence¶
CD-k approximates model samples with k steps of MCMC started at the data1:
persistent=True switches to PCD: negatives resume from a replay buffer instead of restarting at the data, so chains explore the model distribution across updates. ParallelTemperingCD runs chains at several temperatures and swaps them, for multimodal targets where single-temperature chains get stuck. CD trains slowly per step (an inner MCMC loop) but yields a genuine energy with meaningful level sets.
Sampling-free: score matching¶
Score matching sidesteps model samples entirely by fitting the score2. The exact objective needs the Hessian trace; the practical members are denoising SM3, which matches the score of noise-perturbed data,
and sliced SM, which estimates the trace with random projections. DSM at a ladder of noise scales is the training principle underlying score-based diffusion4.
Transport-based: equilibrium and energy matching¶
The modern objectives replace the inner sampling loop with regression along an interpolant path (see Interpolants and Couplings).
Equilibrium matching trains a time-invariant field toward the noise direction along the path; generation integrates the field from noise with FlowSampler(negate_velocity=True), or descends it as an energy:
Energy matching (arXiv:2504.10612) keeps a single time-independent scalar potential: an OT flow-matching warm-up shapes it as transport, then a contrastive phase with temperature-scheduled Langevin negatives sharpens its Boltzmann density near the data. It accepts a coupling= and consumes per-pair weights when the coupling provides them:
Choosing an objective¶
| Objective | Inner sampling | Trains | Generate with | Reach for it when |
|---|---|---|---|---|
| CD / PCD / PT-CD | yes (k MCMC steps) | energy | MCMC | you need a calibrated energy and can afford MCMC per step |
| Exact / sliced SM | no (Hessian term) | energy | Langevin | low dimension, no noise tolerance |
| Denoising SM | no | energy (smoothed) | annealed Langevin | fast sampling-free training, noise scale acceptable |
| Equilibrium matching | no | field or energy | FlowSampler ODE | generative quality with few integration steps |
| Energy matching | phase 2 only | energy | one Langevin sweep | one potential for both transport and Boltzmann sampling |
The rule of thumb embedded in the table: objectives with inner sampling buy energy fidelity at training cost; transport objectives buy training scalability and fast generation, and the hybrids exist to keep the energy while paying the transport price.
Runnable counterparts¶
- CD-k on Two Moons
- Persistent CD
- Denoising Score Matching
- Equilibrium Matching in 2D
- Energy Matching in 2D
-
G. E. Hinton. Training products of experts by minimizing contrastive divergence. Neural Computation, 14(8), 2002. ↩
-
A. Hyvärinen. Estimation of non-normalized statistical models by score matching. JMLR, 6, 2005. ↩
-
P. Vincent. A connection between score matching and denoising autoencoders. Neural Computation, 23(7), 2011. ↩
-
Y. Song and S. Ermon. Generative modeling by estimating gradients of the data distribution. NeurIPS, 2019. ↩