Variational Auto-Encoders (VAEs) are a staple of modern generative modeling, but they frequently suffer from a persistent "generalization gap"—performing significantly better on training data than on unseen test data. While conventional wisdom often points the finger at the decoder (the generative model) for overfitting, research from University College London argues that the real culprit is often the encoder.
This paper demonstrates that the generalization gap in VAEs is primarily caused by the amortized inference network (the encoder) failing to generalize. To address this, the authors propose a "Reverse Half-asleep" training objective that uses model-generated samples to regularize the encoder, significantly improving performance in tasks like lossless compression.
The Problem: Amortized Inference Generalization Gap
In a standard VAE, an encoder maps data $x$ to a latent distribution $q(z|x)$. This is known as amortized inference because a single neural network is trained to predict the "best" latents for any input, rather than optimizing latents for each data point individually.
When performance drops on test data (measured by the Evidence Lower Bound, or ELBO), it is usually assumed the model has "memorized" the training images. However, the authors isolate the problem by comparing the standard encoder against an "optimal inference" strategy, where latent variables are manually optimized for test data points.
They found that the decoder actually generalizes quite well. The massive gap between training and test performance is almost entirely due to the encoder's sub-optimal predictions on unseen data. This creates an amortized inference generalization gap.
As shown above, by using an "Optimal" inference strategy (green line) on test data, the decoder's inherent generalization remains stable. The widening gap to the standard "Test" performance (purple line) is purely the fault of the encoder failing to generalize.
The Solution: Reverse Half-asleep Amortized Inference
For an encoder to generalize, it must be consistent. If the model thinks a certain latent $z$ generates a certain image $x$, the encoder should be able to map that $x$ back to that $z$, regardless of whether $x$ was in the training set.
To enforce this consistency, the authors introduce Reverse Half-asleep Amortized Inference. This method draws inspiration from the classic "Wake-Sleep" algorithm but adds a modern twist:
- Wake Phase: Train the model on real data as usual.
- Sleep Phase: Generate "dreamed" samples from the decoder and train the encoder to reconstruct the latents that produced them. By training on samples generated by the model itself, the encoder effectively sees an "infinite" variety of data, acting as a powerful regularizer against memorizing specific training pixels.
- The "Reverse" Twist: Instead of the standard forward KL divergence used in traditional Wake-Sleep, they use a reverse KL divergence in the sleep phase. This aligns the sleep objective more closely with the ELBO.
- The "Half-asleep" Mixture: The encoder is trained on a mixture of real data and "dreamed" data, controlled by a hyperparameter $\alpha$.
Key Results and Performance
The researchers evaluated their method on three standard benchmarks: Binary MNIST, Grey MNIST, and CIFAR-10. The proposed method consistently outperformed standard VAEs across all datasets.
- Better Compression: In lossless compression, lower Bits-per-dimension (BPD) is better. On Binary MNIST, the method reduced BPD from 0.200 to 0.187. On the more complex CIFAR-10 dataset, it improved BPD from 4.602 to 4.572.
- Zero-Cost Efficiency at Test Time: Unlike "K-step optimal inference," which requires expensive optimization at test time to find good latents, the Reverse Half-asleep method improves the encoder during training. This yields better compression rates with no additional computational cost during actual use.
As seen in the results across different datasets, the Reverse Half-asleep method (orange line) consistently bridges the gap between the standard VAE (pink line) and the theoretical optimal performance (green line).
Limitations and Future Work
While highly effective, the authors acknowledge a few hurdles:
- Training Overhead: Because the "sleep phase" requires generating samples and performing extra gradient steps during training, the initial training process is slower, even though test-time inference remains fast.
- Dependency on Decoder Quality: If the decoder is very poor early in training, the "dreamed" samples will not resemble real data, which might hinder the encoder's ability to learn useful features.
- Future Directions: Having addressed the encoder's gap, future work should investigate how to similarly regularize the decoder to close the remaining generative generalization gap.
Summary updated