Generative AI
Autoencoder (Bottleneck Compression)
Change the bottleneck width and inspect how many shared templates the decoder can use to rebuild an image.
Image 1 of 16, 7 by 7 pixels, Squeezed through 4 latent units. The code keeps 92.3 percent of the dataset's variance, and the rebuild has mean squared error 0.0029. The rebuild undershoots to -0.083. Display clips below zero.
- Original image
- Reconstruction
- Absolute error
- Latent unit carrying variance
- Latent unit with none left to carry
Choose the starting image on the ring.
One moving blob, many changing pixels.
Change Input pattern to follow the same soft blob around the ring.
- 49 pixels
- project onto 4
- code of 4
- add 4 templates
- 92.3% dataset variance kept
Check this stage
Check your understanding
Forty-nine pixels in, a handful of numbers in the middle, forty-nine back out. Watch what survives the squeeze, watch where the loss lands, and find the point past which extra capacity buys nothing at all.
How does an autoencoder rebuild an image?
An autoencoder learns to reconstruct its input through a code. In this linear lab, the encoder turns each image into signed weights. The decoder starts with the mean image and adds the same shared templates for every input, scaled by those weights. A narrow bottleneck limits how many templates it can use.
The fixed dataset is sixteen 7×7 images of a soft blob at different positions on a ring. Use Input pattern to move between them. In Squeeze and Rebuild, compare the two images. Open Under the hood to pick a pixel and see its mean, each signed contribution, and the residual. The display clamps brightness to the visible range. The loss uses the raw decoder values.
Move through the latent space
At The Code, choose a unit and drag Coefficient offset. The decoder changes by that offset times the selected template. The original image stays fixed. Set the offset back to zero to use the encoded coefficients.
Select Show latent map. The circles are the first two coefficients of the original fixtures. The ring marker is the first two coordinates of your current code. A missing second coefficient is plotted at zero. Use Blend to opposite pattern to move the input between two fixtures. At the midpoint the image blends two blobs, and its unedited projection sits halfway along the chord. A straight blend through pixel space differs from moving the blob around the ring.
What the error map measures
At What Was Lost, try Squeeze to two units. The first two coordinates can track the blob around the ring, yet the two templates leave out finer pixel variations. The error map shows the magnitude of each difference. The signed residual in the drawer tells you whether the rebuild put too little or too much light at the selected pixel.
Variance kept measures the share of dataset variance captured by the retained directions. Reconstruction MSE averages squared pixel differences for the current image. An offset can raise MSE without changing the variance kept. Try finding the smallest width that reaches 95% variance kept.
Why wider stops helping
In Capacity You Cannot Use, raise the width past the rank marker. Centring sixteen images leaves at most fifteen independent directions, and this fixture reaches that bound. The extra slots are zero-filled, shown with hatching and ignored by the decoder. Compare the reconstruction at the rank marker and after Add unused slots.
Why this lab uses PCA
A global optimum of a linear autoencoder with squared reconstruction error can use the same projection as principal component analysis. The lab computes an orthonormal basis numerically and uses it for both encoding and decoding. Other choices of latent coordinates can produce the same reconstruction. Baldi and Hornik and Kunin et al. separate the reconstruction map from its factorisation.
A nonlinear autoencoder can learn curved families of reconstructions. Hinton and Salakhutdinov demonstrate this with deep encoders and decoders on several datasets. This lab keeps the fitted linear templates fixed so you can isolate what width and individual coefficients do. Hinton and Salakhutdinov
Stage recap
The Data
Change Input pattern to follow the same soft blob around the ring.
Squeeze and Rebuild
The encoder finds the weights. The decoder multiplies the templates by those weights and adds them to the mean image.
The Code
Offset a coefficient, then switch to the latent map. Blend toward the opposite pattern to move along a chord between the two projected inputs.
What Was Lost
Try two units. The first two coordinates track the ring, while the error panel shows detail the two templates miss.
Capacity You Cannot Use
Move past the rank marker. Hatched slots are zero-filled and leave the reconstruction unchanged.
Reference
- Encoder
- z = U_k^T (x - mu). Project the centred image onto the top k components. Forty-nine numbers become k.
- Decoder
- x_hat = mu + U_k z. Add the k templates back up, weighted by the code. The templates are shared by every image; only z changes.
- Why PCA is the honest model here
- A globally optimal linear autoencoder with squared loss can reconstruct using the principal subspace. The lab chooses the orthonormal PCA basis and solves numerically.
- Explained variance
- The share of the dataset's variance the first k components carry. This depends on width and the fitted spectrum.
- Effective rank
- How many components carry any variance at all — 15 for this dataset of 16 images. Beyond it the encoder can only write zeros.
- Reconstruction MSE
- Mean squared difference between the image and its rebuild, over all 49 pixels. Uses raw values even when the image display clips them.
Break it on purpose
With too few templates the rebuilt blob spreads along the ring. The error map shows where light is missing or was added.
Explore next
- Principal Component Analysis (PCA)For a fixed centred dataset, variance kept plus mean squared orthogonal reconstruction error is constant; PCA chooses a direction that keeps the most variance.
- Diffusion ModelsA reverse sampler generates by repeatedly estimating structure and updating a noisy sample.
- Generative Adversarial Networks (GANs)Change how often the discriminator updates and inspect the loss gradient it sends to each generated output.