VAE · MNIST Playground

Interactive Variational Autoencoder — train, explore & generate

PyTorch MNIST Generative AI
🎯
Status
Not Trained
📈
Epoch
0 / 0
Current Loss
⚙️ Hyperparameters
📉 Training Loss
📊 Loss curve appears here after training starts
🏗️ Network Topology
Input · 784-D
28 × 28 flattened pixel values
Encoder FC · 400-D
ReLU activation
↓ split ↓
μ head  &  log σ² head · 2-D
Two parallel linear layers
↓ reparameterize ↓
Latent vector z · 2-D
z = μ + σ · ε   ε ∼ 𝒩(0, I)
Decoder FC · 400-D
ReLU activation
Output · 784-D
Sigmoid → reconstructed image
📐 Loss Function

ELBO Loss

ℒ = ℒ_recon + β · KL

Reconstruction Loss (Binary Cross-Entropy)

ℒ_recon = −Σ [ x·log(x̂) + (1−x)·log(1−x̂) ]

KL Divergence (closed form)

KL = −½ Σ [ 1 + log σ² − μ² − σ² ]

Reparameterization Trick

The trick decouples stochasticity from parameters, making backpropagation through sampling possible:

z = μ + σ ⊙ ε   where  ε ∼ 𝒩(0, I)

Why 2-D Latent Space?

A 2-D latent space lets us visualise the full manifold as a 2-D scatter plot. Higher dimensions improve quality but lose direct interpretability.

⚠️ Train the model first (Training tab). Latent space visualisation requires a 2-D latent dimension.
🌐 2-D Latent Space — MNIST

Each point is an MNIST digit encoded via the VAE's encoder. Colour = digit class (0–9). Well-separated clusters indicate a structured latent manifold.

🌐 Train the model, then click Generate Plot
⚠️ Train the model first (Training tab) to enable reconstruction.
🔁 Original vs Reconstructed Digits

Row 1: original MNIST samples  |  Row 2: VAE reconstructions. Blurriness reflects the smoothing nature of the reconstruction loss.

🔁 Train then click Random Batch
ℹ️ Adjust the latent sliders to navigate the learned manifold and decode new digit-like images. Grid view requires a 2-D latent space.
🎛️ Latent Controls
Z1 — Latent Dim 1 0.00
Z2 — Latent Dim 2 0.00
🖼️ Generated Image
Train the model then click Generate