Gradient Estimation with Stochastic Softmax Tricks

Max B. Paulus, Dami Choi, Daniel Tarlow, Andreas Krause, Chris J. Maddison

Stochastic Softmax Tricks (SSTs) provide a unified framework for training deep learning models with complex, structured discrete latent variables. By relaxing "hard" combinatorial optimization problems into "soft" differentiable ones, SSTs allow for low-variance gradient estimation and the unsupervised discovery of rich latent structures like spanning trees or specific feature subsets.

The Challenge of Discrete Choices in Deep Learning

Gradient descent is the engine of deep learning, but it hits a wall when models involve discrete choices. If a model needs to pick a specific path in a graph or a subset of features, the "argmax" operation used to make that choice is non-differentiable—it has no gradient to pass back during training.

The well-known Gumbel-Softmax trick solved this for simple categorical choices (picking one item out of $N$) by using a continuous relaxation. However, it fails to scale to "combinatorial" spaces. For example, if you want to pick a spanning tree from a graph, the number of possible trees is astronomically large; you cannot simply enumerate them all to apply a standard softmax. Previously, researchers had to invent bespoke relaxations for every new type of structure, leading to a fragmented landscape of techniques.

Methods: Stochastic Softmax Tricks

The authors introduce Stochastic Softmax Tricks (SSTs), a generalized framework that views discrete sampling as an optimization problem rather than a simple categorical draw.

Visualizing the transition from a discrete finite set to a differentiable continuous relaxation using Stochastic Softmax Tricks.

The framework operates in three main conceptual steps:

  1. Stochastic Argmax Tricks (SMT): They start by defining discrete sampling as a linear program: $X = \arg \max_{x \in \mathcal{X}} U^T x$, where $U$ is a vector of random "utilities" (noise) and $\mathcal{X}$ is a set of discrete objects.
  2. The Relaxation (SST): To make this operation differentiable, the method moves from the discrete set to its convex hull (the polytope containing all valid points) and adds a strongly convex regularizer (such as Shannon entropy).
  3. The Result: This transforms the "hard" argmax into a "soft" solution $X_t$ that is continuous and differentiable. Because many combinatorial problems have efficient solvers, the authors can leverage these algorithms to compute gradients without enumerating the entire state space.

By framing the problem as a perturbed linear program, the authors can use existing, highly optimized combinatorial algorithms (like Kruskal’s for trees or the Hungarian method for matchings) directly within the training loop. The paper demonstrates this framework across several complex structures:

Examples of discrete combinatorial structures represented as matrices, such as k-hot vectors, permutations, and spanning trees.
  • Subset Selection: Picking $k$ items from a set ($k$-hot vectors).
  • Spanning Trees: Finding undirected trees in a graph using Kirchhoff’s Matrix-Tree theorem.
  • Arborescences: Finding rooted, directed trees.

Key Insights and Results

The authors evaluated SSTs across three distinct tasks, revealing several key insights about structure discovery and model performance.

Structure Encourages Discovery: When the latent variable's structure matches the true underlying physics or logic of the problem, the model is significantly better at unsupervised structure discovery. In the Neural Relational Inference (NRI) task—where a model must discover the latent interaction graph between moving particles—the Spanning Tree SST recovered the ground truth latent graph with 91% precision, compared to only 48% for a standard independent-edge baseline.

Task Accuracy: On ListOps, a synthetic dataset of nested arithmetic expressions (e.g., max[ 3 min[ 8 2 ] ]), the model must learn to parse expressions into latent tree structures to predict the final numerical result. The Arborescence SST achieved 95% accuracy, outperforming unstructured Graph Neural Networks (GNNs) and independent edge models.

Interpretability and Noise: The choice of noise (Gumbel vs. Gaussian vs. Exponential) changes the interpretability of the resulting distribution. For instance, negative exponential utilities lead to more interpretable structures in directed trees. In the BeerAdvocate dataset used for the "Learning to Explain" (L2X) task, the "Correlated Top-k" SST selected contiguous blocks of text that were more human-readable and achieved a lower Mean Squared Error (2.9 vs 3.6) compared to standard relaxations.

Limitations and Future Work

While SSTs offer a powerful unified framework, the authors note a few limitations:

  • Marginal Characterization: While it is easy to sample from these models, mathematically characterizing the exact marginal probability of a specific discrete structure remains difficult for many utility distributions.
  • Solver Complexity: Some SSTs require differentiating through complex solvers. While finite difference approximations can be used, this adds computational overhead.
  • Constraint Design: The framework relies on the discrete set being "convex independent." Extending this to more complex constraints, such as those found in general integer programming, remains an open challenge for future research.

Summary updated

BibTeX
@inproceedings{paulus2020gradient,
  author = {Max B. Paulus and Dami Choi and Daniel Tarlow and Andreas Krause and Chris J. Maddison},
  title = {{Gradient Estimation with Stochastic Softmax Tricks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
}
Figure