Learn AI.
Understand Neural Networks · ORIGINAL LEARN AI LESSON

Compress and reconstruct.

Train a tiny shape autoencoder, inspect its bottleneck and test why reconstruction does not guarantee useful generation.

By the end: Explain encoder, latent bottleneck and decoder; compare reconstruction with a baseline and evaluate a declared sampling rule.

01 · TRY

Start with something concrete.

A 4×4 bar has sixteen pixel values. Can two learned numbers preserve its shape? Inspect a reconstruction before training, then change the weights.

Try the interactive model ↓
02 · PREDICT
Before you experiment

A model reconstructs its training shapes well. Does that guarantee every random latent coordinate decodes to a valid new shape?

A model reconstructs its training shapes well. Does that guarantee every random latent coordinate decodes to a valid new shape?
03 · EXPERIMENT

Change one thing. Watch what follows.

  1. Inspect the untrained input, two coordinates and reconstructed pixels. Predict the direction of error change.
  2. Train in batches of 25 updates. Compare training/development MSE with the train-only mean baseline.
  3. Select row 4, which never enters gradients. Explain why its visible result is development evidence.
  4. Interpolate between two encodings. Test endpoints and the middle; inspect validity rather than smoothness alone.
  5. Compare uniform sampling with the fitted training-encoding mixture, including zero spread. Report exact-bar validity and distinct valid bars.
  6. Export a comparison with a failure, claim limits and a proposed new evaluation set.

Loading this browser experiment…

04 · UNDERSTAND

Try to send a shape through a small message

Imagine a square divided into sixteen pixels. Each pixel is 0 for empty or 1 for filled. A horizontal bar fills one row. A vertical bar fills one column. The lab uses eight original synthetic bars, so there are no downloaded images or privacy concerns. The challenge is to send the sixteen numbers through a message containing only two numbers and then reconstruct the image.

An encoder maps the image to those two numbers. We call them a latent representation: internal coordinates learned for the reconstruction task. A decoder maps the two numbers back to sixteen pixel intensities. Both parts learn together. Training targets are the inputs themselves; we do not supply row/column labels to the network.

Six bars enter training: rows 1–3 and columns 1–3. Row 4 and column 4 are separate development examples. Look at both, but remember that repeatedly using their results to choose settings makes them development evidence, not a fresh final examination.

Follow the actual calculation

The diagram connects the input, two coordinates and reconstructed output. Before training, the weights are small seeded numbers and the image looks uncertain. Train one update and inspect what changes. Twenty-five updates is a bounded batch, not a different learning algorithm.

For each latent coordinate, the encoder multiplies each input pixel by a weight, adds all sixteen contributions and a bias, then applies tanh. Tanh keeps that coordinate between −1 and 1. The decoder combines both coordinates with learned weights and a bias for each pixel, then applies sigmoid to produce an intensity between 0 and 1.

z=tanh⁡(Wx+b),x^=sigmoid⁡(Vz+c)z=\tanh(Wx+b),\qquad \hat{x}=\operatorname{sigmoid}(Vz+c)

Here x contains 16 input intensities; z contains 2 latent coordinates; x̂ contains 16 reconstructed intensities. W is a 2-by-16 encoder matrix and b contains 2 biases. V is a 16-by-2 decoder matrix and c contains 16 biases. That is 32 + 2 + 32 + 16 = 82 learned parameters. This is a smaller representation, not a claim that the full model is smaller than an image file. The decoder parameters and a numerical precision convention would also be needed to store and recover images.

The axes in the latent plot stay fixed at −1 to 1. A different run or architecture can encode the same shapes differently; these coordinates do not have inherent names such as “horizontal” and “vertical.” Overlapping coordinates can hide distinct shapes, so inspect the numerical coordinate list as well as the plot.

Measure reconstruction rather than naming it good

Suppose two target pixels are [1, 0] and their reconstructed values are [0.8, 0.2]. Each error has magnitude 0.2. Squaring gives 0.04 and 0.04; their mean is 0.04. The lab performs the same calculation over sixteen pixels, then averages equally across the six training examples.

L=1N∑n=1N116∑i=116(x^n,i−xn,i)2L=\frac{1}{N}\sum_{n=1}^{N}\frac{1}{16}\sum_{i=1}^{16}(\hat{x}_{n,i}-x_{n,i})^2

N is the number of examples being scored; n identifies an example and i a pixel. L is mean squared error, or MSE. Zero means exact reconstruction; lower is better for this objective. It is not accuracy, image likelihood or a universal measure of usefulness. The displayed worked arithmetic follows the selected model and pixel, rather than an unrelated animation.

Backpropagation computes how changing each weight would change the loss. The update subtracts the learning rate times that gradient from each parameter. All gradients are calculated from the same preceding model and then applied simultaneously. The lab trains both encoder and decoder; it does not merely move plotted points or replace outputs with the target image. The implementation tests compare all 82 analytic derivatives with small positive and negative parameter perturbations.

A useful reference is the mean training image, which always predicts the same per-pixel average. It uses no input-specific encoding. Compare both models on the same training and development images. A small training error accompanied by poor development reconstruction is evidence to investigate, even when the training pictures look impressive.

Interpolation asks a new question

Select two shapes and move the fraction slider. At fraction 0 you decode the first encoding; at 1 you decode the second. Halfway means averaging each pair of coordinates. For example, halfway between [−0.6, 0.2] and [0.4, 0.8] is [−0.1, 0.5]. This arithmetic is performed in latent space, not by averaging the final images.

The resulting image can change smoothly without remaining a valid bar. The training objective constrained reconstructions at particular encoded examples. It did not require every point between those examples to decode into a useful shape. Compare an endpoint and the middle before assuming that a smooth visual transition is evidence of generalization.

Specify where a generated latent comes from

The first sampling rule draws two coordinates uniformly from the square [−1, 1]². That can place samples in regions the encoder rarely or never visited. The second is a simple post-fit probabilistic extension: choose one of the six training encodings equally, then add independent Gaussian noise to each coordinate. Gaussian noise is centered at zero; its standard deviation controls the typical perturbation size. With zero standard deviation, this is just a discrete distribution over training encodings.

This mixture is fitted only through the training encodings. It is a sampling heuristic, not a variational autoencoder, not an optimized prior and not a normalized likelihood for images. Positive noise can also produce coordinates outside the encoder’s range. The decoder can still calculate an output there, but reconstruction training did not establish its quality.

Both rules produce eight seeded samples for a reproducible local comparison. The same seed does not give the two algorithms identical latent locations or turn a rerun into independent evidence. In the gallery, thresholding intensities at 0.5 lets us check a deliberately narrow rule: does the result exactly equal one of the eight possible bars? We separately count distinct valid bars, so repeated good copies and diverse failures are not mistaken for the same success. These checks are independent of the MSE training objective.

Apply the distinction

For guided practice, export reset and trained captures, show one failed reconstruction or interpolated blend, and explain why reconstruction and generation need different evidence. For implementation practice, reproduce the forward pass and gradients, test a zero-weight model, and verify that development pixels never enter updates. For a decision brief, compare the baseline, reconstruction errors, valid sample count and distinct valid count. Name what would change if the task included diagonals, thicker bars or real photographs.

A strong next experiment would specify new shape families and a sampling protocol before reviewing their results. This lab’s public examples, optional captures and lesson practice do not establish independent implementation skill or real-image generation quality. Learner pilots and human project review remain pending.

05 · APPLY
Check your understanding

A zero-spread mixture samples only training encodings and has high bar validity. What does it demonstrate?

A zero-spread mixture samples only training encodings and has high bar validity. What does it demonstrate?
06 · CONTINUE

Take this idea with you.

An autoencoder learns to reconstruct through a bottleneck. Useful generation additionally needs a sampling rule and evidence about validity, diversity and generalization.

My work
Original Learn AI lesson ·Deep Learning: Autoencoders
Learn AI · Understand by doing.Loading local progress…Copyright (c) 2026 Mobi Weave, Inc. All rights reserved