Nature 634, 818–823 (2024) · formulas left, widgets rightNature 634, 818–823(2024)· 左邊公式、右邊互動圖
Scalable watermarking for identifying
large language model outputs
SynthID-Text hides a statistical signature in LLM text by changing only how the next token is sampled. Anyone holding the key can later detect it from the text alone, without the model. It runs in Gemini today.SynthID-Text 只改「下一個 token 怎麼抽」,就在 LLM 的文字裡藏進一個統計特徵。持有金鑰的人之後只要拿到文字,不需要模型,就能偵測出來。它已經在 Gemini 上線。
Running example (paper, Fig. 2): the text so far is “… my favourite tropical fruit is”. The model gives mango 0.50, lychee 0.30, papaya 0.15, durian 0.05. We follow how the watermark picks the next word, and how a detector later recognises it.貫穿全頁的例子(論文圖 2):前文是「… my favourite tropical fruit is」,模型給 mango 0.50、lychee 0.30、papaya 0.15、durian 0.05。我們跟著看浮水印怎麼挑出下一個詞,以及偵測器之後怎麼認出它。
Models受測模型
Gemma 2B/7B-IT · Mistral 7B-IT
Seed window H種子視窗 H
4 tokens個 token
Layers m · samples N層數 m · 每場人數 N
30 · 2
g-value distributiong 值分布
Bernoulli(0.5)
Non-distortion無失真等級
single-sequence (K = 1)單序列(K = 1)
Scoring評分函數
Bayesian貝氏
Metric指標
TPR @ FPR = 1%
Extra latency額外延遲
+0.57% (Gemma 7B-IT)(Gemma 7B-IT)
Data: figures marked TOY run the paper's algorithms on invented data in your browser (32-bit toy hash, toy language model). Settings and numbers marked PAPER are the paper's.資料:標 TOY 的圖是在瀏覽器裡用論文的演算法跑玩具資料(32 位元的玩具雜湊、玩具語言模型)。標 PAPER 的設定與數字才是論文的。
Why watermark, and what a generative watermark is made of為什麼要浮水印,生成式浮水印由什麼組成
Three components: seed generator, sampling algorithm, scoring function三個元件:隨機種子產生器、取樣演算法、評分函數
There are three ways to tell AI text apart. Each has a cost:要分辨 AI 寫的文字,有三種做法,各有代價:
| Approach做法 | How怎麼做 | Problem問題 |
|---|---|---|
| Retrieval檢索 | store every generated text, look for matches存下所有生成過的文字,比對 | needs scale and coordination; privacy需要規模與協調;有隱私疑慮 |
| Post hoc detection事後偵測 | a classifier for “human vs AI”訓練「人寫 vs AI」分類器 | expensive, inconsistent; poor out of domain; more false positives for non-native writers; must be retrained as LLMs improve昂貴、不穩定;領域外表現差;對非母語寫作者偽陽性較高;LLM 進步就得重新訓練 |
| Generative watermark生成式浮水印 | bias the sampling with a secret key用秘密金鑰讓取樣產生偏差 | the provider must apply it; paraphrasing weakens it要由服務業者加上;改寫會削弱 |
Paper Fig. 1 shows the generative watermark: the only change to ordinary generation is the box that picks the token. Click a blue box to jump to its unit.論文圖 1 是生成式浮水印:和一般生成相比,唯一改變的是「挑 token」那一格。點藍框可以跳到對應的單元。
Generation and detection with a generative watermark生成式浮水印的生成與偵測
Redrawn from paper Fig. 1. Blue = the three watermark components.依論文圖 1 重畫。藍框=浮水印的三個元件。
PAPERWhat the LLM hands over: a distribution, and how much entropy it hasLLM 交出什麼:一個分布,以及它有多少熵
The watermark can only steer choices the model is unsure about浮水印只能在模型拿不定主意的地方動手腳
At each step the model gives a probability for every token, after top-k, top-p and temperature have been applied; the paper calls this final distribution pLM(·|x<t) (Definition 1). SynthID-Text works on top of any decoding setting with non-zero entropy.每一步,模型為每個 token 給一個機率;top-k、top-p、溫度都套用完之後的分布,論文稱為 pLM(·|x<t)(定義 1)。SynthID-Text 接在任何熵不為零的解碼設定後面。
The quantity that matters most is the collision probability C = Σp(x)²: the chance that two independent draws give the same token. A tournament match only does something when its two players differ, which happens with probability 1 − C.最重要的量是碰撞機率 C = Σp(x)²:獨立抽兩次抽到同一個 token 的機率。錦標賽的一場比賽,只有兩個參賽者不同時才有作用,而這個機率是 1 − C。
The example's next-token distribution under different temperatures例句的下一個 token 分布,在不同溫度下
τ = 1 gives the paper's numbers. pτ(x) ∝ p(x)1/τ is the same as dividing the logits by τ.τ = 1 就是論文的數字。pτ(x) ∝ p(x)1/τ 等同把 logit 除以 τ。
TOYRandom seed: hash the last H tokens with the key隨機種子:把前 H 個 token 和金鑰一起雜湊 component 1元件 1
The detector can recompute the same seed from the text alone偵測時只要有文字,就能重算出同一個種子
The seed for step t depends only on the previous H tokens and the secret key k (sliding window, H = 4 in the paper). Without the key the seed looks random; with it, anyone can rebuild it from the text.第 t 步的種子只取決於前 H 個 token 和秘密金鑰 k(滑動視窗,論文用 H = 4)。沒有金鑰時種子看起來是隨機的;有金鑰,任何人都能從文字重建它。
Which tokens decide the seed哪些 token 決定種子
Amber = the window that is hashed. Try changing “my” to “your”: with H ≤ 4 the seed does not move, because “my” is outside the window.黃框=被雜湊的視窗。試著把 my 換成 your:H ≤ 4 時種子不變,因為 my 在視窗外。
TOYseed rt (toy 32-bit hash)種子 rt(玩具 32 位元雜湊)
Repeated context masking重複上下文遮罩
If the same 4-token window appears twice, the seed and the bias repeat too, which can cause loops. So SynthID-Text skips the watermark at step t whenever its window was already used (Methods, Algorithm 3). With K = 1 the history lasts for one response; the detector skips the same steps.同一個 4 個 token 的視窗出現兩次,種子和偏好也會重複,可能造成重複迴圈。所以只要第 t 步的視窗之前用過,SynthID-Text 就不在這一步加浮水印(Methods 演算法 3)。K = 1 時,紀錄只保留一則回應;偵測時也跳過同樣的步驟。
g-values: a secret score for every token and layerg 值:每個 token、每一層各有一個秘密分數
Hash (token, layer, seed) → a number in [0, 1] → 0 or 1雜湊(token, 層, 種子)→ [0, 1] 中的數 → 0 或 1
Given the seed r, each token x gets one g-value per tournament layer ℓ = 1…m. The g-values have nothing to do with the model's probabilities, so without the key they look like coin flips. The paper uses Bernoulli(0.5): each g is 0 or 1 with equal chance.給定種子 r,每個 token x 在錦標賽的每一層 ℓ = 1…m 各有一個 g 值。g 值和模型機率毫無關係,所以沒有金鑰時看起來就像擲硬幣。論文用 Bernoulli(0.5):每個 g 各有一半機會是 0 或 1。
g-value table for the example例句的 g 值表
“Paper Fig. 2” shows the paper's values. “From 02's seed” computes them from the seed above. Click a cell to see how it is made.「論文圖 2」是論文給的值;「用 02 的種子」由上一節的種子算出。點一格看它怎麼算出來。
TOYTournament sampling: over-generate, then knock out by g-value錦標賽取樣:多抽幾個,再用 g 值淘汰 component 2 · new元件 2 · 本文新提出
2m candidates from the LLM, m knockout rounds, the last one standing is xt從 LLM 抽 2m 個候選,淘汰 m 輪,最後剩下的就是 xt
- Draw 2m candidates from pLM (repeats allowed). Likely tokens show up more often.從 pLM 抽 2m 個候選(可以重複)。機率高的 token 會出現比較多次。
- Layer ℓ: pair them up; in each pair the one with the higher gℓ wins. Ties are broken at random.第 ℓ 層:兩兩配對,gℓ 較高的晉級;平手就隨機決定。
- After m layers one token is left: the output xt.m 層之後剩一個 token,就是輸出 xt。
The tournament for “… my favourite tropical fruit is”「… my favourite tropical fruit is」的錦標賽
Uses the g-value table from 03 and the temperature from 01. The number next to a player is the g-value it competes with in that layer.用 03 的 g 值表和 01 的溫度。參賽者旁的數字,是它在那一層比賽用的 g 值。
TOYThe same tournament without drawing anything: the winner's distribution after each layer不用真的抽:每一層之後,勝者的機率分布
Non-distortion: averaged over keys, nothing changes無失真:對金鑰取平均,什麼都沒變
With exactly two players per match, the bias cancels out on average每場比賽恰好兩人時,偏差平均起來剛好抵銷
For one seed the tournament clearly favours tokens with g = 1. But a token with g = 1 under one seed has g = 0 under another, and for N = 2 the boosts and cuts cancel exactly: averaged over seeds, the output distribution equals pLM (Supplementary Theorems 17–18). With N > 2 they do not cancel (Theorem 19); that is the distortionary setting.對單一種子,錦標賽明顯偏好 g = 1 的 token。但一個 token 在這個種子下 g = 1,在另一個種子下就可能是 0;N = 2 時,放大與縮小剛好抵銷:對種子取平均,輸出分布就等於 pLM(補充資料定理 17–18)。N > 2 時抵銷不了(定理 19),這就是有失真設定。
One tournament layer, computed exactly一層錦標賽,精確計算
“Average over seeds” enumerates all 24 = 16 equally likely Bernoulli g-patterns of the 4 tokens and every N-tuple of candidates; no sampling noise. Grey tick = pLM.「對所有種子平均」列舉 4 個 token 全部 24 = 16 種同樣可能的 Bernoulli g 值組合,以及所有 N 個候選的組合;沒有抽樣誤差。灰色刻線=pLM。
TOYFour levels of non-distortion (weakest to strongest)四種無失真等級(由弱到強)
| Level等級 | Guarantee (averaged over keys)保證(對金鑰取平均) | How怎麼達成 |
|---|---|---|
| single-token單 token | one step's distribution = pLM一步的分布 = pLM | N = 2 tournament (or Gumbel)N = 2 的錦標賽(或 Gumbel) |
| single-sequence單序列 | a whole response is as likely as without watermark一整則回應的機率和沒加浮水印一樣 | + 1-sequence repeated context masking — the paper's setting+ 1 序列重複上下文遮罩——論文的設定 |
| K-sequenceK 序列 | K consecutive responses jointly連續 K 則回應的聯合機率 | + K-sequence masking (masks more → weaker detection)+ K 序列遮罩(遮掉更多 → 偵測變弱) |
| infinite-sequence無限序列 | any number of responses任意多則回應 | K = ∞ |
Detection: recompute the g-values and average them偵測:重算 g 值,取平均 component 3元件 3
Unwatermarked text averages 0.5; watermarked text a little more沒有浮水印的文字平均 0.5;有浮水印的高一點
The detector only needs the tokenised text and the key: it rebuilds every seed rt, looks up gℓ(xt, rt) for every step and layer, and scores the text. No model is involved. Two things decide how well this works: the length T (more evidence) and the entropy of the model when it wrote the text.偵測器只需要分詞後的文字和金鑰:重建每一步的種子 rt,查出每一步、每一層的 gℓ(xt, rt),再給文字打分。完全不需要模型。效果好壞由兩件事決定:文字長度 T(證據多寡),以及模型寫這段文字時的熵。
Watermarked vs unwatermarked texts from a toy language model玩具語言模型產生的有/無浮水印文字
120 watermarked and 300 unwatermarked texts of up to 300 tokens; vocabulary 24, random logits per step, H = 4, repeated context masking, Bernoulli g-values, N = 2. Threshold = top 1% of unwatermarked scores.120 段有浮水印、300 段無浮水印的文字,最長 300 個 token;詞彙 24 個、每步隨機 logit、H = 4、重複上下文遮罩、Bernoulli g 值、N = 2。門檻=無浮水印分數的前 1%。
TOYSelective prediction選擇性預測
When low error rates matter, use two thresholds per length: above one → watermarked, below the other → not, in between → abstain. Paper Fig. 3b: to reach TPR 95% at FPR 1%, short texts need more abstentions; longer texts and higher temperatures need fewer.需要很低的錯誤率時,每種長度設兩個門檻:高於上門檻 → 有浮水印;低於下門檻 → 沒有;中間 → 棄權。論文圖 3b:要在 FPR 1% 下達到 TPR 95%,短文字要棄權較多;文字越長、溫度越高,棄權越少。
Making it fast: watermarking with speculative sampling讓它夠快:浮水印搭配推測取樣
A small draft model proposes, the big target model verifies小的草稿模型提議,大的目標模型檢查
Production systems often use speculative sampling: a small draft model p proposes a few tokens, and the large target model q checks them in one parallel pass, accepting each with probability min(1, q/p). The output follows q exactly. The paper gives two ways to add the watermark; each keeps two of three wishes: non-distortion, acceptance rate (speed), detectability.正式系統常用推測取樣:小的草稿模型 p 先提議幾個 token,大的目標模型 q 一次平行檢查,每個以 min(1, q/p) 的機率接受。輸出完全服從 q。論文給了兩種加浮水印的方法,各自滿足三個願望(無失真、接受率=速度、可偵測性)中的兩個。
One round of speculative sampling with a watermark加了浮水印的一輪推測取樣
Paper's experiment: target Gemma 7B-IT, draft Gemma 2B-IT, 3 lookahead tokens.論文實驗:目標 Gemma 7B-IT、草稿 Gemma 2B-IT、每次 3 個前瞻 token。
PAPERWhat the paper reports論文的結果
Quality unchanged, detection better, latency negligible品質不變、偵測較好、延遲可忽略
| Claim主張 | Evidence in the paper論文的證據 |
|---|---|
| Quality unchanged at scale大規模下品質不變 | Live Gemini experiment, ~20 million responses: thumbs-up rate differs by 0.01% (watermarked higher), thumbs-down by 0.02% (watermarked lower); both not significant, within the 95% CI.Gemini 線上實驗,約 2,000 萬則回應:按讚率相差 0.01%(浮水印較高),倒讚率相差 0.02%(浮水印較低);兩者都不顯著,在 95% 信賴區間內。 |
| Quality unchanged, controlled受控實驗品質不變 | Gemma 7B-IT, 3,000 ELI5 questions, side-by-side ratings on grammar/coherence, relevance, correctness, helpfulness, overall: no significant preference. Perplexity and benchmarks also unchanged.Gemma 7B-IT、3,000 個 ELI5 問題,並排比較文法/連貫、相關、正確、有用、整體:沒有顯著偏好。困惑度與基準測試也沒變。 |
| Better detection, non-distortionary無失真類別偵測較好 | Beats Gumbel sampling at the same length (Fig. 3a); the gap is largest at low entropy (low temperature, larger models). Better diversity/detectability trade-off too.相同長度下勝過 Gumbel 取樣(圖 3a);熵越低(低溫、大模型)差距越大。多樣性/可偵測性的取捨也較好。 |
| Better detection, distortionary有失真類別偵測較好 | For the same log-perplexity cost, much higher TPR@FPR=1% than Soft Red List (Fig. 3c).同樣的 log 困惑度代價下,TPR@FPR=1% 明顯高於 Soft Red List(圖 3c)。 |
| Negligible latency延遲可忽略 | Gemma 7B-IT on 4 TPU v5e: 15.527 → 15.615 ms/token with 30 layers (+0.57%). Gumbel +0.26%, Soft Red List +0.28%. Cost does not grow with model size.Gemma 7B-IT 跑在 4 顆 TPU v5e:30 層時每 token 15.527 → 15.615 ms(+0.57%)。Gumbel +0.26%、Soft Red List +0.28%。成本不隨模型變大而增加。 |
| Works with speculative sampling能搭配推測取樣 | Fast watermarked speculative sampling: acceptance rate very similar with and without watermark.快速浮水印推測取樣:有無浮水印的接受率非常接近。 |
| Deployed已部署 | Watermarks Gemini and Gemini Advanced; first generative text watermark deployed at scale. Code: google-deepmind/synthid-text.為 Gemini 與 Gemini Advanced 加浮水印;第一個大規模部署的生成式文字浮水印。程式碼:google-deepmind/synthid-text。 |
Limitations (paper)限制(論文)
- Only detects text from providers that apply it; other sources need post hoc detection.只能偵測有加浮水印的服務產生的文字;其他來源要靠事後偵測。
- Hard to enforce on open-source models deployed in a decentralised way.開源模型以去中心化方式部署,很難強制加上。
- Vulnerable to stealing, spoofing and scrubbing attacks (open research).可能受到竊取、偽造、清除攻擊(仍在研究中)。
- Edits and LLM paraphrasing weaken it; long texts survive random word deletion, but thorough paraphrasing is a strong attack (Supplementary C.6).編輯與 LLM 改寫會削弱它;長文字被隨機刪字後仍可偵測,但徹底的逐句改寫是很強的攻擊(補充資料 C.6)。
- Little entropy, little watermark: near-deterministic answers carry almost no signal.熵少,浮水印就少:幾乎確定的回答帶不了什麼訊號。