Lesson 4.10core2 h 30 min⚡ live demo

Autoencoders, embeddings and representation learning

Encoders compress, decoders reconstruct; meaning lives in between

"Encoder", "decoder", "latent", "embedding" — these four words run through the rest of the path: seq2seq models (6.6 Seq2seq, encoder–decoder and beam search), the transformer's two stacks (7.1 Attention Is All You Need: the big picture), BERT and GPT as encoder-only and decoder-only (7.5 Encoder-only: BERT and friends (and sentence embeddings), 7.6 Decoder-only: GPT and autoregressive generation), VAEs and the latent space of Stable Diffusion (8.8 Generative models I: VAEs and GANs, 8.9 Generative models II: Diffusion and flow matching), and the embedding vectors that power every retrieval system (9.2 Embeddings deep dive). The autoencoder is the simplest model that contains all of them, and it is the cleanest place to learn what a representation is and why cosine similarity on learned vectors works.

You'll be able to

  • Define encoder, decoder, bottleneck and latent space and write the autoencoder objective
  • Explain why a linear autoencoder recovers the PCA subspace and what nonlinearity adds
  • Describe denoising, sparse and masked autoencoders and the manifold hypothesis
  • Explain nn.Embedding as a learned lookup table and why similarity in embedding space is meaningful
  • Use the words encoder and decoder correctly across autoencoders, seq2seq and transformers

Key ideas

  1. An autoencoder minimizes ‖x − g(f(x))‖² through a bottleneck k < d; the code z is a learned representation obtained without labels.
  2. A linear autoencoder with squared loss learns the top-k principal subspace (PCA); nonlinear encoders/decoders learn curved manifolds.
  3. The manifold hypothesis: real data lies near a low-dimensional manifold; latent coordinates parameterize it, which is why interpolation and generation work.
Show 4 more key ideas
  1. Denoising autoencoders estimate the direction back to the data manifold (the score) — the core of diffusion models; masked autoencoders (MAE, BERT) are denoising over patches/tokens.
  2. nn.Embedding is a V×d lookup table trained by backprop; one-hot × matrix = row selection.
  3. Embedding similarity is meaningful because training objectives score with dot products, pushing similarly-used items together; the geometry is task-dependent.
  4. Encoders map inputs to representations, decoders produce outputs from them; the exact meaning differs across autoencoders, seq2seq, transformers and VAEs.

Suggested path through this lesson