Paper commentary
Neural Discrete Representation Learning
- Problem Continuous-latent VAEs dominate, while discrete-latent VAEs are hard to train and often suffer posterior collapse when the decoder is powerful.
- Method Each encoder output is snapped to its nearest vector in a learned embedding table, the decoder receives that vector, gradients are copied through the lookup, and an autoregressive prior is fitted after the autoencoder is trained.
Why discrete latents are hard in VAEs
A VAE with a powerful autoregressive decoder can end up ignoring its latent variables, a failure called posterior collapse. Discrete latents suit language, speech and many image descriptions, yet training them has proven difficult, so most work relies on continuous latents. NVIL uses a single-sample objective with variance-reduction techniques, VIMCO uses a multi-sample objective, and the Concrete and Gumbel-softmax relaxations anneal a temperature towards a discrete distribution.
None of these closes the gap with continuous VAEs, which can use the Gaussian reparameterisation trick and gain from its lower gradient variance, and most of these methods were tested on small datasets such as MNIST with low-dimensional latents.
The VQ-VAE keeps the VAE structure of an encoder, a prior and a decoder, but makes the posterior categorical and deterministic. The authors argue that this avoids posterior collapse and removes variance problems, and that it reaches likelihood close to continuous counterparts. The likelihood comparison is on CIFAR10, while the reconstruction, sampling and speech experiments use ImageNet, DeepMind Lab and VCTK.
From encoder output to discrete code
The latent space is a table of K embedding vectors, each of dimension D, and the discrete latent is a K-way categorical index into that table. For an input x, the encoder produces z_e(x), and the discrete code is the index k of the embedding closest to it in L2 distance, following \( k = \arg\min_j \lVert z_e(x) - e_j \rVert_2 \). The decoder then receives the selected embedding \( z_q(x) = e_k \), so the forward pass behaves like an ordinary autoencoder with a non-linearity that maps each latent to one of K vectors.
The posterior is deterministic: the one-hot probability is 1 for the nearest index and 0 otherwise. With a uniform prior over the K codes, the KL term is constant and equal to log K, so the model is viewed as a VAE whose ELBO bounds log p(x). For speech, images and video the same mechanism yields 1D, 2D and 3D latent feature maps, and the parameters are the union of the encoder, decoder and embedding parameters.
Gradient copy and the three loss terms
The nearest-neighbour step has no real gradient, so the gradient at the decoder input is copied to the encoder output, similar to the straight-through estimator. Figure 1 shows why this copy is informative: the decoder gradient indicates how the encoder output should move, and a small move can change which embedding is selected in the next forward pass.
The authors note that using the subgradient through the quantisation operation is an alternative, but the simple copy worked well in their initial experiments.
The embeddings receive no gradient from the reconstruction term, so a vector quantisation term moves each embedding towards the encoder outputs assigned to it. The total objective is \[ L = \log p(x \mid z_q(x)) + \lVert sg[z_e(x)] - e \rVert_2^2 + \beta \lVert z_e(x) - sg[e] \rVert_2^2 \] where sg is the stopgradient operator, which is the identity in the forward pass and has zero partial derivatives.
The commitment term, weighted by beta, keeps the encoder output close to its selected embedding, so the encoder output does not grow while the embeddings lag behind. The authors mention updating the embeddings with moving averages of the encoder outputs, but did not use it in their experiments.
The decoder optimises the reconstruction term only, the encoder optimises the reconstruction and commitment terms, and the embeddings optimise the vector quantisation term. Beta was set to 0.25 in all experiments, and the authors report that results did not change for beta between 0.1 and 2.0. With N discrete latents per input, the vector quantisation and commitment terms are averaged over the latents, for example 32 x 32 latents for ImageNet and 8 x 8 x 10 for CIFAR10.
Fitting the prior after autoencoder training
While the VQ-VAE is trained, the prior over the discrete latents is held constant and uniform. Afterwards an autoregressive distribution is fitted over the latents, which is then sampled ancestrally to generate x, using a PixelCNN for images and a WaveNet for raw audio. Training the prior and the VQ-VAE jointly could strengthen the results, and the authors leave it as future research.
Because the decoder is trained on the quantised latent, the authors approximate log p(x) by the term evaluated at z_q(x), and they note from Jensen's inequality that this gives a lower bound. The authors evaluate this approximation empirically in the experiments.
CIFAR10 likelihood against continuous VAEs
The VAE, VQ-VAE and VIMCO models share one standard VAE architecture on CIFAR10, and the latent capacity is varied between them. The encoder uses two strided convolutions with stride 2 and a 4x4 window, followed by two residual 3x3 blocks with 256 hidden units, and the decoder mirrors it with two transposed convolutions. Training uses the ADAM optimiser with learning rate 2e-4, runs 250,000 steps with batch size 128, and VIMCO uses 50 samples in its multi-sample objective.
The authors say their continuous VAE number is comparable to a deep convolutional VAE reported at 4.54 bits/dim in prior work, and they describe the VQ-VAE as the first discrete-latent model to challenge continuous VAEs in this way.
ImageNet compression and PixelCNN samples
The authors compress 128x128x3 ImageNet images to a 32x32x1 discrete space with K=512, using a purely deconvolutional decoder. The paper gives this as a reduction of about 42.6 in bits.
A PixelCNN prior is trained on the 32x32x1 grid, and because there is one channel only spatial masking is needed. Its capacity is similar to that used by the PixelCNN authors. Figure 3 shows 128x128 samples decoded from this prior through the VQ-VAE decoder, including labels such as kit fox and gray whale.
The same procedure is applied to 84x84x3 DeepMind Lab frames, whose reconstructions look nearly identical to the originals. A PixelCNN prior on the 21x21x1 latent space produces the samples in Figure 4, decoded with a deconvolutional decoder.
Second-stage latents that are still used
The authors train a second VQ-VAE with a PixelCNN decoder on the 21x21x1 first-stage latents, a setup they note typically breaks VAEs through posterior collapse. In their model the second-stage latents are used, because the second stage has three latent variables with K=512 and their own embedding spaces.
The three latents carry 27 bits for the whole image, so the model cannot reconstruct the frames perfectly. Figure 5 shows originals above and reconstructions below, sampled from the second PixelCNN prior and decoded to 84x84. The authors describe the room layout and walls as preserved, while the textures are generated procedurally by the PixelCNN rather than stored as pixel values.
Speech reconstructions that keep content, not prosody
On VCTK, which has recordings of 109 speakers, the encoder uses six strided convolutions with stride 2 and window size 4. The latent space is 64 times smaller than the waveform, with one feature map and a 512-dimensional discrete space, and the decoder is conditioned on the latents and a one-hot speaker embedding.
Reconstructions keep the same spoken text, but the waveform differs and the prosody of the voice is altered. The authors read this as the model learning a high-level space that ignores low-level features and encodes the content of the speech, without any linguistic supervision. The evidence for these reconstructions is the linked audio samples and listening, with no score reported in the paper.
Unconditional speech samples
The prior is trained on a larger dataset of 460 speakers, with a discrete space 128 times smaller than the input resolution. Training uses chunks of 40960 timesteps (2.56 seconds), which give 320 latent timesteps.
The authors describe samples from the original WaveNet as babbling, while samples from the VQ-VAE contain clear words and part-sentences. They conclude that the model learns a rudimentary phoneme-level language model from raw waveforms without supervision.
Speaker conversion by changing the speaker identity
Latents are extracted from one speaker and decoded with a different speaker identity, which the authors call speaker conversion. The synthesised speech keeps the content of the original but takes the voice of the second speaker. The authors interpret this as the encoding having factored out speaker-specific information.
Latent codes against ground-truth phonemes
Each of the 128 possible latent values is mapped to its most likely phoneme among 41 phonemes, and the 41-way accuracy is 49.3%. A random latent space, scored with the prior's most likely phoneme, reaches 7.2%. The authors conclude that the codes are high-level speech descriptors closely related to phonemes.
The authors note that a mapping in which each latent depends on previous latents, such as bi- or tri-grams, could compress more and that a more advanced mapping would give higher accuracy.
Action-conditioned video generated in latent space
The prior generates the latent sequence, and each frame is then decoded to pixels by the deterministic decoder, so video is produced purely in latent space. Six input frames are followed by 10 generated frames, with all actions set to forward in the top row and right in the bottom row.
The authors report that the generated sequences keep the local geometry without visible degradation. A model trained without actions gave similar results, which the authors do not show because of space constraints.
Limitations
The prior is fitted after the autoencoder, and joint training is left as future research. The second stage uses three latents, so DeepMind Lab reconstructions are imperfect at 27 bits. The soft-to-hard relaxation could not be trained from scratch in the authors' experiments, because the decoder inverted the continuous relaxation.
The continuous-latent comparison is on CIFAR10 only, with one architecture and one training budget. Beta was checked only from 0.1 to 2.0. The image, speech and video quality claims rest on samples and visual or auditory inspection, apart from the phoneme accuracy. The phoneme accuracy uses one latent-to-phoneme assignment, and the authors note a more advanced mapping could score higher.
Paper info
- Authors
- Aaron van den Oord, Oriol Vinyals, Koray Kavukcuoglu
- Venue
- arXiv · Preprint
- First published
- 2017-11-2
- Added
- 2026-10-20
- Updated
- 2018-5-30
- Version
- v2
- arXiv
- 1711.00937
- Category
- cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Aaron van den Oord, Oriol Vinyals, Koray Kavukcuoglu (2017). Neural Discrete Representation Learning. arXiv:1711.00937v2. https://arxiv.org/abs/1711.00937v2
BibTeX
@misc{oord2017neural,
title = {{Neural Discrete Representation Learning}},
author = {Aaron van den Oord and Oriol Vinyals and Koray Kavukcuoglu},
year = {2017},
eprint = {1711.00937},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1711.00937v2}
}