Definition
Watermarking generated content means embedding a signal into a model's output, at generation time, that people cannot see but a detector holding a secret key can test for statistically. For text, the reference scheme is "A Watermark for Large Language Models" (Kirchenbauer, Geiping, Wen, Katz, Miers and Goldstein, ICML 2023). Before each token is sampled it pushes the model towards a pseudorandom "green" part of the vocabulary. Google DeepMind's SynthID-Text (Dathathri et al., Nature, 2024) is a deployed variant.
The problem is provenance: was this essay, review or news article produced by a particular model? Post-hoc detectors that classify text as "AI-like" are unreliable and biased against some human writers. A watermark makes the question a hypothesis test with a known false-positive rate. The test needs the provider's cooperation, because only the key holder can detect, and it only covers models that embed the mark.
A watermark is one of three provenance tools. Metadata (signed C2PA manifests) is exact but stripped by a screenshot or re-encode. Detection classifies content without any cooperation from the generator (see Deepfake detection). Watermarks live in the content itself, so they survive copying, but they can be weakened by editing. This article covers the watermark.
The green-list scheme
At step , hash the previous token with a secret key to seed a random number generator. Use it to split the vocabulary into a green list of size and a red list of the rest. Add to every green logit, then sample as usual (any temperature or top-p setting):
- the model's logit for token at step
- green fraction of the vocabulary; 0.25 is a common choice
- logit bias added to green tokens (watermark strength); 2 is a common choice
- secret key; without it the lists look random
A strongly preferred token barely changes: if "Paris" has probability 0.99 it stays the likely choice even when red. The bias acts where the model has real choices, so quality loss is small when entropy is high. This is the difference from the paper's "hard" variant, which bans red tokens and breaks forced phrases.
Detection is a z-test
The detector tokenises the text, recomputes each green list from the key and the preceding token, and counts green tokens . Human text knows nothing of the key, so each token is green with probability and the count is binomial:
- number of scored tokens
- number of green tokens in the text
- detection threshold; the paper uses 4 (one-sided)
The detector needs no model weights and no API call, only the key, the tokenizer and the hash rule. The strength of the evidence grows like . In the best case, a flat next-token distribution, the green probability per token is . With , that is , so grows by per and passes 4 after about 14 tokens. Real text has many near-deterministic tokens, so in practice it takes more.
- average green probability per token; close to when the model is nearly deterministic
| Text | Green tokens | z | One-sided p | Flag at z ≥ 4? |
|---|---|---|---|---|
| Watermarked (viz default) | 105 | (105 − 50)/6.12 = 8.98 | 1.3 × 10⁻¹⁹ | yes |
| Watermarked, lightly edited | 90 | 6.53 | 3.2 × 10⁻¹¹ | yes |
| Heavily paraphrased | 62 | 1.96 | 0.025 | no |
| Human-written | 52 | 0.33 | 0.37 | no |
A one-in-31,600 error rate sounds negligible, but scale matters. Scanning a million human-written documents at still flags about 32 of them. Raise the threshold, require a minimum length, and never treat a flag as proof on its own, for example in academic-misconduct cases.
Strength, entropy and edits
Three lessons show up in the figure. Strength costs quality: a larger raises and perplexity together. Low-entropy text resists the watermark: when the model is sure of the next token, the bias cannot move it, so code, lists and memorised passages carry little signal. And each edited token damages two tests, its own and the next token's (whose green list it seeds), so the green excess decays roughly like . A real paraphraser keeps perplexity low while doing the same damage.
Schemes and results (check the papers for exact settings)
- Kirchenbauer et al. 2023
- Soft green-list watermark with a one-proportion z-test; experiments on OPT models with about 200-token continuations. Describes the emoji attack: ask the model to put an emoji after every word, then delete the emojis, which changes every token's predecessor.
- Distortion-free sampling
- Aaronson (2022, OpenAI talk): choose the token maximising for keyed pseudorandom . Each step is still an exact sample from the model. Kuditipudi et al. (2023) and Christ, Gunn and Zamir (2023) give robust and cryptographically undetectable variants.
- SynthID-Text
- Dathathri et al., Nature 2024: tournament sampling with keyed scoring functions, deployed in Google's Gemini; the authors report no measurable drop in user-rated quality in a large live comparison.
- Images and audio
- HiDDeN (Zhu et al., ECCV 2018) learns an encoder-decoder pair that hides bits in pixels. Tree-Ring (Wen et al., NeurIPS 2023) writes a key pattern into the Fourier transform of a diffusion model's initial noise and detects it by DDIM inversion. Stable Signature (Fernandez et al., ICCV 2023) fine-tunes the latent decoder so every image carries a fixed message. AudioSeal (San Roman et al., 2024) localises a watermark within audio.
- Regulation
- The EU AI Act (2024, Article 50) requires providers of systems that generate synthetic audio, image, video or text to mark outputs in a machine-readable, detectable way. This is a summary, not legal advice.
1import hashlib, math, random23def green_list(prev_id, vocab_size, gamma, key=b"secret-key"):4 seed = int.from_bytes(hashlib.sha256(key + prev_id.to_bytes(4, "big")).digest()[:8], "big")5 ids = list(range(vocab_size))6 random.Random(seed).shuffle(ids)7 return set(ids[: int(gamma * vocab_size)])89def detect(token_ids, vocab_size, gamma=0.25, z_threshold=4.0):10 T = len(token_ids) - 1 # the first token has no predecessor11 greens = sum(tok in green_list(prev, vocab_size, gamma)12 for prev, tok in zip(token_ids, token_ids[1:]))13 z = (greens - gamma * T) / math.sqrt(T * gamma * (1 - gamma))14 p = 0.5 * math.erfc(z / math.sqrt(2)) # one-sided p-value15 return {"T": T, "green": greens, "z": round(z, 2), "p": p, "flag": z >= z_threshold}1617# toy check: a "generator" that picks a green token 70% of the time vs uniform text18V, rng = 1000, random.Random(0)19wm, plain = [1], [1]20for _ in range(200):21 g = sorted(green_list(wm[-1], V, 0.25))22 wm.append(rng.choice(g) if rng.random() < 0.7 else rng.randrange(V))23 plain.append(rng.randrange(V))24print(detect(wm, V)) # T=200, green=156, z=17.31, p≈2e-67, flag=True25print(detect(plain, V)) # T=200, green=50, z=0.0, p=0.5, flag=FalseUse when
- +Detection is a hypothesis test with a stated false-positive rate, not a black-box score.
- +Needs only the key and tokenizer; no model weights or API calls at detection time.
- +Cheap at generation: one hash and one vector addition per token, compatible with any sampler.
Avoid when
- −Only works for cooperating providers; open-weight models can be run with the watermark removed.
- −Weak on short or low-entropy text (code, facts, formulaic replies).
- −Paraphrasing, translation and the emoji attack erode the signal; stronger δ costs fluency.
Check yourself
With γ = 0.25, a 400-token human-written text has 115 green tokens. What does the detector conclude at z* = 4?
Check yourself
Why does a single substituted token typically remove two green tests, not one?
Remember
- ✓Embed: hash(key, previous token) splits the vocabulary; add to the green logits, then sample normally.
- ✓Detect: count green tokens, ; means a false-positive rate of per text.
- ✓Evidence grows like and with entropy; short or low-entropy text carries little signal.
- ✓Stronger δ means faster detection and higher perplexity; distortion-free schemes (Aaronson's, SynthID-Text's non-distortionary mode) avoid shifting the distribution.
- ✓Edits, paraphrases and the emoji attack weaken it; absence of a mark proves nothing.
- ✓Images and audio use learned or noise-space watermarks (HiDDeN, Tree-Ring, Stable Signature, AudioSeal); metadata (C2PA) complements but does not replace them.