| Structures and loss | |
|---|---|
| finite set of structures; their binary vectors | |
| length of the binary vectors; the number of categories when one-hot | |
| convex hull of | |
| discrete sample; its relaxation at temperature | |
| loss | |
| parameters; the distribution of | |
| one-hot vector of category | |
| Noise and relaxation | |
| independent standard Gumbel noise | |
| random utility vector | |
| temperature; tempered softmax | |
| strongly convex regularizer | |
| indicator of ; ; its convex conjugate | |
| exponential-family mean map; conjugate of the log-partition function | |
| ; standard exponential variables (Step 7) | |
| Estimators | |
| true gradient | |
| straight-through Gumbel-Softmax; its conditional expectation given | |
| Gumbel-Rao with conditional draws; average of copies | |
| trace of the covariance matrix | |
| Constants | |
| conditional Gumbel draws per estimate; Gumbel-Rao Propositions 2 and 3 | |
| batch size; Gumbel-Rao Proposition 3 | |
| finite-difference step (Step 3) | |
| subset size in -subset models | |
Context. Models with a discrete choice inside, such as a subset of words that explains a prediction, a latent graph or a parse tree, are trained by gradient descent on an expected loss , where the discrete random depends on parameters . The score-function estimator, unbiased for because ; called REINFORCE in reinforcement learning (REINFORCE) is unbiased and needs only values of the loss, but its variance is high unless it is paired with good control variatesterms of known mean subtracted from an estimator to lower its variance, such as a baseline in . Relaxed estimators accept bias for lower variance. The Gumbel-Max trick, with independent standard Gumbel variables (distribution function ), is a draw from the categorical distribution writes a categorical sample as the argmax of the logits plus independent Gumbel noise, and the Gumbel-Softmax estimator (Jang et al., 2017; Maddison et al., 2017) replaces the argmax by a softmax at a temperature in ; as the softmax tends to the one-hot argmax and differentiates through it. That needs one noise variable per outcome, which rules out distributions over all spanning trees of a graph or all -element subsets. Paulus et al. (2020) extend the trick to such structured sets. Paulus et al. (2021) take its straight-througha gradient estimator that uses the discrete sample in the forward pass and backpropagates as if a smooth surrogate had been used variant, which keeps the discrete sample in the forward pass, and lower its variance without evaluating the loss again.
Many structured distributions can be sampled by solving a linear program with random utilities, and adding a strongly convex regularizer to that program turns its solution into a continuous function of the utilities that tends to the discrete sample as the temperature goes to 0. The Gumbel-Softmax recipe then applies to any structure for which the regularized problem can be solved. In the straight-through estimator the noise enters only through a softmax Jacobian, and averaging that Jacobian over the noise consistent with the sampled outcome keeps the estimator's mean and lowers its mean squared error, with a few extra softmax evaluations. Both estimators are biased for the discrete gradient and need a loss that is differentiable in ; REINFORCE needs neither, which is why it remains the tool when the loss is a black-box reward.
Setting. Let be a finite set of structures, each represented by a binary vector in : a one-hot vector for a category, edge indicators for a spanning tree, a -hot vector for a subset of size . Write for the set of these vectors and for its convex hull, all convex combinations of the vectors . For a loss the target isFor one-hot and , the Gumbel-Max sample is with a vector of independent standard Gumbel variables, one per coordinate the noise, the Gumbel-Softmax sample is , and the estimator is unbiased for , the gradient of the relaxed objective, and biased for the target. The straight-through Gumbel-Softmax (ST-GS) evaluates the loss at the discrete and backpropagates through built from the same noise,It is not known to be unbiased for any gradient, but it has low variance and leaves the forward computation discrete.
Main results. (a) Stochastic softmax tricks (Paulus et al., 2020). The definitions separate how a structure is sampled from how the sample is smoothed. A stochastic argmax trick (SMT) is a random utility vector whose distribution is set by , with sample ; one-hot with is Gumbel-Max. A stochastic softmax trick (SST) at temperature adds a regularizer that is proper, closed and strongly convexwhy: strong convexity makes the maximizer unique and a Lipschitz function of (Step 3), which the pathwise gradient needs; proper and closed are the standard technical conditions for convex duality, with domain containing the relative interiorthe interior of taken within the smallest affine space containing of :Gumbel-Softmax is one-hot , and . Proposition 1: if is almost surely uniquewhy: with ties the argmax, and so the sample, is undefined; it holds whenever for every , as for any with a density, then almost surely as , and if is bounded and continuous on why: continuity carries over to , and boundedness lets dominated convergence move the limit inside the expectation, then . Proposition 2: exists, is unique, and is continuous and almost everywhere differentiable in , so for reparameterizablewritten as a differentiable function of and of noise whose law does not depend on , such as the estimatoris unbiased for when is differentiable on and satisfies a local Lipschitz condition in . (b) Gumbel-Rao (Paulus et al., 2021). The second paper's estimator is the Rao-Blackwellizationreplacement of an estimator by its conditional expectation given some statistic; the mean is unchanged and the mean squared error cannot rise (the Rao-Blackwell theorem) of ST-GS given the discrete outcome,and writing the true gradient of the discrete objective, its Proposition 1 gives . The practical version averages the Jacobian over draws of conditional on and satisfies the same inequality for every (Proposition 2). Averaging independent copies, as a minibatch does, gives (Proposition 3, with var the trace of the covariance)
Consequences and limits. An SST is a recipe with three choices: an embedding with a fast linear solver, a utility distribution for , and a regularizer for which the regularized problem can be solved and differentiated; one trains at a fixed chosen on validation data and evaluates with the discrete . In the experiments, relaxations that matched the true latent structure (spanning trees, arborescencesdirected spanning trees in which every node is reached from a chosen root, correlated subsets) recovered more of it than independent-edge or task-specific relaxations, the utility distribution changed results a lot, and the regularizer changed them little (Step 5). Gumbel-Rao replaces only the backward pass of ST-GS and adds no loss evaluations; its gain is largest at small batch sizes, where the noise given dominates (Proposition 3), and at low temperatures, and in the experiments it let training use lower temperatures (Step 8). The evidence for both is a handful of latent-variable benchmarks.
Set against the score-function estimator, both methods are biased for : an SST follows the relaxed objective and needs defined and differentiable on all of , and straight-through needs differentiable at the vertices. REINFORCE, with baselines and several samples per input, remains the choice when the loss is a black box, such as a reward from an environment or a score given to sampled text. The papers' comparisons with it are limited. Gumbel-Rao's uses only REINFORCE with a running-mean baseline, which lags far behind (Step 8). The SST paper's, on the graph task only, uses tuned moving-average, batch-mean, multi-sample and learned baselines but, because the probability of a given spanning tree is intractable, treats the utility as the sampled variable, which the authors call atypical (Step 5). Neither paper tests score-function estimators with stronger control variates, such as REBAR (Tucker et al., 2017) or RELAX (Grathwohl et al., 2018), so how far the best of them stays behind on these tasks is not measured.
The argmax has zero gradient almost everywhere, and a continuous relaxation restores the pathwise derivative. As a function of , is piecewise constant: it is differentiable almost everywhere with derivative 0, so while generally is not 0. All the dependence on sits in the jumps, which break the exchange of derivative and expectation. A relaxation that is continuous in the noise, such as the softmax, makes the exchange valid for the relaxed objective. The temperature sets the balance between bias and variance: as the relaxed sample approaches , so the bias falls, while the softmax Jacobian at is tiny except near ties between utilities, where it grows like , so the variance rises, as the Gumbel-Rao paper reports.
A linear program with random utilities defines the model, and its solver draws the sample. A linear function on is maximized at a vertex, and a unique maximizer over is the unique maximizer over , so drawing means solving a linear program; the sample is unique almost surely when gives no mass to any hyperplane . Fast solvers exist for many structures: the top entries of by sorting for -subsets, Kruskal's algorithm for a maximum spanning tree, Chu-Liu-Edmonds for an arborescence, the Hungarian method for matchings. Only a solver is needed, so sampling is cheap for sets far too large to enumerate. In exchange is defined only implicitly: for structured the law of under Gumbel utilities is in general not and is hard to characterize, so the paper treats as a modeling choice and warns against defaulting to or without analysis.
Strong convexity makes the regularized argmax the gradient of a smooth convex function. Write for the convex indicator of (0 on , outside), , and for its convex conjugate; when the supremum is attained at a unique point, is that point. By conjugate dualityThe conjugate of a strongly convex function is differentiable with a Lipschitz gradient, so is unique and continuous in , and Rademacher's theorema Lipschitz function on is differentiable almost everywhere makes it differentiable almost everywhere: Proposition 2. As , increases to the support function, the value of the linear program over of . Where that linear program has a unique solution, the support function is differentiable on a neighborhood of , and pointwise convergence of convex functions then carries over to their gradients, so : Proposition 1. Because is the Hessian of , it is symmetric, so the vector-Jacobian product that backpropagation needs is a directional derivative of , computable for a small step with two extra solves and no extra loss evaluation:
Projections, entropies and marginal inference give computable relaxations. With , is the Euclidean projection of onto . On the simplex the categorical entropy gives the softmax, and for independent bits the binary entropy gives the sigmoid. The most general choice comes from an exponential familythe distributions on , indexed by the natural parameter : for on , the mean of solves a problem of exactly the SST form,with the convex conjugate of the log-partition function ; at a mean it is minus the entropy of the family member with mean the conjugate of the log-partition function, a negative entropy; then . Computing it is marginal inferencecomputing the marginal probabilities, here the mean vector , of a distribution over structures: for spanning trees the edge marginals follow from Kirchhoff's matrix-tree theoremthe sum of edge-weight products over all spanning trees of a graph equals a determinant of its reduced weighted Laplacian; edge marginals follow from that determinant's derivatives (a directed version for arborescences), and for a chain with a cardinality constraint from dynamic programming. As an SST tends to a random draw from the SMT, because is random; annealing marginal inference toward a single most probable structure is a different limit.
Matching the true structure improves recovery and fit, and the noise distribution matters more than the regularizer. Hyperparameters, including the fixed training temperature, were chosen by random search, and models were trained with and evaluated with . In Neural Relational Inferencea graph neural network whose encoder samples a latent interaction graph from observed particle trajectories and whose decoder predicts the motion by passing messages over that graph, trained on a variational lower bound on particles whose latent interaction graph is a spanning tree over 10 vertices, the spanning-tree SST reached an ELBOevidence lower bound: the variational lower bound on used as the training objective of and edge precision and recall of 91% from 10 observed time steps, against and 48% precision for the original independent-edge encoder, and from 20 steps it recovered 99% of edges. On a simplified ListOpssequences of nested prefix arithmetic such as max[ 3 min[ 8 2 ]], each labeled by its value from 0 to 9; the syntax defines a parse tree, where the true parse is a directed tree rooted at the first token, the arborescence SST with Gumbel utilities reached 95.0% task accuracy with 75.5% edge precision and 71.9% recall, against 90.1%, 13.0% and 56.4% for independent directed edges and 92.1% accuracy for an LSTM, and the same arborescence with negative exponential utilities reached only 71.5%. In L2Xlearning to explain: a model must predict a label from input words it selects, so the selected words explain the prediction on the aroma rating of beer reviews, the correlated -subset SST, whose utilities link neighboring words, raised the precision of the selected words from 28.3% with L2X's own relaxation to 63.1% at with the one-layer convolutional encoder and lowered the mean squared error from 0.036 to 0.029, while the four regularizers for plain top- differed little. In an appendix, score-function estimators on the graph task (REINFORCE with moving-average, batch-mean or multi-sample baselines, and NVILneural variational inference and learning (Mnih and Gregor, 2014): REINFORCE with an input-dependent baseline learned by a network, all applied to ) struggled wherever the SSTs struggled, REINFORCE also failed with spanning trees, and NVIL with spanning trees learned some structure, less and with higher variance than the SST.
Rao-Blackwellizing ST-GS over the noise behind the outcome keeps its mean and lowers its mean squared error. ST-GS has two sources of randomness, the outcome and the Gumbel noise given , and the second enters only through the point at which the softmax Jacobian is evaluated. Conditioning removes it. By the tower rule , so the bias is unchanged, and conditional Jensen applied to the squared error giveswhose expectation is Proposition 1, strict whenever , which holds for finite and . The mean squared error falls at every temperature, so training can move to lower temperatures, where the bias is smaller and plain ST-GS was too noisy. In a three-category example (my check: logits , , a quadratic loss), ST-GS and Gumbel-Rao with 100 conditional draws had the same mean, both away from the true gradient, and the trace of the covariance fell from 0.55 to 0.32.
The Gumbels behind a given outcome have a closed form, so the conditional average costs . Given , the one-hot vector of the winning category , write and let be independent standard exponentialexponentially distributed with mean 1, variables. Then, in distribution, with ranging over the other categories,The winning perturbed logit is Gumbel with location , independent of which index wins, and each other one is Gumbel with location truncated to lie below the winner (my check: these draws match rejection sampling from unconditional Gumbels within Monte Carlo error). Averaging the softmax Jacobian over such draws gives ( is ST-GS), and Jensen applied to the -sample average gives Proposition 2. The extra work is softmax Jacobians of size , done in parallel. Proposition 3 follows from the law of total variance: divides only the first term, which the batch size divides too, so the gain is largest at small batches and returns from larger diminish.
Gumbel-Rao trains better at low temperatures and small batches, by up to 2 nats at batch size 20. On a quadratic objective over the probability simplex in three dimensions, the variance falls at every point, most at low temperature and near the corners and edges. On ListOps with a tree-LSTM parser that its authors (Choi et al., 2017) trained with ST-GS, test accuracy for sequences up to length 10 rose at from 38.8% to 66.5% (; 66.4% with ) and at from 65.8% to 67.0%, so most of the gain is that low temperatures become usable. In a variational autoencoderan encoder draws latent variables given the input and a decoder reconstructs the input from them; both are trained on a lower bound on the log-likelihood on binarized MNIST with 16-category latent variables and batch size 20, the test bound on the negative log-likelihood improved from 98.8 to 96.8 natsunits of natural-log likelihood; the numbers are upper bounds on the negative log-likelihood, so lower is better, and with batch size 200 from 92.6 to 92.2 (an appendix table shows up to 2.9 nats at batch size 5); the best ST-GS models trained at an average temperature of 0.65 and the best Gumbel-Rao models at 0.35, and gains saturated near . REINFORCE with a running-mean baseline reached only 169 to 204 nats at batch size 20. The relaxed Gumbel-Softmax, which changes the forward pass, was best for binary variables (98.2 against 100.5 nats at batch size 20) and matched or trailed Gumbel-Rao with 16 categories (96.8 against 96.8 at batch size 20, 94.3 against 92.2 at 200).
Terms
- Score function (REINFORCE)
- : unbiased, needs only loss values, high variance without control variates
- Gumbel-Max
- Gumbel-Softmax
- ; unbiased for the relaxed objective, biased for the discrete one
- ST-GS
- discrete forward, gradient through backward
- SMT
- , a linear program with random utilities
- SST
- , strongly convex
- SST Propositions 1-2
- a.s. as ; continuous and a.e. differentiable in
- Exponential-family relaxation
- , the marginals of
- Finite differences
- symmetric Jacobian: ,
- Gumbel-Rao
- : same mean as ST-GS, lower mean squared error, no extra loss evaluations
- Conditional Gumbels
- winner ; others
- Proposition 3
Quiz
- Why does the SST paper treat the utility distribution as a modeling choice instead of always taking ?Only for one-hot does Gumbel-Max give the exponential family exactly; for trees or subsets the law of the argmax is hard to characterize. In the ListOps runs the choice of moved accuracy from 71.5% to 95.0%.
- As , what does a stochastic softmax trick approach?Proposition 1 gives almost surely, and is random through . Annealing marginal inference with fixed parameters is the limit that goes to a single mode.
- A model samples a discrete output that an external program scores, and the score has no gradient. Which estimator applies?SSTs need on , and straight-through estimators need at the vertices. The score-function estimator uses only , unbiased, with variance lowered by baselines.
- In the SST experiments, which choice changed results least?On L2X the Euclidean, categorical, binary and exponential-family regularizers gave similar results, while structure (correlated subsets, trees) and utility distribution moved precision and accuracy by tens of points.
Sources
- Max B. Paulus, Dami Choi, Daniel Tarlow, Andreas Krause, and Chris J. Maddison. Gradient Estimation with Stochastic Softmax Tricks. NeurIPS, 2020.
- Max B. Paulus, Chris J. Maddison, and Andreas Krause. Rao-Blackwellizing the Straight-Through Gumbel-Softmax Gradient Estimator. ICLR, 2021.
- Eric Jang, Shixiang Gu, and Ben Poole. Categorical Reparameterization with Gumbel-Softmax. ICLR, 2017.
- Chris J. Maddison, Andriy Mnih, and Yee Whye Teh. The Concrete Distribution: A Continuous Relaxation of Discrete Random Variables. ICLR, 2017.