Generalization Gap in Amortized Inference

Mingtian Zhang, Peter Hayes, David Barber

Abstract

The ability of likelihood-based probabilistic models to generalize to unseen data is central to many machine learning applications such as lossless compression. In this work, we study the generalization of a popular class of probabilistic model - the Variational Auto-Encoder (VAE). We discuss the two generalization gaps that affect VAEs and show that overfitting is usually dominated by amortized inference. Based on this observation, we propose a new training objective that improves the generalization of amortized inference. We demonstrate how our method can improve performance in the context of image modeling and lossless compression.

Introduction

Variational Auto-Encoders (VAEs) are fundamental tools in modern machine learning, utilized for tasks ranging from generative modeling to high-efficiency lossless compression. However, VAEs frequently suffer from a "generalization gap," where the model performs significantly better on training data than on unseen test data.

Traditionally, researchers have assumed that this gap stems from the decoder (the generative model) memorizing specific training samples. This paper challenges that assumption, demonstrating that the primary source of overfitting is actually the encoder (the inference network). By identifying and addressing the "amortized inference gap," we can significantly improve the model's ability to generalize to new data.

Decomposing the Generalization Gap

To understand why VAEs overfit, the authors decompose the standard VAE objective—the Evidence Lower Bound (ELBO)—into two distinct components:

  1. The Generative Model Gap: This represents how well the decoder approximates the true underlying data distribution.
  2. The Amortized Inference Gap: This represents how well the encoder approximates the true posterior distribution for a given input.

Through experiments where inference was "fixed" at test time using slow, iterative optimization (optimal inference), the researchers discovered that the decoder actually generalizes quite well. The drop in performance on test data is largely caused by the encoder failing to provide accurate latent codes for data it hasn't seen before. In other words, the encoder overfits to the training set, even when the decoder does not.

Method: Reverse Half-asleep Inference

To bridge the amortized inference gap, the authors introduce Reverse Half-asleep Inference. This method is built on the "inference consistency requirement": if a model is internally consistent, the encoder should be able to correctly map any data point generated by the decoder back to its latent representation.

Since the decoder can generate an infinite amount of "dreamed" data, this synthetic data can be used to train the encoder. The proposed method uses a mixing parameter ($\alpha$) to balance training:

  • Real Data: The encoder learns from the actual training set.
  • Dreamed Data: The encoder learns from samples generated by the decoder.

Setting $\alpha=0.5$ (an equal mix) acts as a powerful regularizer. It forces the encoder to learn the underlying logic of the generative model rather than just memorizing specific training points. This effectively provides the encoder with an infinite training set, ensuring it can handle any data point the model considers "valid."

Experimental Results

The researchers evaluated the method on Binary MNIST, Grey MNIST, and CIFAR10. The primary metric was Bits-per-dimension (BPD), where a lower score indicates better model fit and more efficient compression.

Key Findings:

  • Improved Generalization: Across all datasets, Reverse Half-asleep Inference achieved lower test BPD than standard VAE training, successfully narrowing the generalization gap.
  • Compression Efficiency: In lossless compression tasks, the method achieved the same high-quality compression rates as "Optimal Inference" but at the speed of a standard VAE.
  • Computational Savings: To achieve similar BPD results using standard VAEs, one would need to perform multiple iterative optimization steps at test time, increasing compression time by 46% to 116%. The proposed method provides these gains "for free" during the inference phase.

Limitations and Future Work

While the method significantly improves the encoder, the authors note that the decoder still exhibits a small degree of overfitting, which remains a subject for future research. Additionally, the training phase is more computationally intensive because the model must generate and process synthetic samples.

There is also a "cold start" challenge: if the method is used from the beginning of training, a poor decoder will generate low-quality "garbage" images, which can lead the encoder astray. Currently, the most effective strategy is to use this method as a fine-tuning step after initial standard training. Future work will focus on stabilizing this dream-based training from the start of the learning process.

Summary updated

BibTeX
@inproceedings{zhang2022generalization,
  author = {Mingtian Zhang and Peter Hayes and David Barber},
  title = {{Generalization Gap in Amortized Inference}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=Wxkbjkw8yu},
}
Figure