Interactive demo · Advanced topics · Reproduction of Murphy's book code (MNIST VAE)

Deep generative models: the VAE latent explorer (MNIST)

A variational autoencoder decodes a latent point z ∈ ℝ² into an image x of 28 by 28 pixels with a neural network. This page reproduces the experiment of Murphy's book code (notebook 21): the vanilla VAE with a two-dimensional latent space, trained on the 60000 MNIST training images with binary cross-entropy reconstruction, Adam (learning rate 0.001), batch size 500 and 10 epochs. The default decoder uses the standard ELBO (BCE summed over the 784 pixels plus the KL summed over the 2 latent dimensions, per image, averaged over the batch). The notebook's averaged loss is available with the toggle "Loss", and its decoder collapses. Left: the latent plane, with the latent means of 500 training images coloured by digit. Right: the decoded digit at the chosen point, or the decoded grid, walk, samples or region. Click or drag in the left panel to decode a latent point.

Decoder loss

Click or drag sets

Show

Latent plane

Walk position s

Loading the decoder and the latent codes...

Try these

The page has no encoder: a latent point is decoded directly. The walk and region views use the centres of the training codes of two digits (the mean latent code of each digit), so the endpoints are where the data lie. The default decoder and its 500 codes are loaded from code/data/vae_mnist_standard_decoder.json and code/data/vae_mnist_standard_latent.json; the notebook-loss pair is code/data/book_vae_mnist_decoder.json and code/data/book_vae_mnist_latent.json. All four come from code/bridge_vae_mnist_book.py (same architecture, optimiser, seed and 10 epochs; only the loss differs).

Default: the standard ELBO, where the BCE is summed over the 784 pixels and the KL over the 2 latent dimensions, per image, averaged over the batch. The notebook's loss (toggle "Loss") averages the KL over the 2 latent dimensions and the reconstruction over the 784 pixels, so its KL term weighs about 392 times more than in the standard ELBO. That collapses the code: with the book's loss the training codes stay within about 0.01 of the origin, and the decoded digits over the prior [-3, 3]^2 are almost identical. The readout explains this when the book's loss is selected. The zoom plane is the useful view for the book's decoder; for the standard decoder it spans [-4.5, 4.5]^2.

In the lecture notes