liveBook · Manning

Quantized latent representation

As explained in Build a Text-to-Image Generator (from Scratch)

A quantized latent representation is a latent representation whose continuous vectors have been replaced by discrete codebook vectors.

A quantized latent representation replaces continuous latent vectors with discrete codebook vectors. In VQGAN, each latent vector maps to its nearest codebook entry, producing a compact sequence of integer indices. section 11.5.2

The conversion proceeds in three stages:

  • Encode an image into a continuous latent grid containing 576 feature vectors. section 11.5.2
  • Match every latent vector to one of 1,024 codebook vectors and record its index. section 11.5.2
  • Look up the indexed vectors to rebuild zq, then pass it through the decoder to reconstruct the image. section 11.5.2

Image tokens

If the first two indices are 873 and 862, they select codebook vectors 873 and 862. Repeating this lookup for all 576 indices reconstructs the quantized latent grid. section 11.5.2

z_q, _ , indices= model.quantize(z)    #1
int_sequence = indices[2]    #2
print(int_sequence)

Inspect the quantization call that returns the quantized vectors and the integer index sequence. section 11.5.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains encoding, codebook lookup, latent reconstruction, and decoding, but stops short of quantization-loss internals.
Examples
Uses a 576-index image sequence, example indices 873 and 862, and paired reconstructions from vectors and indices.
What it assumes
Assumes familiarity with latent representations, encoders, decoders, and vector codebooks.
What you can do after
Builds and reconstructs quantized image latents by mapping codebook indices back into vectors.
How it connects
Connects latent representation, codebook, VQGAN, decoder, and DALL-E.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.