CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Artificial Intelligence / Generative AI: Making New Things

Autoencoders: Squeeze and Rebuild

Lesson 2 of 11 · 7 min · Free, no account needed

What you will learn

  • An autoencoder has an encoder that squeezes the input into a short code and a decoder that rebuilds it.
  • The narrow middle is the bottleneck: it forces the code to keep only what matters most.
  • Training makes the rebuild error small. Things unlike the training data rebuild badly, which is how it spots defects.
  • Set the code numbers yourself and the decoder draws critters nobody fed in.

Start the lesson

How the lesson goes

  1. This critter is 256 numbers. Could you send it as just 4?

    Every pixel is one number from 0 to 1.

  2. Squeeze the critter through codes of different sizes.

    The encoder turns 256 numbers into a short code. The decoder rebuilds a picture from it.

  3. Find the smallest code with a rebuild error under 9.

    Slide the code size. The error is shown with its number.

    Each extra code number fixes the biggest remaining difference. Here the 4th number brings back the ears, and the error drops from 11.2 to 8.5.

  4. This squeeze-and-rebuild machine is an autoencoder.

    It is trained so that out matches in. The narrow middle forces it to keep only what matters.

  5. Skip the encoder: set the 3 code numbers yourself and rebuild the target.

    The decoder draws whatever code you give it.

  6. Which new picture will the autoencoder rebuild worst?

    Tap one, then Check. The rebuilds appear after.

    The decoder can only draw mixes of what it learned. An upside-down critter is unlike every training picture, so the rebuild error is about 41, while normal critters stay between 8 and 10.

  7. Factory inspector: catch the 3 broken toys.

    Each toy sits above its rebuild. 2 misses allowed.

  8. Code: which formats give back an exact copy?

    Drag each format to what comes back after unpacking.

    ZIP and PNG are lossless: you get every byte back. JPEG, MP3 and an autoencoder are lossy: smaller, but only close to the original.

  9. A 256-number critter becomes a 4-number code. How many times smaller is the code?

    256 ÷ 4 = 64, so the code is 64 times smaller. The price: the rebuild is close, not exact.

  10. Send a critter of your own as a 3-number postcard.

    Set any 3 numbers and press Send. The receiver only has the decoder.

Previous lesson: Generating vs Classifying · Next lesson: Latent Space Walks · Part of the course: Generative AI: Making New Things

Lessons are interactive and need JavaScript. Turn it on to play them.

Loading TwiddleLab