Watermarking › Watermarking Schemes
Language AI HandbookAll chapters Watermarking › Watermarking SchemesOne section · Sections in this chapter3 / 10 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The field has converged on two main families of watermarking schemes: token-level schemes that operate on the sampling distribution at each decoding step, and distortion-free schemes that modify how sampling randomness is used without changing the marginal output distribution. Token-level schemes have dominated research because they offer strong statistical guarantees and integrate cleanly into the decoding pipeline. Both families share the requirement that the watermark key must be kept private for the scheme to remain secure.
Before diving into the mechanics, it helps to think about what a watermarking scheme must accomplish simultaneously:
- Detectability: The signal must be strong enough that a detector can reliably confirm its presence in a reasonable amount of text.
- Imperceptibility: The text must still read like natural language. A watermark that causes the model to produce awkward or ungrammatical sentences would be both obvious and counterproductive.
- Security: An attacker who does not know the key should not be able to remove the watermark without degrading text quality significantly, nor should they be able to forge a watermark to falsely attribute text.
These three requirements exist in tension, and much of the research in this area examines the tradeoffs between them.
Token-Level Watermarking
The key insight in token-level watermarking is that language model decoding involves choosing tokens from a probability distribution at each step. If you can systematically bias those choices, even slightly, you introduce a pattern that accumulates over many tokens and becomes statistically detectable.
The most influential scheme was introduced by Kirchenbauer et al. (2023), often called the KGW watermark. It works by partitioning the vocabulary into two sets at each token position: a "green" set and a "red" set. The partition depends on the previous token, using a hash function keyed to a secret key. During generation, the logits for green-list tokens are increased by a fixed additive amount , making the model more likely to select them. Tokens from the red list are not penalized but compete against boosted green tokens.
To understand why this works, consider what happens to the softmax distribution when you add to a subset of logits. If token has logit , then adding to green tokens changes the selection probability. For green token versus red token :
Even when the red token has a higher base logit (), if is large enough, the green token wins. This is the boost mechanism: you are not forcing specific tokens but tilting the odds.
More precisely, before sampling token , the scheme:
- Hashes the previous token (or a window of previous tokens) together with the secret key to obtain a pseudo-random partition
- Marks a fraction of the vocabulary as green
- Adds to the logit of every green-list token
- Samples normally from the modified distribution
The detection procedure counts how many green tokens appear in the candidate text, computes a z-score under the null hypothesis that the text was generated without watermarking, and rejects the null if the score exceeds a threshold.
The partition changes at every step because it depends on the current context. This means you cannot predict future green lists from past ones without the key, which prevents attackers from simply avoiding green tokens. If you change token to avoid a red-token situation at position , you simultaneously change the partition at position . The dependency chain makes targeted removal difficult.
At each decoding step, the KGW scheme uses a hash of the previous token and a secret key to split the vocabulary into a green list (fraction , typically 0.5) and a red list (fraction ). During generation, green-list logits are boosted by . During detection, a z-test counts how many tokens in the candidate text are green under the same partition, using the same key to reproduce the identical partition for each position.
The KGW Detection Statistic
The statistical heart of the KGW scheme is a hypothesis test. Let be the number of tokens in the candidate text, and let denote the count of green tokens, where "green" is determined by the same hash function and key used during generation.
Under the null hypothesis (text was not watermarked), each token is independently green with probability . Why? Because without the logit boost, the token choice is determined solely by the model's learned distribution, which has no reason to match any particular hash-derived split. The expected number of green tokens is , and by the central limit theorem, the count is approximately normally distributed with mean and variance .
The z-score is computed as:
where:
- : the number of tokens in the text that fall in the green list under the key-derived partition
- : total number of tokens in the text
- : the fraction of the vocabulary assigned to the green list (typically 0.5)
- : the variance of a binomial distribution with trials and success probability
This is a standard z-test for a proportion. The numerator measures how far the observed green count is from what you would expect by chance. The denominator normalizes by the standard deviation, putting the statistic on a scale where values above roughly 2 are unlikely under the null.
If the text was watermarked, green tokens appear at a rate higher than because their logits were boosted by during generation. A large positive score indicates the presence of the watermark. The detector rejects and concludes the text is watermarked when exceeds a threshold , where is the desired false positive rate.
For a one-sided test at significance level , the threshold is . For , the threshold rises to . These correspond to the upper tail of the standard normal distribution: a z-score of 2.33 means the observed green count is in the top 1% of what you would expect from unwatermarked text.
The intuition for why the signal accumulates is essentially the same as why large samples give more precise estimates. Each token is a single Bernoulli trial: was it green? With only 20 tokens, random fluctuations dominate. With 200 tokens, the law of large numbers ensures that the observed green rate converges to its true mean, and the true mean under the watermarked distribution is higher than by an amount that depends on .
Soft vs. Hard Watermarking
The KGW scheme has two variants that differ in how they handle high-entropy versus low-entropy positions.
Hard watermarking strictly forbids red tokens by setting their logits to . This maximizes detection power because every generated token is guaranteed to be green. The z-score grows at the maximum rate, and detection is reliable even with fewer tokens. The problem is quality degradation. When the model would naturally continue with a word like "not" or "however" but these happen to be on the red list for the current context, the model is forced to produce something awkward. At low-entropy positions, where one or two tokens strongly dominate the distribution, the forced exclusion of red tokens can produce grammatically incorrect or semantically inconsistent text.
Soft watermarking adds to green-list logits without zeroing out red tokens. Quality loss is much smaller because the model can still choose red tokens if they dominate the distribution strongly enough. Consider a position where the model assigns logit 8.0 to "not" (a red token) and logit 4.0 to its best green alternative. With , the best green token now has logit 6.0, but "not" still wins at 8.0. The sentence continues naturally. Detection power is lower than hard watermarking because not every generated token is green, but it degrades gracefully and remains reliable at moderate text lengths.
The tradeoff between quality and detection power is fundamental and cannot be fully eliminated. Higher makes the watermark easier to detect but also more perceptible as unnatural text because the model is more strongly biased away from its most natural continuations. Kirchenbauer et al. showed that soft watermarking with and achieves a useful balance: text quality remains close to the unwatermarked baseline as measured by perplexity and human evaluation, while detection succeeds reliably with tokens at meaningful significance levels.
The choice between hard and soft watermarking is not merely technical. Hard watermarking might be appropriate for internal auditing where text quality is not consumer-facing. Soft watermarking is necessary for any deployment where the watermarked model interacts directly with users who would notice quality degradation.
Unigram and Context-Dependent Watermarks
The context-dependent partitioning of the KGW scheme has both strengths and weaknesses. The strength is that the partition is unpredictable without the key. An attacker observing the generated text cannot infer which tokens are green for future positions because the partition changes with each new token. The weakness is that the hash of consecutive tokens creates correlations between adjacent decisions, complicating the statistical analysis and making it harder to reason about detection power theoretically.
A simpler alternative is the unigram watermark, which uses a single fixed partition of the vocabulary that does not change across positions. The same green list applies at every token position throughout a document. Detection is still a z-test on the green token count, but the partition is fixed rather than context-dependent. This simplification has two consequences: the statistical analysis is cleaner because token choices are more nearly independent, and the scheme is more vulnerable to attack because an attacker who discovers which words are on the green list can avoid them entirely. Since the partition does not change, discovering even part of the green list gives the attacker useful information for targeted removal.
A more sophisticated approach, proposed by Christ et al. (2023), generates a pseudo-random binary signal for each position using a pseudo-random function keyed to the secret key and the current position index. The bits determine which tokens to prefer without partitioning the full vocabulary. This scheme offers provably optimal detection under certain assumptions because it achieves the maximum possible information content per token while remaining undetectable to a party without the key. The theoretical guarantees come at the cost of more complex detection algorithms, but the framework has influenced subsequent work.
Distortion-Free Watermarking
A significant limitation of logit-bias schemes is that they always distort the output distribution. The generated text is not drawn from the true model distribution. This matters for several reasons. First, calibration: watermarked models are slightly less faithful to the input prompt because they systematically prefer certain tokens even when those tokens are not the most natural continuation. Second, detectability: the distortion is in principle measurable by anyone who knows enough about the model's natural distribution, even without knowing the watermark key. Third, downstream use: if a watermarked model's outputs are used as training data for another model, the biased distribution introduces systematic errors.
Kuditipudi et al. (2023) introduced a family of distortion-free watermarks that preserve the original sampling distribution in expectation. The key idea is to use a pseudo-random coupling between the model's probability distribution and a secret signal, rather than modifying the logits. Because the signal is embedded through the randomness of the sampling process rather than through biased logits, the marginal distribution over outputs is unchanged.
To understand the mechanism, recall how token sampling normally works. The model produces a probability distribution over the vocabulary. You sample a token by drawing a uniform random variable and applying the inverse CDF of : you find the token such that . Different values of produce different tokens according to their probabilities.
The distortion-free watermark replaces the uniformly random with a value derived from the secret key: where is a pseudo-random function. The output distribution is still because a pseudo-random is statistically indistinguishable from a truly uniform one if is a good pseudo-random function. But now the specific token chosen at each position is determined by the key in a way that a detector can verify.
Detection works by testing whether the observed tokens are consistent with having been chosen using the key-derived randomness. Concretely, for each token in the candidate text, the detector computes the rank of under the probability distribution given the preceding context. Under the watermark, each token should have a specific expected rank determined by . Under the null hypothesis, ranks are uniformly distributed. A rank-based test statistic exploits this asymmetry to identify watermarked text.
The tradeoff is detection efficiency. Because distortion-free schemes do not boost any signals above the natural distribution, each token provides less evidence about the watermark's presence than it would under a logit-bias scheme. Empirically, distortion-free schemes typically require more tokens to achieve the same detection confidence. The theoretical guarantee of zero distribution shift is useful, but practical performance at short text lengths is lower than logit-bias approaches. For long documents, the difference diminishes.