A Watermark for Large Language Models
Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202)
Subscriber deck — free during early access
19 cards
1 Introduction
- What is a watermark for language model output?A hidden pattern in generated text that humans can’t perceive but an algorithm can detect, marking the text as machine-generated; Kirchenbauer et al. aim to detect it from short spans (as few as about 25 tokens) with statistically improbable false positives.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §1
- What properties do Kirchenbauer et al. want from a watermark?Detectable without the model’s parameters or API (so the detector can be public and cheap); applicable to a standard model without retraining; detectable from any contiguous portion of the text; not removable without changing a large fraction of tokens; and with a rigorous statistical confidence measure.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §1
1.2 A caveat: The difficulty of watermarking low-entropy sequences
- Why is low-entropy text hard to watermark?When the first tokens nearly determine the rest (e.g. a famous pangram or a standard for-loop), humans and models produce the same completion, so the source can’t be told apart; and forcing different tokens would make the text unnatural.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §1.2
2 A simple proof of concept
- Describe the “hard red list” watermark.At each step, hash the previous token to seed a random generator, use it to split the vocabulary into a green and a red list, and sample the next token only from the green list. A detector that knows the hash can rebuild each red list and count violations.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §2
- How is the watermark detected statistically?Under the null hypothesis that the text was written without knowing the red list rule, the green-token count \(|s|_G\) of \(T\) tokens has mean \(\gamma T\) and variance \(T\gamma(1-\gamma)\); compute \(z = (|s|_G - \gamma T)/\sqrt{T\gamma(1-\gamma)}\) and flag the text if \(z\) exceeds a threshold, e.g. \(z > 4\) (false-positive rate \(3 \times 10^{-5}\)).
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §2
- With the hard red list (\(\gamma = 1/2\)) and threshold \(z = 4\), how many tokens are needed for detection, and why?16: if every token is green, \(z = 2(T - T/2)/\sqrt{T} = \sqrt{T}\), which reaches 4 at \(T = 16\).
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §2
- Why is the watermark hard to remove by editing tokens?Each changed token can create at most two red-list violations (itself and the next token, whose list it seeds). Even a maximally adversarial edit of 200 of 1,000 tokens leaves 600 green tokens, \(z \approx 6.3\); removal needs changing roughly a quarter of the tokens, and an attacker who doesn’t know the lists does far worse.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §2
- What is the drawback of the hard red list rule?It forbids red tokens even when they are the only sensible continuation (e.g. “Obama” after “Barack”), degrading low-entropy text.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §2
3 A more sophisticated watermark
- How does the soft watermark change generation?Instead of forbidding red tokens, it adds a constant \(\delta\) to the logits of green-list tokens (a fraction \(\gamma\) of the vocabulary) before the softmax. Near-certain tokens stay likely even if red, while in high-entropy steps the bias strongly favours green tokens.
Green tokens get a logit bonus δ; the watermark is strong only where many tokens are plausible (invented logits) - Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §3
- What do the parameters \(\gamma\) and \(\delta\) control?\(\gamma\) is the green-list fraction of the vocabulary, \(\delta\) the logit bias (hardness). Smaller \(\gamma\) and larger \(\delta\) give a stronger watermark from fewer tokens but distort the text more (higher perplexity); \(\delta \to \infty\) recovers the hard rule.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §3
3.1 Detecting the soft watermark
- How does detection sensitivity of the soft watermark depend on the text?Detection uses the same z-test, but the green-token excess depends on entropy: high-entropy text is detected from few tokens, while low-entropy text (often memorized or near-copied human text) needs many tokens or isn’t detectable at all.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §3.1
4 Analysis of the soft watermark
- What is spike entropy, and why do Kirchenbauer et al. use it?A measure of how spread out a distribution is, roughly a softened count of entries with probability above \(1/z\); minimal when all mass is on one token. It bounds how many green tokens a watermarked model is expected to produce, and so how detectable its output is.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §4
4.2 Impact on quality of generated text
- When does the soft watermark leave perplexity unchanged?At both extremes: if the model’s distribution is uniform, a random green list still gives uniform sampling; if all mass is on one token, the bias doesn’t change the choice. Perplexity is affected only for tokens of moderate entropy.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §4.2
5 Private Watermarking
- How does a private watermark differ from a public one?The red lists depend on a secret key behind an API, so attackers don’t know which tokens to replace; but detection then requires the API, and access must be monitored so that an adversary can’t probe it with many slightly varied texts.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §5
6 Experiments
- How well did the soft watermark work with OPT-1.3B on C4 news prompts?With \(\gamma = 0.5\), \(\delta = 2\) and \(z = 4\) on about 200 generated tokens, 98.4% of watermarked texts were detected with multinomial sampling (99.6% with 4-way beam search), and essentially no human text was flagged.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §6
- How does beam search interact with the soft watermark?It “irons in” the watermark: searching among likely continuations finds ones dense in green tokens, giving much higher z-scores at little perplexity cost; with 8 beams and \(\delta = 2\), average \(z > 5\) was reached from about 35 tokens.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §6
- Why can the detector stay the same when the watermarking rule changes?The z-statistic depends only on \(\gamma\) and the hash function, not on \(\delta\) or how green tokens are favoured, so \(\delta\) can vary by context (e.g. prose vs code) or the generator can change without updating the detector.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §6
7.1 Degradation Under Attack: Span Replacement
- How effective was the T5 span-replacement attack?Replacing random spans with T5-Large suggestions, without knowing the green lists, barely helped at a 10% budget (AUC dropped by 0.01); at 30% it degraded the watermark substantially, but tripled perplexity and needed many model calls.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §7.1
8 Related Work
- Why do Kirchenbauer et al. prefer watermarking to post-hoc detection of machine text?Post-hoc detectors lose ground as models improve (GPT-2 detectors struggle with GPT-3), are vulnerable to adversarial attacks, and risk falsely flagging human text, especially from non-native speakers or writers using assistance tools.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models (Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202), §8
Source
- John Kirchenbauer, Jonas Geiping, Yuxin Wen, Jonathan Katz, Ian Miers and Tom Goldstein. 2023. A Watermark for Large Language Models. In Proceedings of the 40th International Conference on Machine Learning (ICML 2023), PMLR 202, pp. 17061–17084. https://proceedings.mlr.press/v202/kirchenbauer23a.html