
How Much Is an AI Watermark Worth? Part 2: A Soft Watermark
In Part 1 I built a green list and a detector. A secret key and the previous token mark about 25% of the vocabulary as green, and the detector counts how many tokens in a text are green. My simulated model there only ever picked green tokens, which made the watermark easy to find but is not something a real model can do.
Why hard is not enough
After “The capital of France is”, the model should write “ Paris”. If “ Paris” happens to be red after “ is”, a model that refuses red tokens has to write something else, and that something else is wrong.
Kirchenbauer et al. (2023) describe both versions. The hard one forbids red tokens, while the soft one gives green tokens a bonus instead. If several words fit equally well, a green one usually wins, but if one word is far better than all others, it still wins, even if it is red.
The bonus
At every step, a model gives each token a score, usually called a logit. Before it draws a token, it turns the scores into probabilities with softmax:
def softmax(scores: np.ndarray) -> np.ndarray:
highest = scores.max()
shifted = scores - highest
exp_values = np.exp(shifted)
total = exp_values.sum()
probs = exp_values / total
return probs
Every score goes through exp, which turns it into a positive weight, and the weights are
divided by their sum so that they add up to 1. Subtracting the highest score first does
not change the result, because only the differences between scores matter. It only keeps
exp from overflowing on large scores.
The watermark steps in before softmax and adds delta to the score of every green token:
def apply_watermark(logits: np.ndarray, key: str,
prev_token: int, gamma: float = 0.25,
delta: float = 2.0) -> np.ndarray:
mask = green_mask(key, prev_token, len(logits), gamma)
new_logits = logits.copy()
new_logits[mask] = logits[mask] + delta
return new_logits
green_mask is an array of True and False, one entry per token, True where the token is
green. logits[mask] picks out only the green scores, and the function works on a copy,
so the scores the model passed in stay unchanged.
Because softmax runs every score through exp, adding delta to a score multiplies that
token’s weight by e^delta:
e^(score + delta) = e^score × e^delta
delta = 1 → × 2.7
delta = 2 → × 7.4
delta = 4 → × 54.6
At delta = 2, a green token is 7.4 times as likely as a red token with the same score.
If the model has many tokens with about the same score, the share of green tokens follows
from that directly. Take four tokens with the same score, one green and three red. Without
a bonus, each has weight 1, so green has a chance of 1 in 4. With delta = 2, the green
weight becomes 7.4, and green now has a chance of 7.4 / 10.4 = 71%. With about a quarter
of the tokens green, the same works for any vocabulary:
green = 0.25 × e^delta / (0.25 × e^delta + 0.75)
delta = 1 → 48%
delta = 2 → 71%
delta = 4 → 95%
This only works when the model has many options. Kirchenbauer et al. cover the general case in their Theorem 4.2. There, the formula is multiplied by a factor between 0 and 1 that measures how spread out the model’s probabilities are, which they call spike entropy. When many tokens have small probabilities, the factor is close to 1 and only the formula is left, while it drops when a few tokens take most of the probability. Formula times factor is a lower bound: on average, at least that share of tokens should be green.
To see why the factor drops, take the extreme case: the model gives one token almost 100%. After “The capital of France is”, it might give “ Paris” 99.9%. If “ Paris” is green, it is picked and counts as green, with or without the bonus. If it is red, the green tokens still get their bonus, but even multiplied by 7.4 their tiny share stays far behind 99.9%, and “ Paris” is picked anyway. The bonus changes nothing at this step. Whether a green token comes out depends only on whether “ Paris” happens to be green after “ is”, and the key makes that true 25% of the time, just as for a human who does not know the key. Here the factor brings the result down to 25%.
A toy model
I don’t have a real model in the loop yet, so I built a toy. At every step it draws a
random score for each of 1,000 tokens from a normal distribution. One setting,
sharpness, sets how far the scores spread around 0:
- At 0.5, even the most likely token gets only about 0.5%. Many words fit, as in an open sentence.
- At 2.0, the most likely token gets about 11%, so there are still many options.
- At 5.0, the most likely token gets about 54%, and the top five together about 85%. That stands in for a sentence with one right answer.
Generating a text takes four steps per token:
while len(token_ids) < length:
previous_token = token_ids[-1]
# 1. The toy model gives every token a random score.
scores = rng.normal(0, sharpness, vocab_size)
# 2. Green tokens get a bonus of delta.
scores = apply_watermark(scores, key, previous_token,
delta=delta)
# 3. Scores become probabilities.
probs = softmax(scores)
# 4. Draw the next token according to these probabilities.
next_token = int(rng.choice(vocab_size, p=probs))
token_ids.append(next_token)
Each text is 200 tokens long, which gives the detector 199 pairs to score. For every
combination of sharpness and delta I generated 20 texts and ran the detector from
Part 1 on each of them.
Results
To show what a single text looks like, here is a short one at sharpness = 0.5 and
delta = 2, coloured the way the detector sees it. G is green and R is red, and the first
token has no colour because it has no previous token:
start 814, then:
G G R R G R G G G R G G R G G G R G G (13 of 19 green)
13 of 19 are green, 68%, while the formula says 71%. With so few tokens, a difference of one or two green tokens is normal.
The table sums up all 240 texts. green is the average share of green tokens, z mean
the average z-score, z std how much z varies between the 20 texts, and detected the
share of texts above the threshold of z = 4:
sharpness delta green z mean z std detected
0.5 0.0 25% 0.1 1.1 0%
0.5 1.0 46% 6.9 1.2 100%
0.5 2.0 71% 15.1 0.9 100%
0.5 4.0 95% 22.7 0.4 100%
2.0 0.0 25% 0.0 1.1 0%
2.0 1.0 46% 6.9 1.4 100%
2.0 2.0 70% 14.7 1.0 100%
2.0 4.0 95% 22.8 0.5 100%
5.0 0.0 26% 0.2 1.0 0%
5.0 1.0 37% 3.9 1.1 40%
5.0 2.0 52% 8.9 1.5 100%
5.0 4.0 79% 17.5 1.0 100%
Without a bonus, the share stays at the 25% that chance gives, and z stays near 0, so no text is flagged, just like the “human” text in Part 1.
At sharpness 0.5 and 2.0, the measured shares are within two points of the formula:
46% instead of 48% at delta = 1. At delta = 2 and delta = 4 they match. Every text
with a bonus is detected, and even at delta = 1 the average z is 6.9, far above the
threshold of 4.
At sharpness 5.0, the bonus falls short of the formula. At delta = 1 only 37% of the
tokens are green instead of 48%, and even delta = 4 reaches only 79% instead of 95%.
This is the Paris case from above in a milder form: when a red token is far ahead,
multiplying the weight of a green competitor by 2.7 is not enough to overtake it, so the
model usually picks the same token as without the watermark.
37% green is almost exactly the example from the end of Part 1, where a text with 37.5% green needed about 190 tokens to reach z = 4. These texts have 199 pairs but a little less green, so on average they land just below the threshold, at z = 3.9. Because z varies by about 1 between texts, some score above 4 and some below: the detector found 8 of the 20, the 40% in the table. For the other 12 it would report “no watermark”, although every one of them was generated with the key.
A bigger bonus helps: at delta = 2 all 20 texts are detected again. But a bigger bonus
also pushes the model harder away from the tokens it would have picked, and that is the
cost I have not measured yet.
Why it runs in seconds
In Part 1 I listed speed as a limit: to apply the bonus, the generator needs the colour of every token at every step. For the toy model that is 1,000 calls to the keyed function per step. The whole experiment has 240 texts with 199 steps each, so computing every colour fresh would take about 48 million calls.
But the green list only depends on the key and the previous token. With 1,000 tokens there
are at most 1,000 different green lists, and green_mask computes each one once and
stores it:
_green_mask_cache = {}
def green_mask(key: str, prev_token: int, vocab_size: int,
gamma: float = 0.25) -> np.ndarray:
cache_key = (key, prev_token, vocab_size, gamma)
if cache_key in _green_mask_cache:
return _green_mask_cache[cache_key]
colours = []
for token_id in range(vocab_size):
green = is_green(key, prev_token, token_id, gamma)
colours.append(green)
mask = np.array(colours)
mask.setflags(write=False)
_green_mask_cache[cache_key] = mask
return mask
That brings the work down to at most a million calls, and the whole experiment takes about 3 seconds.
setflags(write=False) makes the stored array read-only, because every caller gets the
same array back: if one of them changed an entry, the green list would change for every
later caller too. A read-only array raises an error instead.
For a real model the cache helps much less. Qwen2.5 scores 151,936 tokens, and there are 151,665 possible previous tokens. Every new previous token costs 151,936 calls, and a complete cache would hold about 23 billion entries. Algorithm 2 of Kirchenbauer et al. avoids this: it seeds a random generator once per step instead of computing each colour separately. I will need something like that when the watermark goes into Qwen.
Known limits
The model is a toy. Its scores are random and do not depend on the previous tokens, while real text has structure: some passages have many options and others almost none. A real text mixes the rows of my table.
20 texts per setting. That is enough to see that sharpness 5.0 with delta = 1
behaves differently from the rest, but not to say whether the true detection rate there is
40% or 50%.
The cost is not measured. The table shows how strong the signal gets, but not how much the bonus changes what the model writes.
Repetition is still counted. The detector from Part 1 has not changed, so a pair that appears twenty times counts twenty times.
What I learned
Why softmax uses the exponential function
While writing softmax, I learned why models turn scores into probabilities with the
exponential function, and that this is the standard choice. It makes every weight
positive, keeps the order of the scores, and turns differences between scores into
factors. For the watermark, the last point matters most: adding delta to a score
multiplies the token’s weight by e^delta, the same factor for every green token. That is
why the share of green tokens follows a simple formula.
The provider does not control the signal alone
Working through Theorem 4.2, I learned that the bonus only matters where the model has a real choice. If the model gives one token almost 100%, that token is green with the same 25% chance as in a human text, with or without the bonus. How much watermark a text carries depends on how many real choices it contains.
The provider chooses delta, but not how many good options the model has while writing. A
factual answer with one right word per step carries less watermark than an open paragraph,
even with the same key and the same bonus.
Anthropic’s post on its own watermark describes the same effect for Claude: factual passages carry little watermark because there are fewer acceptable word choices, and detection does not work well on short texts. My toy model shows the mechanism behind that.
The spread matters as much as the average
An average z of 3.9 sounds close to the threshold of 4, almost good enough, but z varies
between texts, and at that average the detector is wrong for more than half of them. The
z std column turned out to matter as much as z mean.
One more reason a negative result proves little
In Part 1 I listed reasons why a negative result proves little: the wrong key, no watermark at all, or a text that is too short. This part adds one more: a text written with the watermark can still come out below the threshold if the model had few choices while writing it.
What comes next
First I want to measure what the bonus costs: how often the model picks a different token than it would have picked without the watermark. After that, the watermark goes into Qwen2.5 and runs on real text.
The code is at github.com/DilaraKoc1/inkwash.
python experiment.py prints the table and the coloured example from this post.
How I worked
I used Claude, an AI assistant by Anthropic, to summarise the paper by Kirchenbauer et al. for me and to support me in building this project along the lines of their scheme.