Negative Sampling in Variational Autoencoders

Adrián Csiszárik, Beatrix Benko, Dániel VargaarXiv 2019

Abstract

Modern deep artificial neural networks have achieved great success in the domain of computer vision and beyond. However, their application to many real-world tasks is undermined by certain limitations, such as overconfident uncertainty estimates on out-of-distribution data or performance deterioration under data distribution shifts. Several types of deep learning models used for density estimation through probabilistic generative modeling have been shown to fail to detect out-of-distribution samples by assigning higher likelihoods to anomalous data. We investigate this failure mode in Variational Autoencoder models, which are also prone to this, and improve upon the out-of-distribution generalization performance of the model by employing an alternative training scheme utilizing negative samples. We present a fully unsupervised version: when the model is trained in an adversarial manner, the generator's own outputs can be used as negative samples. We demonstrate empirically the effectiveness of the approach in reducing the overconfident likelihood estimates of out-of-distribution inputs on image data.

Introduction

A persistent challenge in generative modeling is the "likelihood paradox," where models assign higher probability to out-of-distribution (OOD) data than to the training data itself. For instance, a Variational Autoencoder (VAE) trained on Fashion-MNIST might assign a higher likelihood to MNIST digits, which it has never seen. This failure mode makes VAEs unreliable for safety-critical applications like medical imaging or autonomous driving. This paper proposes a training scheme using negative sampling to force the model to learn the boundaries of the data manifold more effectively.

Methodology

The authors introduce two primary mechanisms to incorporate negative signals during training:

  1. Negative Prior: In addition to the standard Gaussian prior for "positive" (real) samples, a shifted "negative prior" is introduced. The model is trained to map OOD samples to this shifted distribution in the latent space.
  2. Evidence Upper Bound (EUBO): While standard VAEs maximize the Evidence Lower Bound (ELBO) for real data, the authors utilize an upper bound (EUBO) to explicitly minimize the likelihood of negative samples.

Negative samples are sourced either from auxiliary datasets (e.g., using MNIST as negatives for a Fashion-MNIST model) or through adversarial training, where the VAE’s own generator produces samples that the encoder must then learn to reject.

Experimental Results

The effectiveness of negative sampling was evaluated across several benchmarks, including MNIST, Fashion-MNIST, CIFAR-10, and SVHN.

AUC results for grayscale datasets comparing baseline VAE with auxiliary and adversarial negative sampling.

As shown in Figure 1, the baseline VAE often fails to distinguish between datasets, sometimes performing worse than random chance (e.g., AUC BPD of 0.46 for Fashion-MNIST vs. MNIST). Incorporating auxiliary negative samples can lead to near-perfect OOD detection (AUC 1.00), while the unsupervised adversarial approach also provides significant gains, typically reaching AUCs between 0.70 and 0.90.

AUC results for color datasets (CIFAR-10 and SVHN) demonstrating the effectiveness of negative sampling.

The results extend to color images as well. In Figure 2, the CIFAR-10 vs. SVHN task shows that negative sampling substantially improves OOD detection over the baseline, particularly when using auxiliary data.

Discussion and Insights

  • Near-Manifold Necessity: Effective negative samples must be "near-manifold"—they should resemble real data enough to challenge the model. Simple random noise is often too easy to distinguish and provides little benefit.
  • Noise Model Impact: The choice of output distribution (Bernoulli vs. Gaussian) affects OOD performance. While Gaussian models sometimes mitigate the paradox, they do not resolve it without negative sampling.
  • Latent Space Metrics: The KL divergence in the latent space often serves as a more reliable OOD indicator than raw likelihood scores.

Conclusion

Negative sampling significantly improves the robustness of VAEs against OOD data. While the method introduces some computational overhead and hyperparameter sensitivity (e.g., the shift of the negative prior), it provides a consistent and effective way to address the likelihood paradox in generative models.

Summary updated

BibTeX
@misc{csiszarik2019negative,
  author = {Adrián Csiszárik and Beatrix Benko and Dániel Varga},
  title = {{Negative Sampling in Variational Autoencoders}},
  year = {2019},
  eprint = {1910.02760},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.02760},
}
Figure