Post · 2 min read· p. 77

Deriving the DALL-E lower bound

In the DALL-E paper, we want to model the joint likelihood of the model distribution over images xx, captions yy, and tokens zz for an encoded RGB image[^1].

The joint likelihood is modelled using the factorization

\begin{equation} \label{eq:factorization} p_{\theta, \psi}(x, y, z) = p_\theta(x | y, z) p_\psi(y, z) \end{equation}

The paper presents this lower bound

\begin{equation} \label{eq:lower-bound} \ln p_{\theta, \psi}(x, y) \geq \mathbb{E}{z \thicksim q\phi(z |x)} \left( \ln p_\theta (x | y, z) - D_{KL}(q_\phi(y, z | x), p_\psi(y, z))\right) \end{equation}

It was unclear to me how this was derived (and apparently unclear to others), so I thought I’d try to derive it myself.

The evidence lower bound lets us write

ln⁡pθ,ψ(x,y)≥Ez∼qϕ[ln⁡pθ,ψ(x,y,z)qϕ(z)]\ln p_{\theta, \psi}(x, y) \geq \mathbb{E}_{z \thicksim q_\phi}\left[ \ln \dfrac{p_{\theta, \psi}(x, y, z)}{q_\phi(z)}\right]

From the factorization of the joint likelihood, we can rewrite this as

Ez∼qϕ[ln⁡pθ,ψ(x,y,z)qϕ(z)]=Ez∼qϕ[ln⁡pθ(x∣y,z)pψ(y,z)qϕ(z)]=Ez∼qϕ[ln⁡pθ(x∣y,z)+ln⁡pψ(y,z)−ln⁡qϕ(z)]=Ez∼qϕ[ln⁡pθ(x∣y,z)]+Ez∼qϕ[ln⁡pψ(y,z)−ln⁡qϕ(z)]=Ez∼qϕ[ln⁡pθ(x∣y,z)]+Ez∼qϕ[ln⁡pψ(y,z)qϕ(z)]\begin{align*} \mathbb{E}_{z \thicksim q_\phi}\left[ \ln \dfrac{p_{\theta, \psi}(x, y, z)}{q_\phi(z)}\right] &= \mathbb{E}_{z \thicksim q_\phi}\left[ \ln \dfrac{p_\theta(x | y, z) p_\psi(y, z)}{q_\phi(z)}\right]\\ &= \mathbb{E}_{z \thicksim q_\phi}\left[ \ln p_\theta(x | y, z) + \ln p_\psi(y, z) - \ln q_\phi(z)\right]\\ &= \mathbb{E}_{z \thicksim q_\phi}\left[ \ln p_\theta(x | y, z)\right] + \mathbb{E}_{z \thicksim q_\phi}\left[\ln p_\psi(y, z) - \ln q_\phi(z)\right]\\ &= \mathbb{E}_{z \thicksim q_\phi}\left[ \ln p_\theta(x | y, z)\right] + \mathbb{E}_{z \thicksim q_\phi}\left[\ln \dfrac{p_\psi(y, z)}{ q_\phi(z)}\right] \end{align*}

Note that the term on the right is precisely the KL-divergence between qϕq_\phi and pψp_\psi:

DKL(qψ(y,z∣x)∣∣pψ(y,z))=E[ln⁡qψ(y,z∣x)pψ(y,z)]=−E[ln⁡pψ(y,z)qψ(y,z∣x)]D_{KL}(q_\psi(y, z | x) || p_\psi(y, z)) = \mathbb{E}\left[\ln \dfrac{q_\psi(y, z | x)}{p_\psi(y, z)}\right] = -\mathbb{E}\left[\ln \dfrac{p_\psi(y, z)}{q_\psi(y, z | x)}\right]

So we can write:

Ez∼qϕ[ln⁡pθ,ψ(x,y,z)qϕ(z)]=Ez∼qϕ[ln⁡pθ(x∣y,z)]−DKL(qψ(y,z∣x)∣∣pψ(y,z))\mathbb{E}_{z \thicksim q_\phi}\left[ \ln \dfrac{p_{\theta, \psi}(x, y, z)}{q_\phi(z)}\right] = \mathbb{E}_{z \thicksim q_\phi}\left[ \ln p_\theta(x | y, z)\right] - D_{KL}\left(q_\psi(y, z | x) || p_\psi(y, z)\right)

Which, combined with Equation \eqref{eq:lower-bound}, gives us our lower bound.

[^1]: Encoded using a dVAE— see the DALL-E paper for details.