Vector Quantized Variational Autoencoders (VQ-VAEs) were introduced to address several limitations of regular VAEs:
- The “posterior collapse” problem where the latent code is ignored
- The continuous latent space can make it difficult to model discrete structures
- The aggregated posterior mismatch between $q_\phi(z)$ and the prior $p(z)$
VQ-VAEs solve these issues by using discrete latent variables through vector quantization. The architecture consists of:
An encoder network $E_{\phi}$ that maps input $x \in \mathbb{R}^N$ to continuous latent vectors $z_e = E_{\phi}(x) \in \mathbb{R}^{D}$
A codebook $\mathcal{C} = {e_k}_{k=1}^K$ containing $K$ learnable embedding vectors $e_k \in \mathbb{R}^D$, where typically $K$ is large (e.g., 512 or 1024)
A vector quantization operation that maps $z_e$ to the nearest codebook vector: $z_q = e_k$ where $k = \argmin_j |z_e - e_j|_2$
A decoder network $D_{\theta}$ that reconstructs the input from the quantized vectors: $\hat{x} = D_{\theta}(z_q)$
The training objective consists of three terms:
where:
- $\text{sg}[\cdot]$ is the stop-gradient operator
- The codebook loss updates the embeddings to match the encoder output
- The commitment loss ensures the encoder commits to codebook vectors
- $\beta$ is a hyperparameter controlling the commitment (typically 0.25)
Unlike regular VAEs that use a continuous latent space with sampling and KL divergence regularization, VQ-VAEs use a discrete latent space through the codebook. This allows them to better model discrete structures while avoiding posterior collapse and distribution matching issues.