VQ-VAE
6 memberslucid.models.generative.vqvaeVQ-VAE family — van den Oord, Vinyals & Kavukcuoglu, 2017.
van den Oord, Aaron, Oriol Vinyals, and Koray Kavukcuoglu. "Neural Discrete Representation Learning." Advances in Neural Information Processing Systems, vol. 30, 2017, pp. 6306-6315.
The Vector-Quantised Variational Auto-Encoder replaces the continuous Gaussian bottleneck of a VAE with a discrete one. An encoder maps an image to a spatial grid of -dimensional vectors, and each grid position is snapped to its nearest neighbour in a learned codebook :
The decoder then reconstructs from . Because the has zero gradient almost everywhere, training uses the straight-through estimator — the forward pass carries the quantised vector while the backward pass copies the decoder's gradient directly onto the encoder output, which is implemented as with the stop-gradient operator.
The codebook receives no gradient from that path, so it is trained by two additional terms. The codebook loss pulls each selected entry toward the encoder output it was matched to, and the commitment loss pulls the encoder output toward the entry it chose, preventing the encoder's output space from growing without bound. The full objective is
with in the paper's experiments. Note the asymmetry: the codebook term is unweighted because the codebook has no other learning signal, while scales how strongly the encoder is held to its current assignment.
Unlike a Gaussian VAE there is no KL term to anneal. The prior over the discrete latents is held uniform during training, which makes its KL the constant and removes posterior collapse as a failure mode entirely — the paper's central practical claim. A faithful generative prior is fit afterwards as a separate autoregressive model (PixelCNN over the latent grid), so the auto-encoder trained here is a representation learner and a discrete tokeniser rather than a stand-alone sampler. That tokeniser role is what later made the architecture load-bearing across discrete generative modelling.
Classes
VQVAEConfig2 methodsFrozen configuration for the VQ-VAE family.
VQVAEForImageGeneration3 methodsVQ-VAE with the full training objective and a codebook sampler.
VQVAEModel9 methodsBare discrete-latent auto-encoder — encoder, codebook, decoder.
VQVAEOutput1 methodsForward output of the discrete-latent auto-encoder.