Gumbel trick teaches you to Sample From a Distribution by Adding Noise and Pointing at the Biggest…
You want your model to make a random choice — pick a word, draw a sample, roll a weighted die.
Gumbel trick teaches you to Sample From a Distribution by Adding Noise and Pointing at the Biggest Number.
You want your model to make a random choice — pick a word, draw a sample, roll a weighted die.
But the natural way to do that, picking the largest of a set of scores, is a hard corner that gradients cannot pass through.
There is a trick that turns the random choice into a clean recipe: add a very particular kind of noise, then just point at the winner. It should not work. It works exactly.
The setup comes up constantly.
A model produces a set of scores — one per option — and you want to sample an option, with bigger scores more likely. The honest way is to run the scores through a softmax to get probabilities, then draw from those probabilities.
Fine for sampling. But it hides a problem when you want to learn through the choice: the act of picking the winner is an argmax, a hard corner, and gradients refuse to flow through corners.
Backpropagation hits the sampling step and stops dead.
Here is the trick that dissolves it, and it feels like sleight of hand.
Take your scores. To each one, add an independent dose of noise of a specific flavor called Gumbel noise.
Then do not bother with probabilities at all — just take the largest of the noisy scores. Whichever option won, that is your sample.
The claim: the option that wins this noisy contest is distributed exactly according to the softmax of the original scores. Not approximately. Exactly.
Adding Gumbel noise and taking the maximum reproduces the softmax distribution perfectly, with none of the probabilities ever computed.
Why does such a specific noise pull off something so clean? Because the Gumbel distribution is the natural mathematics of maxima — it is the shape that describes how the largest of many random draws behaves.
Gumbel noise is precisely engineered so that the competition between noisy scores resolves with the same odds as the softmax.
The softmax was secretly a question about who wins a noisy race, and Gumbel noise is the noise that makes the race fair in exactly the right way.
This is the Gumbel-max trick, and on its own it is already a small marvel: sampling from a weighted distribution with no division, no normalizing, just noise and a maximum.
But the real payoff is the corner-dissolving version. Taking the maximum is still a hard corner — still blocks gradients. So you replace the hard “take the maximum” with a soft, temperature-controlled softmax over the noisy scores.
At low temperature it behaves almost like picking the single winner; but because it is now a smooth softmax rather than a hard pick, gradients flow straight through it.
Jang and colleagues introduced this in 2016 as the Gumbel-Softmax: a way to sample a discrete choice while keeping the whole operation differentiable, so the network can learn through its own random decisions.
That unlocked things that were genuinely stuck. Models that make discrete choices in their hidden machinery — routing, selecting, sampling structure — could suddenly be trained end to end, because the discrete sample was no longer a wall the gradient crashed into.
A corner became a slope, and learning poured through.
What delights me about this one is the sheer audacity of the move. The obstacle was a hard maximum.
The solution was not to remove the randomness or approximate the corner crudely — it was to add more randomness, of exactly the right kind, so that the corner became something gradients could climb.
You fix a problem caused by sharpness by injecting precisely-shaped noise. It is the opposite of what instinct suggests, and it is exactly right.
So here is the question to leave you with. We usually treat noise as the enemy of clean computation, the thing to average away.
But here, the right noise is the thing that makes a hard, impassable choice smooth and learnable.
How often is the randomness not the problem, but the solution waiting to be added?
Sources: the Gumbel-max trick; Jang, Gu, Poole — “Categorical Reparameterization with Gumbel-Softmax” (2016), arXiv:1611.01144.
메타데이터
- post_id
- 20d2b185b1d7
- slug
- gumbel-trick-teaches-you-to-sample-from-a-distribution-by-adding-noise-and-pointing-at-the-biggest-20d2b185b1d7
- url
- https://levelup.gitconnected.com/gumbel-trick-teaches-you-to-sample-from-a-distribution-by-adding-noise-and-pointing-at-the-biggest-20d2b185b1d7
- canonical_url
- https://levelup.gitconnected.com/gumbel-trick-teaches-you-to-sample-from-a-distribution-by-adding-noise-and-pointing-at-the-biggest-20d2b185b1d7
- author_url
- https://medium.com/@swarnenduiitb2020i
- status
- ok
- fetched_at
- 2026-07-14 06:46:45