Categorical Reparameterization with Gumbel-Softmax

Eric Jang, Shixiang Gu, Ben Poole

Introduction

Deep learning thrives on gradients. To train a neural network using standard backpropagation, we need to know how a small change in a parameter affects the final output. This works perfectly for continuous values, but breaks down when the model involves discrete choices—such as picking one of ten categories or routing information through a discrete graph.

Sampling from a categorical distribution is a "jumpy," non-differentiable operation. Traditionally, researchers dealt with this using Score Function Estimators (like REINFORCE), which are unbiased but suffer from extremely high variance, making training slow and unstable. Alternatively, one could use marginalization (calculating the probability of every possible outcome), but this becomes computationally impossible as the number of categories or latent variables grows due to the curse of dimensionality.

This paper introduces the Gumbel-Softmax, a simple and effective continuous relaxation that allows researchers to train neural networks with discrete (categorical) latent variables using standard backpropagation. By replacing non-differentiable discrete samples with a differentiable approximation, the authors enable end-to-end training of models that previously required complex, high-variance gradient estimators.

The Gumbel-Softmax Relaxation

The core innovation is the Gumbel-Softmax distribution, a continuous distribution on the simplex that can smoothly approximate categorical samples.

The authors start with the "Gumbel-Max trick," a known method for sampling discrete variables: add Gumbel-distributed noise to the log-probabilities of your categories and take the argmax. However, because argmax is still non-differentiable, they replace it with a softmax function.

To control how closely this continuous relaxation approximates a true discrete choice, they introduce a temperature parameter ($\tau$).

  • As $\tau \to \infty$, the output becomes a uniform, smooth distribution.
  • As $\tau \to 0$, the output approaches a "one-hot" vector, effectively mimicking a discrete sample.
Gumbel-Softmax distribution at different temperatures

For tasks requiring strictly discrete values in the forward pass, the authors also propose a "Straight-Through" (ST) Gumbel-Softmax. It uses the discrete argmax for the forward pass but uses the continuous Gumbel-Softmax gradient for the backward pass.

Key Insights

The primary breakthrough is the realization that we don't need perfectly discrete samples during the entire training process. By starting with a high temperature and "annealing" (lowering) it over time, the model can learn from smooth, well-behaved gradients early on and gradually specialize into making sharp, discrete decisions.

This introduces a favorable bias-variance trade-off. While Gumbel-Softmax is a biased estimator (unlike REINFORCE), its variance is significantly lower. In practice, accepting a little bias is a small price to pay for much more stable and faster convergence. Furthermore, in semi-supervised learning, standard methods marginalize over all possible classes. Gumbel-Softmax allows the model to simply sample a class and backpropagate through it, breaking the marginalization bottleneck and making it highly scalable for problems with many categories.

Experimental Results

The authors evaluated their method on several generative modeling and prediction tasks using binarized and semi-supervised MNIST datasets.

Superior Performance: On structured output prediction and generative modeling tasks (like training Variational Autoencoders and Sigmoid Belief Nets), the Gumbel-Softmax estimator consistently achieved better variational lower bounds compared to state-of-the-art estimators like NVIL, DARN, and MuProp.

Training curves comparing Gumbel-Softmax to other estimators on a Categorical SBN

Massive Speedups: In semi-supervised classification setups with 100 labeled examples and 50,000 unlabeled examples, Gumbel-Softmax achieved nearly identical accuracy to exact marginalization methods but was 9.9x faster when dealing with 100 categories. The method proved highly versatile, effective for both Bernoulli (binary) and Categorical (multi-class) latent variables.

Limitations and Future Work

Despite its success, the method has limitations. The performance of the model is highly sensitive to the annealing schedule of the temperature $\tau$, meaning finding the "sweet spot" requires careful hyperparameter tuning. Additionally, while high temperatures provide stable gradients, they also introduce more bias because the "samples" look less like discrete choices and more like uniform noise.

Future directions suggested by the authors include exploring more complex, adaptive annealing schedules and applying the technique to even larger-scale discrete problems, such as reinforcement learning with massive action spaces or natural language processing tasks.

Summary updated

BibTeX
@inproceedings{jang2017categorical,
  author = {Eric Jang and Shixiang Gu and Ben Poole},
  title = {{Categorical Reparameterization with Gumbel-Softmax}},
  booktitle = {International Conference on Learning Representations},
  year = {2017},
  url = {https://openreview.net/forum?id=rkE3y85ee},
}
Figure