Skip to content
AI360XpertBeta
Core ML

Visual explainer

Autoencoders

Trace a two-input, one-code autoencoder through averaging, reconstruction, denoising and a visible information-loss limit.

Two coordinates can vary together along a one-dimensional family.
Two coordinates can vary together along a one-dimensional family.

An autoencoder learns an encoder and decoder by reconstructing inputs through an internal code. A useful code preserves patterns needed for the task, but a narrow layer alone guarantees neither meaningful features nor generalization.

Start with a deliberately simple family: x=(t,t)x=(t,t) for 0≤t≤10\le t\le1. Both coordinates change, but one value identifies every member. The three plotted examples are (0.25,0.25)(0.25,0.25), (0.5,0.5)(0.5,0.5) and (0.75,0.75)(0.75,0.75). The line marks the assumed family, not a universal model of images. Both axes cover the same numerical interval; this opening plot stretches horizontal space for readability.

Encode, Then Decode

An encoder maps two inputs to one code and a decoder expands it.
An encoder maps two inputs to one code and a decoder expands it.

Our synthetic encoder computes E(x1,x2)=(x1+x2)/2E(x_1,x_2)=(x_1+x_2)/2; the decoder repeats its input, D(z)=(z,z)D(z)=(z,z). The network shape is 2→1→2. Circles show actual scalar values, not unnamed hidden layers. For (1,0)(1,0), the path is (1,0)→0.5→(0.5,0.5)(1,0)\to0.5\to(0.5,0.5).

These are specified toy weights, not weights claimed to emerge from an experiment. On the diagonal training family, the same rule rebuilds every point exactly: E(t,t)=tE(t,t)=t and D(t)=(t,t)D(t)=(t,t). The general architecture and reconstruction objective are described in Deep Learning, chapter 14.

Keep A Shared Summary

Averaging replaces the two input values with their shared midpoint.
Averaging replaces the two input values with their shared midpoint.

The two coordinates contribute equally to the midpoint z=(1+0)/2=0.5z=(1+0)/2=0.5. Each arrow identifies a value being combined; the mean preserves their shared level while losing their difference. Two stored activations become one: a 2:1 coordinate-count ratio. Storage savings also depend on precision, model parameters and encoding overhead. A 784→32 architecture would have a 24.5:1 coordinate-count ratio, not an automatic 24.5-fold compressed file.

Measure What Was Lost

The repeated code can miss both original input coordinates.
The repeated code can miss both original input coordinates.

The filled dot is input (1,0)(1,0); the open square is reconstruction (0.5,0.5)(0.5,0.5). From here, coordinate plots use equal horizontal and vertical scales, so the arrow is perpendicular to the diagonal for this particular linear projection. Its component errors are −0.5-0.5 and +0.5+0.5. Mean squared error is

L=(1−0.5)2+(0−0.5)22=0.25.L=\frac{(1-0.5)^2+(0-0.5)^2}{2}=0.25.

An arbitrary nonlinear autoencoder need not be an orthogonal projection. The decoder produces what its code and learned mapping permit; it cannot consult the discarded input coordinates.

Corrupt Input, Clean Target

Averaging cancels this corruption when the two errors oppose each other.
Averaging cancels this corruption when the two errors oppose each other.

Use clean target (1,1)(1,1) and corrupted input (1.2,0.8)(1.2,0.8). Its errors +0.2,−0.2+0.2,-0.2 cancel in the mean, so E=1E=1 and D=(1,1)D=(1,1). The plot translates the origin and extends the range to include 1.2, retaining 200 drawing units per coordinate on both axes. The output square coincides with the clean target; the dot is the noisy input.

Denoising training pairs a corrupted input with its clean target, as in Vincent et al., section 3. Success depends on the corruption and learned mapping. This fixed model would leave (1.2,1.2)(1.2,1.2) unchanged, yielding MSE 0.040.04 against (1,1)(1,1). A bottleneck does not universally remove noise.

Compare Code Capacity

A two-coordinate identity code can preserve a distinction the mean code loses.
A two-coordinate identity code can preserve a distinction the mean code loses.

Keep the input (1,0)(1,0) fixed. The upper one-coordinate mean code rebuilds (0.5,0.5)(0.5,0.5) with MSE 0.250.25. The lower two-coordinate code uses the identity encoder and decoder, rebuilding (1,0)(1,0) with zero error. The labels “1 code” and “2 codes” count scalar code coordinates, not separate networks.

More capacity can preserve more detail, including unwanted detail. A small nonlinear code can also memorize a finite training set if the surrounding networks have enough capacity. Evaluate held-out reconstruction and downstream usefulness; no universally optimal width follows from this drawing.

An Unseen Code Is Unchecked

Matching the trained endpoint codes leaves the midpoint output undetermined.
Matching the trained endpoint codes leaves the midpoint output undetermined.

For this separate support example, suppose training constrains only codes zero and one. Compare two possible decoders: D1(z)=(z,z)D_1(z)=(z,z) and D2(z)=(z,z+4z(1−z))D_2(z)=(z,z+4z(1-z)). Both exactly rebuild (0,0)(0,0) and (1,1)(1,1). The plot shows only each decoder's second output coordinate, with 400 drawing units per code unit and 120 per output unit.

At z=0.5z=0.5, their second outputs are 0.50.5 and 1.51.5. The filled endpoint dots agree, while the open midpoint markers separate. These are constructed alternatives, not observed training results. Reconstruction at a few known codes does not determine sampling quality throughout latent space. A plain autoencoder does not itself specify a probability distribution for sampling new codes; the VAE visual adds that modeling choice.

Train A Decoder Weight

A reconstruction gradient can improve the decoder on a fixed code.
A reconstruction gradient can improve the decoder on a fixed code.

This controlled update freezes the encoder at E(1,1)=1E(1,1)=1 and varies the decoder Dw(z)=(wz,wz)D_w(z)=(wz,wz). With target (1,1)(1,1), MSE is L(w)=(w−1)2L(w)=(w-1)^2. At w=0.5w=0.5, loss is 0.250.25 and derivative 2(w−1)=−12(w-1)=-1.

A teaching learning rate 0.250.25 gives w′=0.5−0.25(−1)=0.75w'=0.5-0.25(-1)=0.75, reducing loss to 0.06250.0625. The ring marks the new point on the exact loss curve; its axes are weight and MSE, not input coordinates. In general, reconstruction gradients train both encoder and decoder through backpropagation.

Check A Fresh Input

A fresh off-family input is reconstructed with a measurable error.
A fresh off-family input is reconstructed with a measurable error.

Restore the original mean encoder and repeat decoder, and predict what happens to (0.25,0.75)(0.25,0.75). Its mean is 0.50.5, so reconstruction is (0.5,0.5)(0.5,0.5). Component errors are +0.25,−0.25+0.25,-0.25, giving MSE (0.0625+0.0625)/2=0.0625(0.0625+0.0625)/2=0.0625. The plot uses the same equal coordinate scales as the earlier reconstruction view. Exact diagonal reconstruction does not imply zero error on off-family inputs.

Where It Breaks

Two inputs sharing one code cannot both be reconstructed exactly.
Two inputs sharing one code cannot both be reconstructed exactly.

Both (1,0)(1,0) and (0,1)(0,1) produce code 0.50.5. A deterministic decoder receiving that code must return the same answer for both. Our decoder returns (0.5,0.5)(0.5,0.5), with MSE 0.250.25 for each. The cross marks the lost distinction, not a stopped forward computation.

Changing the decoder alone cannot reconstruct both inputs exactly once the encoder has merged them. Code dimension, architecture, regularization and data assumptions determine what gets preserved. Measure which differences matter before choosing what the bottleneck may discard.

The Quick Version

  • An encoder produces a code; a decoder reconstructs from it.
  • Coordinate-count reduction is not a compressed-file guarantee.
  • Reconstruction loss measures what the code and decoder fail to preserve.
  • Denoising learns from corrupted inputs and clean targets.
  • Narrow codes do not rule out memorization.
  • Unseen codes require separate evaluation.
  • Reconstruction gradients train the mapping.
  • Identical codes cannot recover different inputs exactly.