Predictive Embeddings, JEPA, and Energy-Based Models › Energy Functions and Compatibility Learning

Michael BrenndoerferJune 29, 20267 min read
World Models HandbookAll chapters
Part 5 of 12World-Model Architectures
Chapter 29Predictive Embeddings, JEPA, and Energy-Based Models › Energy Functions and Compatibility Learning
Reading section 4 of 10 · Energy Functions and Compatibility Learning · 7 minSection 4 of 10 · 7 min

Book contents

Section 4 of 10 · 7 min read

Predictive Embeddings, JEPA, and Energy-Based Models › Energy Functions and Compatibility LearningOne section · Sections in this chapter4 / 10 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Energy functions supply a scalar language for compatibility and multimodal prediction. They cover normalized probabilistic models, explicit-negative contrastive objectives, and unnormalized scores, but writing a stop-gradient discrepancy as an energy does not by itself explain the optimization dynamics that prevent collapse. The distinctions between these uses matter more here than a single historical lineage.

Definition and the Boltzmann connection

An energy-based model assigns a scalar energy Eψ(x,y)E_\psi(x, y) to a pair. When the energy is measurable and the partition function satisfies 0<Zψ(x)<∞0 < Z_\psi(x) < \infty, it defines a density over continuous yy relative to a chosen base measure μ\mu through the Boltzmann, or Gibbs, form:

pψ(y∣x)=exp⁡(−Eψ(x,y))Zψ(x),Zψ(x)=∫exp⁡(−Eψ(x,y′)) dμ(y′).p_\psi(y \mid x) = \frac{\exp\big(-E_\psi(x, y)\big)}{Z_\psi(x)}, \qquad Z_\psi(x) = \int \exp\big(-E_\psi(x, y')\big)\, d\mu(y') .

where:

  • pψ(y∣x)p_\psi(y \mid x): the conditional density over targets yy given context xx
  • xx: the context input
  • yy: the target variable
  • ψ\psi: the parameters of the energy function
  • Eψ(x,y)E_\psi(x, y): the scalar energy assigned to the pair (x,y)(x, y), parameterized by ψ\psi
  • Zψ(x)Z_\psi(x): the partition function, which normalizes the distribution over yy
  • y′y': a dummy variable of integration over possible targets under base measure μ\mu

For a discrete target space, the integral in Zψ(x)Z_\psi(x) is replaced by a sum. Adding an xx-dependent constant to every energy leaves the normalized conditional distribution unchanged. Only energy differences matter, so the energy zero point, or additive offset, is not identifiable; multiplying all energies would generally change the distribution's effective temperature. A low energy is not by itself a probability. In continuous spaces, probability mass depends on the relative depths and integrated shapes or volumes of the wells, not depth alone.

The quantity Zψ(x)Z_\psi(x) is the partition function. Computing or differentiating it is a central practical difficulty in likelihood-based energy learning. Training by maximum likelihood gives

∇ψlog⁡pψ(y∣x)=−∇ψEψ(x,y)+Ey′∼pψ(⋅∣x)[∇ψEψ(x,y′)].\nabla_\psi \log p_\psi(y \mid x) = -\nabla_\psi E_\psi(x, y) + \mathbb{E}_{y' \sim p_\psi(\cdot \mid x)}\big[\nabla_\psi E_\psi(x, y')\big].

where:

  • ∇ψlog⁡pψ(y∣x)\nabla_\psi \log p_\psi(y \mid x): the gradient, with respect to ψ\psi, of the model log-density of the observed target
  • xx: the context input
  • yy: the observed target
  • ψ\psi: the parameters of the energy function
  • ∇ψEψ(x,y)\nabla_\psi E_\psi(x, y): the gradient of the energy of the observed pair
  • Ey′∼pψ(⋅∣x)[∇ψEψ(x,y′)]\mathbb{E}_{y' \sim p_\psi(\cdot \mid x)}[\nabla_\psi E_\psi(x, y')]: the expected energy gradient under the model's current distribution over y′y'
  • y′y': a sample from the model distribution pψ(⋅∣x)p_\psi(\cdot \mid x)

The first term is the positive phase: it pushes the energy of observed pairs down. The second term is the negative phase: it pushes up the energy of pairs the model currently considers likely. Without the negative phase, nothing in this maximum-likelihood objective opposes lowering observed energies through a broad or nearly uniform downward shift, so the model need not learn meaningful relative normalization. Approximating the model expectation is the main computational problem for likelihood-trained EBMs. Other energy objectives replace maximum likelihood rather than approximate this particular term.

Different objectives under the energy lens

Maximum-likelihood sampling. Run Langevin dynamics or a Markov chain targeting pψp_\psi to draw y′y' for the negative phase. Under suitable convergence conditions this is exact in the limit, but high-dimensional mixing can be slow or unstable. Denoising diffusion uses a different construction in which iterative sampling is part of the model; for a normalized Gibbs density the score identity is ∇ylog⁡p(y)=−∇yE(y)\nabla_y \log p(y) = -\nabla_y E(y).

Contrastive estimation. Train a sampled classification objective over one positive and a finite candidate set of negatives drawn from a chosen marginal, minibatch, noise distribution, or proposal. The candidates are generally resampled during training; they are not equilibrium samples from the current EBM. A canonical form is InfoNCE:

LNCE=− E[log⁡exp⁡(−Eψ(x,y+))exp⁡(−Eψ(x,y+))+∑j=1Kexp⁡(−Eψ(x,yj−))],\mathcal{L}_{\mathrm{NCE}} = -\,\mathbb{E}\left[ \log \frac{\exp\big(-E_\psi(x, y^+)\big)}{\exp\big(-E_\psi(x, y^+)\big) + \sum_{j=1}^{K} \exp\big(-E_\psi(x, y_j^-)\big)} \right],

where:

  • xx: the context input
  • y+y^+: the true successor (positive example)
  • yj−y_j^-: the jj-th negative example drawn from a proposal distribution
  • KK: the number of negatives
  • ψ\psi: the parameters of the energy function
  • Eψ(x,y)E_\psi(x, y): the energy assigned to the pair (x,y)(x, y)
  • the expectation is over the data distribution and the negative sampling distribution
  • LNCE\mathcal{L}_{\mathrm{NCE}}: the InfoNCE contrastive loss

Under the standard sampling construction, with one positive from the joint distribution and negatives drawn independently from the target marginal, InfoNCE yields the lower bound I(X;Y)≥log⁡(K+1)−LNCEI(X;Y) \ge \log(K+1)-\mathcal{L}_{\mathrm{NCE}}, where XX and YY are the context and target random variables. Increasing the candidate count can raise the ceiling of this particular bound, but a tighter numerical bound is not guaranteed for every finite model or negative sampler. Computing more candidate scores also raises training cost.

Asymmetry. The third option, used by several joint-embedding methods, is to avoid explicit negatives and use architectural asymmetry together with other anti-collapse mechanisms. The illustrative squared prediction discrepancy used here can be read as a compatibility score

Eθ,ϕ,θˉ(x,y;c)=∥gϕ(fθ(x),c)−sg(fθˉ(y))∥22,E_{\theta,\phi,\bar\theta}(x, y; c) = \big\| g_\phi(f_\theta(x), c) - \mathrm{sg}(f_{\bar\theta}(y)) \big\|_2^2 ,

where:

  • xx: the context input
  • yy: the target input
  • cc: conditioning information, such as an action
  • fθf_\theta: the context encoder, parameterized by θ\theta
  • θ\theta: the parameters of the context encoder
  • fθˉf_{\bar\theta}: the target encoder, parameterized by θˉ\bar\theta
  • θˉ\bar\theta: the parameters of the target encoder
  • gϕg_\phi: the predictor, parameterized by ϕ\phi
  • ϕ\phi: the parameters of the predictor
  • gϕ(fθ(x),c)g_\phi(f_\theta(x), c): the predictor applied to the context embedding and conditioning input
  • sg(fθˉ(y))\mathrm{sg}(f_{\bar\theta}(y)): the stop-gradient target embedding
  • Eθ,ϕ,θˉ(x,y;c)E_{\theta,\phi,\bar\theta}(x, y; c): the compatibility energy assigned to the pair (x,y)(x, y) under conditioning cc, parameterized by θ\theta, ϕ\phi, and θˉ\bar\theta
  • sg(⋅)\mathrm{sg}(\cdot): the stop-gradient operator, which detaches its argument from the computation graph
  • ∥⋅∥22\|\cdot\|_2^2: the squared Euclidean norm

but stop-gradient and EMA do not estimate the maximum-likelihood negative-phase expectation above. They change the optimization dynamics of the positive-pair regression problem. Because the target branch is detached and, with an EMA decay close to one, updated on a slower timescale, the two branches cannot co-adapt through the same instantaneous gradient. Collapse can still be a mathematical solution, so practical methods rely on combinations of architecture, normalization, predictor dynamics, data augmentation or masking, and, in some variants, explicit variance regularization. Calling the method self-distillation describes the teacher-student relation; it should not be mistaken for likelihood training of a normalized energy model.

Compatibility Learning

Compatibility learning uses an energy to measure how well two entities fit together: a state and its successor, a goal and a trajectory, or an action and a state. Low energy means compatible; high energy means incompatible. When an energy is the negative log of an unnormalized trajectory posterior, minimizing it corresponds to MAP, or a zero-temperature limit of, control as inference from Part II: Inference, Decisions, and Control. This relation is not restricted to discrete control.

Why the energy view is worth the detour

Three practical benefits come from thinking in energies rather than in losses.

First, you can compose energies. If E1E_1 scores progress toward a goal and E2E_2 scores obstacle avoidance, then, for λ≥0\lambda \geq 0, E1+λE2E_1 + \lambda E_2 expresses a weighted soft tradeoff. For nonnegative, comparably scaled penalties with aligned zero points, the sublevel set {E1+E2≤ϵ}\{E_1 + E_2 \leq \epsilon\} lies inside {E1≤ϵ}∩{E2≤ϵ}\{E_1 \leq \epsilon\} \cap \{E_2 \leq \epsilon\}, which supports an approximate joint-constraint interpretation. Arbitrary energies do not implement an exact intersection, and new terms must be calibrated against the existing objective.

Second, an energy can represent multiple separated low-energy wells, although sampling among them may still be difficult. A squared-error point predictor instead returns the conditional mean. Depending on the mode locations and probabilities, that mean can lie between the wells, including in an implausible high-energy region.

Third, the energy lens covers several objectives without making them equivalent. Contrastive predictive coding and InfoNCE use sampled classification; triplet and margin losses use discriminative ranking; score matching uses a derivative-based criterion that avoids the partition function. For likelihood-trained EBMs, ask how the negative phase is estimated. For alternative objectives, ask what replaces likelihood training and what prevents a flat, uninformative score.

The cost is that sampling or minimizing a general high-dimensional energy is often iterative, and evaluating Zψ(x)Z_\psi(x) is intractable in general. Tractable structure or an amortized proposal can reduce that cost. When iterative inference requires many model evaluations, its latency can matter in planners with tight per-query budgets.