Ground Truth.
AI, checked against the source.

Learn · Intermediate

The Gumbel-max trick: turning random noise into a categorical choice

The Gumbel-max trick samples one item from a categorical distribution by adding random Gumbel noise to each item’s log probability and selecting the largest resulting score. It turns a probability-based choice into an argmax calculation while preserving the original chance of selecting every item. This simple identity appears in differentiable models, discrete sampling methods, and Mistral’s newly reported Keyrings text watermark.

The choice we want to make

Suppose a language model assigns probabilities to its next tokens: “blue” has probability 0.5, “green” has 0.3, and “red” has 0.2. Ordinary categorical sampling returns one token, with each token selected at its assigned rate over many repetitions. A direct implementation draws a random number and walks through cumulative probability intervals. The Gumbel-max trick gives another way to make the same kind of draw.

For each option, take the logarithm of its probability and add an independent random value drawn from a Gumbel distribution. Pick the option with the largest sum. The noise sometimes boosts a low-probability choice and sometimes leaves a high-probability choice on top. Across repeated samples, the probability that option i wins is exactly its original probability. The noise changes the path to the choice, not the distribution of outcomes.

Why use logarithms and maxima?

Log probabilities turn products into sums, which makes them convenient to compare as scores. The Gumbel distribution has a useful relationship to the maximum of noisy values: adding independent Gumbel noise to log weights creates a winner with probability proportional to the original weight. This is an exact result, not a heuristic approximation. If the weights are probabilities that sum to one, the probability of winning is that same probability.

An analogy is a contest where every candidate begins with a head start based on its probability, then each receives a random boost. A favorite tends to win more often, but an underdog can still win. The distribution of boosts is specially shaped so that the long-run win rate matches the intended odds exactly.

A small numerical example

For the three-token example, the starting scores are log(0.5), log(0.3), and log(0.2). Each receives its own independent Gumbel draw. In one sample, “green” might get a large boost and win; in another, “blue” may remain first. The algorithm needs only one draw per candidate and an argmax. It does not need to modify the probabilities to encourage a particular token.

Hard choices and differentiable approximations

An argmax is discrete: a tiny change in a score can switch the winner, and ordinary derivatives do not describe that jump usefully. The Gumbel-Softmax method replaces the hard winner with a soft distribution controlled by a temperature. At high temperature, probability mass spreads across candidates; at low temperature, it concentrates around the winner. The result can be used in gradient-based training as a differentiable approximation. Jang, Gu, and Poole’s Gumbel-Softmax paper and Maddison, Mnih, and Teh’s related Concrete distribution work introduced this approach for learning with discrete latent variables.

The distinction matters: Gumbel-max is an exact discrete sampler, while Gumbel-Softmax is a smooth approximation used to pass gradients through a choice. They share the noise construction but solve different problems.

Sampling several distinct items

The same idea can produce a ranked list. Add Gumbel noise to each log weight, then take the top k scores. This Gumbel-Top-k method samples items without replacement according to a weighted distribution. Kool, van Hoof, and Welling describe this construction in The Gumbel-Top-k Trick. It is useful when a system needs several alternatives rather than a single sampled result.

Why it matters for language models and watermarking

Language models repeatedly make categorical choices. Sampling strategies such as temperature and top-p alter or filter the distribution before drawing a token; see how AI picks its next word. Gumbel-max provides an equivalent way to express a draw from a chosen categorical distribution. That makes it useful for algorithms that need to reason about the randomness itself.

Mistral says its Keyrings watermark derives sampling noise from a secret key and preceding-token context, aiming to preserve each next token’s original marginal distribution while leaving a sequence-level detectable pattern. The Gumbel-max identity explains why sampling-time randomization can, in principle, preserve token probabilities. It does not by itself prove that a watermark is undetectable, robust to rewriting, or correctly implemented. Those are additional properties requiring separate analysis and tests. Read the Keyrings and TextOrca report for the launch’s measured claims and limitations.

The Gumbel-max trick is a small mathematical tool with a useful guarantee: it makes a random categorical choice through noisy scores without changing the intended odds. Knowing the difference between exact sampling and its differentiable approximation helps clarify what a model’s sampling code is doing—and what a watermarking system must prove beyond the sampling identity.

Key papers
Categorical Reparameterization with Gumbel-Softmax
The Gumbel-Top-k Trick for Discrete Sampling without Replacement

Key questions

What problem does the Gumbel-max trick solve?

It turns a categorical probability distribution into an argmax operation by adding carefully distributed random noise to each option’s log probability.

Does Gumbel-max change the probabilities of the choices?

No. With independent Gumbel noise, the chance that an option wins is exactly its original categorical probability.

How is Gumbel-max different from Gumbel-Softmax?

Gumbel-max produces a discrete choice, while Gumbel-Softmax replaces the hard maximum with a differentiable soft approximation for gradient-based training.
Cite this

APA

Ground Truth. (2026, December 3). The Gumbel-max trick: turning random noise into a categorical choice. Ground Truth. https://groundtruth.day/learn/gumbel-max-trick.html

BibTeX

@misc{groundtruth:gumbel-max-trick,
  title  = {The Gumbel-max trick: turning random noise into a categorical choice},
  author = {{Ground Truth}},
  year   = {2026},
  month  = {dec},
  url    = {https://groundtruth.day/learn/gumbel-max-trick.html}
}

Topics: sampling · probability · machine-learning · watermarking