§18.0–18.2The Log-Likelihood Gradient · Contrastive Divergence · Stochastic Maximum Likelihood

Part III DL pp. 605–614 · ~6 min read

  • positive phase
  • negative phase
  • fantasy particles
  • contrastive divergence (cd)
  • spurious modes
  • stochastic maximum likelihood (sml)
  • persistent contrastive divergence (pcd)
  • fast pcd (fpcd)

§18.0 The problem

An undirected model gives an unnormalized p~(x;θ)\tilde{p}(\boldsymbol{x}; \boldsymbol{\theta}); the real distribution needs the partition function Z(θ)=xp~Z(\boldsymbol{\theta}) = \sum_{\boldsymbol{x}} \tilde{p} (or p~dx\int \tilde{p}\,d\boldsymbol{x}), which is intractable for most interesting models (§16.2.3). Some deep models are designed to have a tractable ZZ, or to be used without ever computing p(x)p(\boldsymbol{x}) (chapter 20); this chapter is about the models that confront the intractable ZZ head-on — how to train and evaluate them anyway.

§18.1 The log-likelihood gradient splits in two

Maximum-likelihood learning is hard here because ZZ depends on the parameters. The gradient splits into two named pieces:

Positive minus negative phase (eq 18.4)

θlogp(x)=θlogp~(x)θlogZ(θ)\nabla_{\boldsymbol{\theta}} \log p(\boldsymbol{x}) = \nabla_{\boldsymbol{\theta}} \log \tilde{p}(\boldsymbol{x}) - \nabla_{\boldsymbol{\theta}} \log Z(\boldsymbol{\theta})
θlogp~(x)\nabla_{\boldsymbol{\theta}} \log \tilde{p}(\boldsymbol{x})the POSITIVE phase — raise the unnormalized probability of the observed training example (easy: no Z)gradient
θlogZ-\nabla_{\boldsymbol{\theta}} \log Zthe NEGATIVE phase — lower the normalizer. This is the hard term; for an RBM the positive phase is easy but this one is notgradient

The negative phase looks hopeless — ZZ is an intractable sum — but it has a beautiful form. Differentiating logZ\log Z (eqs 18.5–18.13, using p~=exp(logp~)\tilde{p} = \exp(\log\tilde{p})) collapses to an expectation over the model’s own samples:

The negative phase is a model expectation (eq 18.15)

θlogZ=Exp(x)[θlogp~(x)]\nabla_{\boldsymbol{\theta}} \log Z = \mathbb{E}_{\boldsymbol{x} \sim p(\boldsymbol{x})}\left[\nabla_{\boldsymbol{\theta}} \log \tilde{p}(\boldsymbol{x})\right]
Exp(x)\mathbb{E}_{\boldsymbol{x} \sim p(\boldsymbol{x})}the expectation is under the MODEL distribution p — so we must draw samples from the model (chapter 17's MCMC) to estimate itexpectation
θlogp~(x)\nabla_{\boldsymbol{\theta}} \log \tilde{p}(\boldsymbol{x})the same easy per-example gradient as the positive phase — just evaluated at MODEL samples instead of datagradient

In energy terms (logp~=E\log\tilde{p} = -E), the two phases are a tug of war: the positive phase pushes the energy down on training data; the negative phase pushes the energy up on samples drawn from the model. When pmodel=pdatap_\text{model} = p_\text{data}, every up-push is matched by a down-push and the gradient vanishes — training is done. Drive it yourself:

Fig 18.1–18.2, live — the positive phase (green up-arrows) raises p̃ on data; the negative phase (red down-arrows) lowers p̃ on model samples. The model starts with a spurious bump on the right. With SML the persistent chains reach that bump and push it down, and p_model converges to p_data; switch to CD and its data-initialized chains never reach the bump, so the spurious mode survives.
push up (data)push down
step 0
spurious-mode mass = 56.5%
∇ log p̃ += η·(p_data − p_neg)

The positive phase pushes p̃ up on data; the negative phase pushes it down on model samples. SML’s persistent chains reach the far spurious bump and suppress it → the model converges to the data.

The model samples of the negative phase are the points the model believes in most strongly — its wrong beliefs, often called “hallucinations” or fantasy particles . (The positive/negative split has even been floated as an account of dreaming: follow logp~\nabla\log\tilde{p} awake, its negative asleep.)

§18.2 Making the negative phase affordable

The naive recipe (Algorithm 18.1) estimates eq 18.15 by burning in a fresh set of Markov chains from random initialization at every gradient step — far too expensive. Every practical method is a cheaper way to initialize those negative chains so they need less burn-in:

The MCMC maximum-likelihood loop (the shared skeleton)
  1. 1sample a minibatch of data {x(1),,x(m)}\{x^{(1)}, \ldots, x^{(m)}\}
  2. 2positive phase: g1miθlogp~(x(i))g \leftarrow \frac{1}{m}\sum_i \nabla_\theta \log \tilde{p}(x^{(i)})
  3. 3initialize negative samples x~(i)\tilde{x}^{(i)} ← ???
  4. 4run kk Gibbs steps on each x~(i)\tilde{x}^{(i)}
  5. 5negative phase: gg1miθlogp~(x~(i))g \leftarrow g - \frac{1}{m}\sum_i \nabla_\theta \log \tilde{p}(\tilde{x}^{(i)})
  6. 6update θθ+ϵg\theta \leftarrow \theta + \epsilon\, g
How each method initializes the negative chains — and what it costs. Click a cell for detail.
MethodNegative-chain initConsequence
Naive MCMC (Alg 18.1)naive MCMCrandom, every stepcorrect but infeasibly expensive
Contrastive divergence (CD-k)contrastive divergencefrom DATA points each stepcheap; biased; leaves spurious modes
Stochastic max likelihood (SML/PCD-k)SML = persistent CDfrom the PREVIOUS step's chainsfinds all modes; trains deep models
Fast PCD (FPCD)fast PCDprevious chains + fast weightsforces rapid mixing during learning
Dotted-underlined cells have explanations — click one.

Why CD leaves spurious modes and SML doesn’t

Contrastive divergence starts its negative chains at the data and runs only a few Gibbs steps, so they stay near the data. A mode the model invents far from the data — a spurious mode — is never visited, so the negative phase never pushes it down (watch the spurious-mode mass stay high in CD mode above). Stochastic maximum likelihood (a.k.a. persistent contrastive divergence ) instead keeps persistent chains alive across gradient steps; free to wander, they discover every mode and suppress it. Fast PCD accelerates that wandering with a fast-weight copy of the parameters.

A crucial bonus: because these methods yield an estimate of θlogZ\nabla_\theta \log Z separately, you can bolt the negative-phase gradient onto any positive- phase method — even one that only lower-bounds p~\tilde{p}. Most of the other techniques in this chapter (next) cannot compose with a lower-bounded positive phase. Next: methods that sidestep Z entirely — pseudolikelihood, score matching, and noise-contrastive estimation.

Check yourself — positive/negative phase, CD & SML

1.The undirected log-likelihood gradient is ∇θ log p̃(x) − ∇θ log Z. What are these two terms?

2.In energy terms, what do the positive and negative phases do, and when does learning stop?

3.Across the naive/CD/SML methods, what is the one line that actually differs?

4.Why does contrastive divergence fail to suppress spurious modes, and how does SML fix it?

5.Predict the outcome — in PhaseLab you train in CD mode from the spurious-bump start, then reset and train in SML mode. What does the spurious-mode mass do?

5 questions