CR-VAE: Contrastive Regularization on Variational Autoencoders for Preventing Posterior Collapse

Fotios Lygerakis, Elmar Rueckert

Introduction

Variational Autoencoders (VAEs) are fundamental models in the generative deep learning landscape, designed to learn latent representations of data by maximizing the Evidence Lower Bound (ELBO). However, a persistent challenge in training VAEs is the phenomenon of posterior collapse. This occurs when the decoder becomes sufficiently powerful to reconstruct the data using its own internal priors, effectively ignoring the latent code provided by the encoder. Consequently, the encoder fails to learn meaningful features, and the latent space collapses into a state where it is independent of the input, rendering the model useless for representation learning.

To address this, the authors introduce Contrastive Regularization for VAEs (CR-VAE), a method that leverages contrastive learning to ensure the latent space remains informative and robust against collapse.

Methodology

The CR-VAE Objective

The core innovation of CR-VAE is the addition of a contrastive regularization term to the standard VAE objective. By incorporating the InfoNCE loss, the model is explicitly incentivized to maximize the Mutual Information (MI) between the input data and its corresponding latent representation. The modified loss function is defined as:

$$\mathcal{L}_{CR} = \mathcal{L}_{VAE} + \gamma \cdot \mathcal{L}_{InfoNCE}$$

While the standard VAE objective can mathematically encourage the minimization of mutual information (leading to collapse), the $\mathcal{L}_{InfoNCE}$ term acts as a lower bound on MI, creating a necessary tension that forces the encoder to capture salient features.

Architecture and Contrastive Task

CR-VAE adopts a Momentum Contrast (MoCo) framework to implement the contrastive task efficiently. The system maintains two encoders:

  1. Query Encoder: Updated via standard backpropagation.
  2. Key Encoder: Updated as an Exponential Moving Average (EMA) of the query encoder's weights.

For any given input, the model generates a "positive pair" through data augmentations such as random cropping or flipping. The contrastive objective requires the model to align the latent representations of these two views while simultaneously pushing them away from "negative samples" (other unrelated images in the batch). This process ensures that the latent code is not just noise, but a discriminative feature set.

Experimental Results

The effectiveness of CR-VAE was evaluated across several benchmarks, including MNIST, EMNIST, FashionMNIST, CIFAR10, and Omniglot. The results demonstrate that CR-VAE significantly outperforms standard VAEs and existing baselines like InfoVAE and InfoMax-VAE.

Quantitative Performance

  • Representation Quality: On the EMNIST dataset, the linear classification accuracy of the learned representations improved from 2.74% in a standard VAE to 52.90% with CR-VAE. This indicates that the latent space captured significantly more structural information.
  • Active Units (AU): The AU metric measures how many latent dimensions are utilized by the model. In tests on MNIST, the standard VAE suffered from total collapse (0 active units), whereas CR-VAE utilized all 16 available dimensions.
  • Mutual Information (MI): CR-VAE consistently achieved the highest MI scores across all datasets, confirming that the latent codes remained highly informative of the input features.

Qualitative Insights

Visualizations using t-SNE reveal a stark contrast between models. While standard VAEs often produce a single, undifferentiated cluster of points—indicative of a collapsed latent space—CR-VAE produces well-defined, separated clusters that correspond to the underlying data classes.

Discussion and Limitations

CR-VAE offers a computationally straightforward modification to the VAE loss function without requiring complex architectural changes like skip connections or specialized update schedules. However, the authors note some dependencies:

  • Batch Size: The strength of the InfoNCE bound is logarithmic to the batch size. Larger batches (e.g., 256) provide a stronger signal to prevent collapse, which may pose memory constraints in some environments.
  • Data Complexity: While CR-VAE showed marked improvements on natural images (CIFAR10), the performance gap was less dramatic than on simpler datasets like MNIST. This suggests that complex natural images may require more sophisticated augmentation strategies or larger latent capacities.

Conclusion

CR-VAE provides a robust solution to the problem of posterior collapse by integrating contrastive learning into the VAE framework. By maximizing mutual information, the model prevents the encoder from becoming "lazy," resulting in latent representations that are far more effective for downstream tasks. Future work will explore the application of CR-VAE in reinforcement learning and its scalability to even larger, more complex datasets.

Summary updated

BibTeX
@misc{lygerakis2023cr,
  author = {Fotios Lygerakis and Elmar Rueckert},
  title = {{CR-VAE: Contrastive Regularization on Variational Autoencoders for Preventing Posterior Collapse}},
  year = {2023},
  eprint = {2309.02968},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2309.02968},
}
Figure