Exponential Minimum Sampling
8 min read
A language model chooses its next token using both its predicted probabilities and some randomness. Usually that randomness is discarded. If the model provider keeps it, could it help the provider recognize the generated text later?
A watermark can use a secret key to supply the sampling randomness. The chosen token is then correlated with numbers that a verifier holding the key can reconstruct. The verifier can test that relationship even when the text alone gives no such evidence. For the exponential sampler, averaging over the random key gives exactly the model’s token probabilities. A fixed key supplies the additional information that detection uses.
Scott Aaronson proposed using shared sampling randomness for a watermark [Aaronson, ’22]. Kuditipudi, Thickstun, Hashimoto & Liang developed the EXP scheme and its detector [KTHL, TMLR ’24].
Randomness a Verifier Can Reproduce
A language model at step \(t\) produces a next-token distribution \(p_t\) over the vocabulary, conditioned on everything generated so far. Ordinary sampling draws fresh randomness at each step and throws it away. Instead, we need draws \(E_{t,1}, \dots, E_{t,n} \sim \mathrm{Exp}(1)\) for every step \(t\) that we can produce twice: once at generation time and once at detection time. Any pseudorandom generator seeded with a secret key does this; the generator expands the key into the \(E_{t,i}\) on demand, and whoever holds the key can regenerate them. Scott Aaronson described this scheme in a 2022 lecture, and Kuditipudi, Thickstun, Hashimoto & Liang [KTHL, TMLR ’24] analyzed the version where the key is a fixed sequence indexed by position.
Generation at step \(t\) is deterministic given the key:
\[ x_t = \arg\min_{i} \; \frac{E_{t,i}}{p_t(i)}. \]
Marginalized over the key, the \(E_{t,i}\) are independent \(\mathrm{Exp}(1)\) draws, so by the claim \(x_t\) is an exact sample from \(p_t\), and the generated text is equal in distribution to ordinary sampling. This is the distortion-free property (Theorem 2 in [KTHL, TMLR ’24]): watermarked and unwatermarked text have the same distribution, so the quality cost is exactly zero. Exactness holds as long as no draw \(E_{t,i}\) is reused, so the guarantee comes with a generation budget, the length of the key; a random starting offset into the key keeps repeated queries from replaying the same text.
Detection
A verifier holds the key and a text \(y_1, \dots, y_m\), with no model and no prompt, and asks whether the text was generated with the key. It cannot rerun generation, since that needs \(p_t\). What it can do is regenerate the draws and read off the one each token points to, \(E_{t, y_t}\). For text produced with the key, those draws are small.
Claim: if \(x = \arg\min_j E_j/p_j\) for independent \(E_1, \dots, E_n \sim \mathrm{Exp}(1)\), then
\[ \mathbb{E}\big[E_x \,\big|\, x\big] = p_x, \]
while an index \(i\) chosen without reference to the draws has \(\mathbb{E}[E_i] = 1\).
Proof
The argmin achieves the minimum, so \(E_x / p_x = \min_j E_j/p_j\), and multiplying through by \(p_x\),
\[ E_x = p_x \cdot \min_j \frac{E_j}{p_j}. \]
The minimum is \(\mathrm{Exp}(1)\) and independent of \(x\), so its mean given \(x\) is \(1\):
\[ \mathbb{E}\big[E_x \,\big|\, x\big] = p_x \cdot \mathbb{E}\Big[\min_j \tfrac{E_j}{p_j}\Big] = p_x \cdot 1 = p_x. \]
An index chosen without reference to the draws leaves \(E_i\) a plain \(\mathrm{Exp}(1)\) variable with mean \(1\).
Applied at every step, the mean of \(E_{t, y_t}\) over a watermarked text is about \(\frac{1}{m}\sum_t p_t(y_t)\), which is at most \(1\), while over text written without the key it is about \(1\). The detector computes the average draw and flags the text when it falls far enough below \(1\). The per-token evidence is the gap \(1 - p_t(y_t)\), so the signal comes from the model’s entropy. Where the model is uncertain the gap is wide; where it is confident, \(p_t(y_t)\) is near \(1\) and there is almost no signal. No distortion-free scheme can do better, because a deterministic model emits the same fixed string with or without a key. On Alpaca-7B, whose instruction responses are low-entropy, only about a quarter of responses of median length around 100 tokens are detectable at \(p\)-value \(0.01\).
In the plot below, a synthetic model draws each next-token distribution \(p_t\) as a softmax of Gaussian logits over a 50-token vocabulary, a choice that spreads the per-step entropy instead of fixing one confidence level. The average draw separates 35-token watermarked texts from unwatermarked ones at the one-percent threshold.
Real text does not arrive aligned with the key: the user crops the prompt, edits words, or splices the generation into their own writing, and then the verifier no longer knows which step \(t\) each token came from. [KTHL, TMLR ’24] score the text against every shift of the key and keep the best alignment, taking the \(p\)-value from a permutation test over fresh random keys; on OPT-1.3B and LLaMA-7B this still detects 35-token texts after 40 to 50 percent of the tokens are corrupted.
Aaronson’s lecture instead derives the step-\(t\) draws by hashing the previous few tokens together with the secret key. That makes detection alignment-free, since the verifier recomputes the draws straight from the text, but hashing reuses randomness: the same context always produces the same draws, which biases the text toward particular phrases ([KTHL, TMLR ’24] show sampled lists repeating themselves on prompts like “give me a list of 20 movies”), and editing any single token in a hash window destroys the signal for the token that follows it.
Where the Sample Appears
Aaronson’s variant was prototyped inside OpenAI by the engineer Hendrik Kirchner, and [KTHL, TMLR ’24] released code and an in-browser detector for the fixed-key scheme.
The argmin is the Gumbel-max trick after a change of variables: \(G_i = -\ln E_i\) has CDF \(\Pr(G_i \le g) = \Pr(E_i \ge e^{-g}) = e^{-e^{-g}}\), a standard Gumbel, and \(\arg\min_i E_i/p_i = \arg\max_i (\ln p_i + G_i)\). In that form it powers reparameterized discrete sampling, where a categorical draw becomes an argmax over noised log-probabilities that can be softened to let gradients through, and it resurfaces as a differential privacy mechanism. Maddison, Tarlow & Minka [MTM, NeurIPS ’14] push it to continuous spaces as A* sampling, which turns drawing from a continuous distribution into an optimization problem.