Applications of Machine Learning

Lecture 11 · Animations

Autoencoders and representation learning

One widget for today's central comparison. It puts a tiny non-linear autoencoder on points that lie along a curve, which no line can follow, and shows its error going below the best a line can do.

All data on this page is synthetic, generated in your browser from a fixed seed, so Reset always gives back the same picture.

1A non-linear autoencoder follows the curve

Eighty centred points along a parabola, with a little noise. The best line through them (purple, dashed) is what PCA finds, and no linear autoencoder, however trained, does better than it. The green curve is what a tiny non-linear autoencoder decodes from a sweep of its one-number code: two numbers in, eight hidden units, one number of code, eight hidden units, two numbers out, trained by gradient descent with momentum on all eighty points. Each step is one gradient step on the whole set.

How it works

The loss is the mean squared distance between each point and its reconstruction, and the gradients come by reverse mode through the four layers, as in Lecture 8. The gradient is clipped, and the update uses momentum, both from Lecture 9: without the clipping, one large early step can saturate a unit, and a saturated unit has no gradient left to learn with. A linear autoencoder can only reconstruct on a line; this one reconstructs on a curve, and what it gains over the best line is the part of the error that no line can remove: the curvature of the data.

Watch for
  • The green curve starts as a short, nearly straight stroke near the origin and bends to follow the parabola. The cost crosses the dashed level of the best line within the first hundred steps and keeps falling well below it.
  • The code is one number, as for the best line. The gain comes from what the decoder does with it: a curve instead of a line.
  • Away from the data, the green curve goes wherever the decoder happens to extrapolate. A code between two seen codes decodes to a point near the curve; a code beyond the seen range decodes to nothing the data vouches for — the motivation, in one picture, for the variational autoencoder's constraint on the code.
Try this
  1. Set the curvature to none: the points lie on a line. Now the best line's error is almost all noise, and the non-linear model cannot go far below it, because there is no curvature left to remove. The two models tie.
  2. Lower the step size to 0.01. The curve takes longer to bend; the best line is passed later and the cost at step 300 is higher. Capacity that the optimiser has not reached yet is not accuracy, which is how PCA beat the network at $d = 128$ in the lecture.
  3. Press New start. The final curve is nearly the same; the final code values along it are not. The representation is the curve; the coordinates on it are whatever the start produced.