Skip to content
BIASED

The reparameterization trick

Block 1 of 7~2 min

What the encoder outputs

The topic Latent variables and the ELBO gave the VAE (Kingma and Welling, 2014) its objective, the ELBO. Its encoder maps each input to a Gaussian, not a point,

qφ(z∣x)=N(μφ(x), σφ2(x)),q_\varphi(z \mid x) = \mathcal N\big(\mu_\varphi(x),\ \sigma^2_\varphi(x)\big),

and the KL term pulls every such Gaussian toward the prior p(z)=N(0,I)p(z) = \mathcal N(0, I). In code, the encoder ends with two heads: one for μ\mu and one for log⁡σ2\log\sigma^2.

The ELBO's reconstruction term is an expectation over qφq_\varphi, and we estimate it with a sampled code. To train the encoder, we have to differentiate through that sample. This topic shows how.

Answers are saved on the server and tied to this browser until you sign in.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • KL term in codeoptional

    Write the element-wise KL between N(μ, σ²) and N(0, 1) from encoder outputs mu and logvar.

    ~15 min · easier on a computer · The Reparameterization topic read; closed-form KL for diagonal Gaussians.

    Open practice
  • Reparameterization in codeoptional

    Finish sampling z = μ + σ ⊙ ε so gradients reach the encoder.

    ~15 min · easier on a computer · The Reparameterization topic read; basic PyTorch (tensors, element-wise ops).

    Open practice
  • Reparameterization — derivation and CPU demooptional

    Detailed derivation of z=μ+σ⊙ε, a NumPy distribution/gradient demo, and links to the code exercises. Self-check in the notebook.

    ~30 min · easier on a computer · The Reparameterization topic read; code exercises optional after the notebook.

    Self-check in the notebook — not part of mastery or the certificate.