A vector-quantized variational autoencoder (VQ-VAE) represents inputs with discrete latent codes selected from a learned codebook. Unlike a traditional variational autoencoder, it replaces continuous probabilistic latent distributions with finite, interpretable embeddings, reducing blurry reconstructions and inefficient latent-space use. section 11.3 section 11.3.1
Trace an input through the VQ-VAE:
- Encode the input into a grid of continuous latent vectors rather than directly producing discrete values. section 11.3.2
- Quantize each latent vector by replacing it with the nearest learned vector in the finite codebook. section 11.3.2
- Represent each selected codebook vector by its integer index, producing a sequence or grid of discrete latent codes. section 11.3.2
- Decode the quantized vectors to reconstruct the original input, optimizing reconstruction and quantization losses during training. section 11.3.2
The encoder, codebook, and decoder form the core architecture. The codebook contains learned prototype vectors, so quantization removes the continuous sampling uncertainty associated with ordinary VAEs. The resulting discrete representation supports sharper reconstruction and efficient downstream generation, including image synthesis and text-to-image systems. section 11.3.1 section 11.3.2
From image to tokens
An image such as a cat is compressed into a grid of latent feature vectors. Quantization replaces every vector with its nearest codebook entry, turning the image into integer indices that the decoder converts back into an image. section 11.3.2
Figure 11.5 The architecture of a VQ-VAE and its three components—encoder, codebook, and decoder—in the training process
Use the architecture figure to follow the encoder-to-codebook-to-decoder path and the associated training losses. section 11.3.2
