Autoencoder

Squeeze data through a narrow bottleneck and see what survives

Game modeSandbox = free play. Squeeze Prediction and Latent Treasure Hunt are two small games with a clear goal.
Sandbox: paint on the left, load symbols, drag the bottleneck slider k or move the marker on the 2D map. Play freely and watch what happens.
Input (8×8 — you paint)The input image, 8×8 pixels. Paint here or load a symbol.
Latent code (k = 8 active)The compressed description. Grey bars are switched off by the bottleneck.
How many latent dimensions are used. Smaller = narrower = more information loss.
2D latent map: drag the marker to morph
ReconstructionWhat the decoder rebuilds from the latent code alone.
ErrorMean squared error between input and reconstruction. Rises as the bottleneck narrows.0.000
Controls
Load symbolsLoad a known training symbol into the grid.
Actions

Paint a symbol on the left, watch the latent code in the middle and the reconstruction on the right. Turn the bottleneck slider and see how the picture crumbles.

How to play: paint into the left grid (click/drag; right-click or Ctrl erases) or load a training symbol with the symbol buttons. The encoder presses it into the latent code (the bars in the middle), the decoder rebuilds the reconstruction on the right. Drag the bottleneck slider k down from 8 to 1: for many symbols the reconstruction crumbles and the error bar rises. Or drag the marker on the 2D map — that bypasses the encoder and morphs directly between the symbol clusters. In the squeeze prediction you guess beforehand whether a symbol survives the hardest squeeze (k = 1) still recognizable. Tip: before you start, read the explanation below the playfield — it walks you through every part of the machine, step by step.

The autoencoder in nine steps

You need no prior knowledge. We'll build the autoencoder up from scratch: first the everyday problem it solves, then each part on its own, and only at the very end the technical term. Read the steps in order — each one uses only what was already explained before.

  1. 1. The problem: too much information, too little roomImagine describing a picture to a friend over the phone so she can redraw it. You can't read out every single dot — that takes forever. You have to boil the picture down to a few telling keywords: "round symbol, open at the top". Exactly this problem — squeezing a lot of information into a few meaningful values and unpacking it again later — is something machines solve constantly: when storing photos, recognizing patterns, sorting through huge amounts of data.
  2. 2. What is an autoencoder? The summary machineAn autoencoder is a machine that learns to do exactly that automatically: it takes an input, squeezes it into a terse shorthand description, and rebuilds the input from it. The special part: nobody tells it which keywords are good — it figures out for itself what matters by practising thousands of times to repeat its own input as faithfully as possible. In this demo the input is a small 8×8 image (64 dots) that you'll paint yourself in a moment.
  3. 3. The encoder: the squeezingThe first part of the machine is called the encoder. Its job: turn the 64 dots into a few numbers — the shorthand description. In the playfield that's the left half: you paint on the left, the encoder compresses the image step by step (64 → 32 → 8 numbers). You'll see those few numbers as bars in the middle in a moment.
  4. 4. The bottleneck: the narrowest point (the squeezing)Between encoder and decoder sits the narrowest point — the bottleneck. All information has to pass through here. With the slider k you set how far the bottleneck is opened: k = 8 means room for eight numbers, k = 1 only a single one. The narrower (smaller k), the less gets through — that is the "squeezing". Remember this slider: it's the single most important knob in the whole demo.
  5. 5. The decoder: the rebuildingThe second part of the machine is called the decoder. It receives only the few numbers from the bottleneck and rebuilds a full 64-dot image from them — the reconstruction (on the right of the playfield). Important: the decoder never sees your original. Anything that didn't fit through the bottleneck it has to guess or leave out.
  6. 6. The reconstruction error: how much was lost?How good was the reconstruction? That is measured by the reconstruction error: the difference between your original (left) and the rebuilt image (right), averaged over all 64 dots. Little difference = small error = the machine kept the essentials. Big difference = big error. You see it on the right as the error bar: the fuller, the more was lost.
  7. 7. Why the narrow bottleneck is the trickNow the actual idea. If the bottleneck were as wide as the input, the machine could simply pass everything through — and learn nothing. Only because the bottleneck is much narrower is the machine forced to drop the unimportant parts and keep just the essentials. Try it: drag k from 8 to 1. At large k the symbol stays recognizable; at k = 1 many symbols fall apart, and the error bar rises. The narrowing presses out knowledge — and that is exactly the point.
  8. 8. The latent space: where similar things lie togetherThe shorthand descriptions of all images together form a map — the latent space. You see it as the 2D map in the middle: each point is one possible shorthand. The remarkable part: similar symbols lie close together and form groups (clusters), different ones lie far apart. That's why you can drag the marker between two groups and watch one symbol morph smoothly into another — the machine learned a meaningful order, entirely on its own.
  9. 9. And now the bridge to real AIWhat you try here in miniature with 64 dots is one of the most important tools of modern AI — only that real models process millions of values. What exactly this has to do with artificial intelligence is in the next section, right below the demo.

The five stations in the playfield

The playfield shows an image's journey from left to right through the machine. For each station: what you see, what to try, and what to watch for.

  1. Input (8×8 — you paint)
    What you see
    Far left, the input grid: 8×8 = 64 cells that you fill yourself. It is your original image.
    What to try
    Paint a symbol (click and drag) or load a ready-made training image with the symbol buttons.
    What to watch for
    Only this image enters the machine. Everything that follows is computed from it alone.
  2. Encoder
    What you see
    The first arrow stands for the encoder — the part that squeezes the image together.
    What to try
    You don't have to do anything here; the encoder computes automatically whenever the input image changes.
    What to watch for
    In latent mode (when you drag the map) the encoder is bypassed — the arrow goes pale then.
  3. Latent code
    What you see
    The middle: a few bars (the shorthand) plus a 2D map with all the learned symbol groups.
    What to try
    Drag the marker on the map between two groups — and watch on the right how one symbol turns into another.
    What to watch for
    Grey bars are switched off by the bottleneck. At small k only the leading, most important bars stay active.
  4. Decoder
    What you see
    The second arrow stands for the decoder — the part that rebuilds an image from the shorthand.
    What to try
    Here too the machine computes by itself; your changes above (k or marker) take effect immediately.
    What to watch for
    The decoder only knows the few numbers from the bottleneck — never your original.
  5. Reconstruction
    What you see
    Far right, the reconstruction (the rebuilt image) plus the error bar below it.
    What to try
    Compare it with your original on the left. Then drag k smaller and watch how it changes.
    What to watch for
    The narrower the bottleneck, the more the reconstruction deviates and the fuller the error bar gets.

Does this remind you of the PCA demo? It also reduces dimensions. The difference: PCA can only do straight (linear) projections. An autoencoder uses nonlinear layers (tanh) and can therefore learn curved relationships — you can see it because on the way between two clusters the decoder produces real in-between shapes instead of just cross-fading the two images.

Definition

What is an autoencoder?

Analogy

Imagine you have to send a picture through a very narrow mail slot. It won't fit as a whole. So you describe it to a friend with just a few keywords — "round symbol, open at the top" — and she redraws it on the other side from memory. The fewer keywords you're allowed, the rougher her drawing gets.

That is exactly what an autoencoder does. One part of the network (the encoder) squeezes the input into a tiny description — the latent code. The other part (the decoder) rebuilds the input from it. In between sits the bottleneck: the narrow point all information must pass through. The narrower the bottleneck, the more detail is lost.

An autoencoder learns entirely without labels — it only gets inputs and tries to output them as faithfully as possible. The trick lies in the middle: the bottleneck is much smaller than the input, so the network can't simply pass everything through. It has to find a clever shorthand. Here's how it works:

  • Encode: the encoder gradually compresses the 64 pixels of the input grid until only a few numbers remain — the latent code. That is the shorthand description of the image.
  • Bottleneck: this is the narrowest point. With the slider k you decide how many latent dimensions may be used. Fewer dimensions = less room for information = a coarser description.
  • Decode: the decoder rebuilds a 64-pixel image from the latent code. It only has the shorthand — anything that didn't fit it must guess or leave out.
  • Ordered code: in this demo the latent dimensions are sorted by importance. The first dimension carries the most, the last the least. That's why the reconstruction gets steadily worse the more dimensions you cut — reliably, not randomly.

Important: the latent space is not an arbitrary cloud of numbers. Similar inputs land close together — identical symbols form clusters. That's exactly what you see on the 2D map, and exactly why you can morph between symbols by dragging the marker in between.

This little toy is no special case — it shows a basic principle that sits in many places inside modern artificial intelligence. Four applications follow directly from what you just tried, and a fifth bridges over to image generation.

Representation learning & embeddings

The few-numbers-long shorthand in the bottleneck is what AI calls a representation or an embedding. Instead of working with raw pixels, the machine learns to describe each object by a few meaningful values — and to do so such that similar things lie close together. Such embeddings are the base currency of modern AI: words, images, users, molecules are translated into these compact numeric profiles that a model can then compute with.

Dimensionality reduction

Turning 64 dots into a few numbers is dimensionality reduction. Real data often has thousands of features, most of them redundant or irrelevant. An autoencoder presses them down to the few that truly count. That saves memory and compute time and makes hidden structure visible — similar to PCA, but with curved instead of only straight relationships.

Anomaly detection

An autoencoder only learns to reconstruct well what it sees often. Feed it something unusual later that it never practised, and the reconstruction error suddenly spikes — a clear alarm signal. That's how AI spots credit-card fraud, manufacturing defects, or oddities in sensor data: not because someone told it what fraud looks like, but because the unknown simply doesn't fit through the bottleneck.

Denoising

Train an autoencoder specifically to reconstruct clean images from noisy inputs and it becomes a denoiser. Because the bottleneck only lets the essentials through, the actual image survives and the random noise drops away. Such denoising autoencoders sit in photo apps, in image enhancement, and in cleaning up sensor and audio data.

The bridge to generative AI

Now the most exciting step. You saw that in the latent space you can aim for points between symbols and produce new in-between shapes. What if you deliberately picked new, meaningful points and decoded brand-new images from them? That is exactly what a variational autoencoder (VAE) does: it organizes the latent space so you can safely sample new points in it and turn them into real images — the first step from "rebuild" to "generate".

From here a direct line runs to today's image generation: the VAE made the latent space generation-ready; later diffusion models, like the ones behind Stable Diffusion and similar image generators, often work in exactly such a learned latent space. The basic scaffold — press an input into a compact space, then rebuild images from it — is something you already held in your hands in this demo.

In short: an autoencoder is not a niche trick but a way of thinking that runs right across AI — from compressing, through spotting oddities, to generating new content.

  1. 1. EncodeThe encoder is a sequence of layers that maps the input x (64 pixels here) to ever smaller vectors: 64 → 32 → 8. Each layer multiplies by a weight matrix, adds a bias, and applies the nonlinear tanh function.
  2. 2. BottleneckThe smallest layer is the latent code z. With k the trailing dimensions are set to 0. Because the code is ordered, only the most important information remains with a small k.
  3. 3. DecodeThe decoder mirrors the encoder: 8 → 32 → 64. From the latent code z it rebuilds the reconstruction x' — again with weights, bias and tanh.
  4. 4. Loss functionTraining minimizes the reconstruction error, the mean squared error L = mean over (x − x')². The network adjusts its weights via backpropagation so that this error becomes small — without any labels.
  5. 5. Ordered code (nested dropout)To sort the dimensions by importance, training picks a random cut k at each step and switches off all dimensions behind it. This forces the network to pack the most important information into the leading dimensions — and the error falls monotonically on average as k grows.

Check

Test your knowledge

Not completed

What is the purpose of the bottleneck in an autoencoder?

Select one answer

Answer Key: 1) B · 2) C · 3) A · 4) B

TheoryHistoryPseudocodeStep by StepFlow Diagram

Compress first, then reconstruct

An autoencoder is a neural network that is supposed to output its own input again. The encoder squeezes the input through a narrow bottleneck into a few numbers, and the decoder builds the input back up from that. It is trained without labels: the target is simply the input itself. That's why the autoencoder is a method of unsupervised representation learning.

The bottleneck forces the learning

In the demo, the input has 64 pixels (an 8x8 glyph), but the bottleneck has only 8 numbers. The network therefore cannot simply pass the input through 1:1 — it must distill the essential information to get by with so few numbers. This exact compact sequence of numbers in the bottleneck is the latent code (the learned representation).

Ordered code: the k control

This network was trained with nested dropout, so that the 8 code dimensions are ordered by importance: the first carries the most, the last the least. Setting all dimensions from k onward to 0 leaves a valid, shorter code — and the reconstruction error drops monotonically the more dimensions you keep. This is not an exact optimum but a learned approximation: at a small k, the reconstruction stays visibly blurry.

Properties

  • Unsupervised: the input is its own target, no labels needed
  • Lossy: the bottleneck forces a simplification, the reconstruction is rarely perfect
  • Nonlinear: due to the tanh layers, the code is not a flat plane like in PCA
  • Representation: the latent code is a compact, reusable feature representation

Variants

The denoising autoencoder receives a noisy input but is supposed to reconstruct the clean version — this way it learns robust features. The variational autoencoder (VAE) produces, instead of fixed numbers, a probability distribution in the bottleneck; new, plausible examples can be drawn from it. This turns the autoencoder into a generative model and builds the bridge to modern image AI.

Play with the demo! Slide the k control down from 8 to 1 and watch the reconstruction fall apart and the error bar rise. Then drag the marker across the latent map and see how one glyph smoothly transitions into the next — a nonlinear interpolation in the learned code space.

Plain Language

This preview is in Plain Language. The whole portal is also available in Plain Language. You can change the language at the top. Or use the button below. Our Plain Language texts are AI-assisted and editorially reviewed. They follow the core principles of easy-to-read language, but they are not certified Easy Read: a review panel of people with learning difficulties does not test them.

Preview: Squeezing Pictures and Rebuilding Them

What does the demo show?

The demo shows an autoencoder. An autoencoder is a program that learns. It squeezes a picture into a short description. Then it builds the picture again. Some of the picture gets lost along the way.

How to use the demo

Draw a small picture on the left. On the right, you see the rebuilt picture. Use a slider to make the narrow spot tighter. Then less fits through. The new picture gets less and less exact.

What you learn

The narrow spot forces the program to save space. It keeps only the most important parts. Similar pictures lie close together on a map. If you drag a point there, the picture changes. Modern AI often uses this trick.