Undetectable Watermarks for Language Models

Miranda Christ, Sam Gunn, Or Zamir

Introduction

With the rise in the use of artificial models that churn out human-like text, there’s also an increase in the potential for misuse. Imagine a student employing a language model to effortlessly write her “Machine Learning 101” homework or conjuring up tear-jerking emails to beg professors for easier exams. That’s when the need arises to distinguish between texts penned by a language model and those crafted by human hands. The go-to method of employing a heuristic test to determine if a text was AI-generated, however, grows increasingly fragile as large language models (LLMs) advance. Even the cutting-edge detectors, like GPTZero [Tia23], can be outsmarted with cleverly crafted prompts.

Ultimately, as LLM outputs move closer to becoming identical to human-generated text, this approach becomes hopeless. It is already very hard to tell, for instance, that the previous paragraph was written by such a model. To overcome this problem, it is reasonable to consider intentionally modifying the model to embed watermarks into the text. Recent work of [KGW+23] introduced such watermarks in the context of LLMs. However, existing watermarking schemes come with a cost: To plant a useful watermark, the distribution of texts the model generates has to be noticeably changed. In fact, for existing schemes it is possible for the user to distinguish between outputs of the original model and of the watermarked one, and it is hence possible that the quality of text degrades.

We show how to plant watermarks with the following properties, stated informally, in any LLM.

(Undetectability) It is computationally infeasible to distinguish between the original and the watermarked models, even when the user is allowed to make many adaptive queries. In particular, the quality of generated text remains identical.

(Completeness) There is a secret key that enables efficient detection of responses from the watermarked model, as long as “enough randmoness” was used to generate the response. The detection works even when presented with only a contiguous sub-string from the response, and it doesn’t require any other information.

(Soundness) Any text generated independently from the secret key has a negligible chance of being detected as watermarked.

We note that the existence of a secret key is necessary, as otherwise Properties (1) and (2) would directly contradict each other. However, in practice the secret key can be published if one wishes; Property (1) still ensures that the quality of the text is imperceptibly changed for all uses not involving the secret key.

An important aspect of our construction is that Properties (1) and (3) will always hold, for any LLM with any choice of parameters, and without making any assumptions on the text. Our scheme is the first to have these properties, and we argue that they are completely crucial. First, the creator of a state-of-the-art LLM is unlikely to intentionally degrade the quality of their model, making Property (1) necessary for any practical watermarking scheme. As the quality and versatility of LLMs has reached such high levels, any noticeable change due to the watermark is liable to have adverse side-effects in some situations. Second, falsely accusing humans of using LLMs to generate their texts should be completely unacceptable. When heuristics are used for detection, this will always be a possibility — indeed, instances of such false accusations against students have already made news headlines [Fow23, Jim23], and concerningly, false accusations are more common for non-native English writers [LYM+23]. Property (3) in our construction rigorously guarantees that natural text will not be detected as watermarked.

Of course, a watermark is only useful if it can be detected with the secret key. If the model has a deterministic response to some prompt, then we should not be able to embed the watermark in that response (as any change to the output would necessarily be detectable). For Property (2), we therefore need to assume that enough “randomness” was used in the generation of the specific text we are considering. We introduce a formal notion that we call empirical entropy, and show that this condition is necessary. Our detection algorithm works when it is given text containing any consecutive sub-string with enough empirical entropy from an output of the model.

Primary contributions of this work include the formal definition and construction of undetectable watermarks, and the notion of empirical entropy that quantifies the randomness used in the generation of a specific output. These definitions and our results appear in Section 2.

Approaches for detecting AI-generated text largely fall into two categories. Watermarking schemes alter the output of a language model in a way that a corresponding detection algorithm can identify. Post-hoc detectors leave the output of the model unchanged and instead identify AI-generated text using existing differences between natural language and the model’s output.

The simplest post-hoc detectors use natural heuristics to distinguish between human- and AI-generated text. These heuristics include relative entropy scoring [LUY08], perplexity [Ber16], and other statistical methods [GSR19]; see [Ber16] for a survey of such methods. Other post-hoc detectors (e.g., [ZHR+19, MLK+23, Tia23, KAAL23]) are themselves models, specifically trained for this binary classification task. Unfortunately, these heuristic and model-based methods lack formal guarantees, and it’s possible to train a model to transform AI-generated text in a way that evades them; see, e.g., [KSK+23, SKB+23]. For example, [KSK+23] trains a model to paraphrase text output by language models, fooling common post-hoc detectors such as GPTZero [Tia23], DetectGPT [MLK+23], and the detector developed by OpenAI [KAAL23]. Furthermore, simple tricks such as instructing the model in the prompt to write a response that evades a detector, or varying the model’s parameters (e.g., increasing the temperature and frequency/presence penalties for GPT-4), fool [Tia23]. [CBZ+23] prove that as AI-generated text more closely resembles natural text, post-hoc detectors will need longer text samples.

See [JAML20] for more comprehensive background on post-hoc detection of AI-generated text and attacks.

Language watermarking schemes.

Several schemes (e.g., [AF21, QZL+23, YAJK23, MZ23]) involve using an ML model in the watermarking algorithm itself. [AF21, MZ23] work by taking a passage of text and using a model to produce a semantically similar altered passage. By nature of using machine learning, these constructions have no formal guarantees and rely on heuristic arguments for undetectability, soundness, and correctness.

In a recent work, [KGW+23] presented the first watermarking scheme for LLMs with any formal guarantees. They showed that a watermark can be planted in outputs with large enough entropy (with a definition different than ours, yet morally similar). However, their watermarking scheme crucially changes the distribution of generated texts and uses this change to detect the watermark. They bound the difference between the original distribution and the distribution of their watermarked model, using a quantity called perplexity. In contrast, in our work the original and watermarked output distributions are completely indistinguishable.

The authors of this paper are also aware of an ongoing watermarking project of [Aar22], which he mentions in his blog. It appears that in this project, the guarantee is that the two distributions will be indistinguishable, but only as long as no two output texts are seen that share a common substring of a certain length. In contrast, our construction guarantees undetectability without any assumption on the texts or the model. In particular we allow the distinguisher to make adaptive queries with arbitrary prompts, so it may force the model to return outputs that share long parts with each other.

Our scheme, as well as those of [KGW+23] and [Aar22] are vulnerable to simple attacks such as the “emoji attack”https://twitter.com/goodside/status/1610682909647671306 discussed in [KGW+23]. We discuss attacks on watermarking schemes further in Section 6.1.

Steganography.

Steganography is the study of encoding a hidden message into a given channel (e.g., natural language or an image) such that a recipient possessing a key can read the message but an eavesdropping adversary cannot determine whether a message is present. [HvAL09] defines security of a steganography scheme against a chosen hiddentext attack (CHA) as the requirement that an adversary cannot determine whether a given oracle is for the original distribution or the distribution embedded with a hiddentext. Porting this definition over to the watermark setting, one would obtain undetectability. However, the corresponding steganography schemes we are aware of would not obtain undetectability without making assumptions about the entropy of the channel. Crucially, in our setting where prompts for the language model are adversarially chosen, we want to retain undetectability even if the adversary submits a prompt with a deterministic response.

Part of the reason for this difference stems from the access that the watermark and encoding algorithms have to the channel (or the distribution of the language model’s output). In steganography, the encoding algorithm has only oracle access to the channel. In our language model setting, the watermark algorithm receives from the model a full description of the probability distribution pip_{i} for each token. Because of this limited access, steganography schemes largely either rely on assumptions about the entropy of the channel (e.g., [HvAL09]) or lose security when the channel has low entropy (e.g., [DIRR09]). Our watermark is undetectable regardless of the entropy of the text. We achieve this guarantee exactly by using the watermark algorithm’s access to the distributions pip_{i}. Using this knowledge, the algorithm is able to compute the empirical entropy of its output thus far. Once the empirical entropy is sufficiently high, it uses the output as a random seed for a PRF used to embed the watermark in subsequent tokens. Importantly, our algorithm alters the output distribution only once it has collected enough entropy; in the steganography schemes, the encoding algorithm with only oracle access does not know when this has happened.

This complete knowledge of each token distribution pip_{i} separates the problem of watermarking language models from watermarking more generally. One prior steganography scheme for language models, [KJGR21], operates in our regime where the encoding algorithm has access to each pip_{i}. However, it assumes that the decoding algorithm has access to each pip_{i} as well. This is unrealistic for watermarking, as the probability distributions pip_{i} for the output of the model on some prompt depend on that prompt. A watermark detection algorithm, which receives only the output and not the prompt, does not know the distributions pip_{i}. In practice, it would be unrealistic to assume that a detector trying to determine whether an essay was generated by a language model would also be given the prompt used to generate it.

Watermarking.

The field of digital watermarking focuses on the problem of covertly planting a signal in a medium (e.g., an image or text) such that it can be detected by an algorithm. [ARC+01, ARH+03] present some of the first watermarking schemes for NLP-generated text, though their schemes rely on a syntactic tree structure that was present in NLP models at that time but no longer used today. [HMW07] formally defines watermarking and desired properties, though these definitions are not tailored to language models.

Other related work.

Recently, [GKVZ22] used a cryptographic construction to embed undetectable backdoors into neural networks. In both their work and ours, cryptographic notions of indistinguishability are used in the context of machine-learning, rather than empirical notions.

2 Organization of the Paper

In Section 2 we formally define our model, introduce the notions of empirical entropy and undetectable watermarks, and outline our results. In Section 3 we sketch a simple watermarking scheme that achieves undetectability, but falls short of our main scheme in other respects. In Section 4 we construct our undetectable watermarks with strong completeness and soundness guarantees. We include an overview of these constructions in Section 4.2. In Section 5 we discuss the necessity of the assumptions we make. In Section 6 we discuss possible methods of removing watermarks from texts. In particular, we prove that it is impossible to create undetectable watermarks that are completely unremovable, under certain assumptions. In Section 7 we summarize and discuss open problems.

Modeling the Problem

Let \secpar\secpar denote the security parameter. A function ff of \secpar\secpar is negligible if f(\secpar)∈O(1\poly(\secpar))f(\secpar)\in O(\frac{1}{\poly(\secpar)}) for every polynomial \poly(⋅)\poly(\cdot). We denote f(\secpar)≤\neglf(\secpar)\leq\negl to mean that ff is negligible. For a vector or sequence of tokens s=(s1,…,s\absolutevalues)s=(s_{1},\ldots,s_{\absolutevalue{s}}) and positive integers b≥ab\geq a, let s[a:b]s[a:b] denote (sa,…,sb)(s_{a},\ldots,s_{b}). We use log⁡(x)\log(x) to denote the logarithm base 2 of xx, and ln⁡(x)\ln(x) to denote the natural logarithm of xx. For integer n>0n>0, we define [n]:={1,…,n}[n]:=\{1,\dots,n\}. For integers n≥k>0n\geq k>0, we define [k,n]:={k,…,n}[k,n]:=\{k,\dots,n\}.

Pseudorandom function (PRF).

2 Language Models

We loosely follow [KGW+23] in our definition of a language model. We will often refer to language models simply as models.

A language model Model\mathsf{Model} over token set T\cal{T} is a deterministic algorithm that takes as input a prompt prompt and tokens previously output by the model x=(x1,…,xi−1)x=(x_{1},\ldots,x_{i-1}), and outputs a probability distribution pi=Model(\textscprompt,x)p_{i}=\mathsf{Model}(\textsc{prompt},x) over T\cal{T}.

A language model Model\mathsf{Model} is used to generate text as a response to a prompt by iteratively sampling from the returned distribution until a special terminating token done∈T\texttt{done}\in\cal{T} is drawn.

A language model’s response to a prompt prompt is a random variable Model‾(\textscprompt)∈T⋆\overline{\mathsf{Model}}(\textsc{prompt})\in\mathcal{T}^{\star} that is defined algorithmically as follows. We begin with an empty list of tokens x=()x=(). As long as the last token in xx is not done, we draw a token xix_{i} from the distribution Model(\textscprompt,x)\mathsf{Model}(\textsc{prompt},x) and append it to xx. Finally, we set Model‾(\textscprompt)=x\overline{\mathsf{Model}}(\textsc{prompt})=x.

Throughout the text we will make use of a security parameter λ\lambda. We will assume that our model never outputs text of length super-polynomial in λ\lambda. (For OpenAI’s language models, there is actually a fixed limit to the length of generated text.)

3 Entropy and Empirical Entropy

Let log⁡(x)\log(x) denote the logarithm base 2 of xx. For a probability distribution DD over elements of a finite set XX, we define the Shannon entropy of DD as

where D(x)D(x) is the probability of xx in the distribution DD. The empirical entropy of xx in DD is simply −log⁡D(x)-\log D(x). The expected empirical entropy of x∼Dx\sim D is exactly H(D)H(D). Intuitively, the empirical entropy of xx (with respect to DD) is the number of random bits that were required to draw xx out of the distribution DD. The entropy H(D)H(D) is thus the expected number of random bits needed to draw an element out of the distribution DD.

We thus define the empirical entropy of a model’s response as follows.

For a language model Model\mathsf{Model}, a prompt prompt, and a possible response x∈T⋆x\in\mathcal{T}^{\star}, we define the empirical entropy of Model‾\overline{\mathsf{Model}} responding with xx to prompt as

We next generalize the definition of empirical entropy from whole outputs to substrings out of a model’s output. Intuitively, we want to measure how much entropy was involved in the generation of a particular contiguous substring of the output.

For a language model Model\mathsf{Model}, a prompt prompt, a possible response x∈T⋆x\in\mathcal{T}^{\star}, and indices i,j∈[\absolutevaluex]i,j\in[\absolutevalue{x}] with i≤ji\leq j we define the empirical entropy on substring [i,j][i,j] of Model‾\overline{\mathsf{Model}} responding with xx to prompt as

We sometimes write Hei:=He[i,i]H_{e}^{i}:=H_{e}^{[i,i]} to denote the empirical entropy of a single token ii. We remark that in expectation, Definition 3 simply captures the entropy in the response generation. That is, we have

where x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}\left(\textsc{prompt}\right).

4 Watermarks

We formally define a watermarking scheme as follows.

A watermarking scheme for a model Model\mathsf{Model} over T\cal{T} is a tuple of algorithms W=(Setup,Wat,Detect)\mathcal{W}=(\mathsf{Setup},\mathsf{Wat},\mathsf{Detect}) where:

Setup(1\secpar)→\sk\mathsf{Setup}(1^{\secpar})\to\sk outputs a secret key, with respect to a security parameter \secpar\secpar.

Wat\sk(\textscprompt)\mathsf{Wat}_{\sk}(\textsc{prompt}) is a randomized algorithm that takes as input a prompt prompt and generates a response in T⋆\cal{T}^{\star}.

Detect\sk(x)→{\true,\false}\mathsf{Detect}_{\sk}(x)\to\{\true,\false\} is an algorithm that takes as input a sequence x∈T⋆x\in\cal{T}^{\star} outputs \true\true or \false\false.

Ideally, Detect\sk(x)\mathsf{Detect}_{\sk}(x) should output \true\true if xx is generated by Wat\sk(\textscprompt)\mathsf{Wat}_{\sk}(\textsc{prompt}), and should output \false\false if xx is generated independently of \sk\sk. The former property is called completeness and the latter soundness.

A watermarking scheme W\mathcal{W} is sound if for every security parameter \secpar\secpar and token sequence x∈T⋆x\in\mathcal{T}^{\star} of length \absolutevaluex≤\poly(λ)\absolutevalue{x}\leq\poly(\lambda),

A scheme is sound if any text that is generated independently from \sk\sk has negligible probability of being detected as watermarked by Detect\sk\mathsf{Detect}_{\sk}. Essentially, this means we will never see a false-positive detection.

Defining completeness requires care: It is not reasonable to require Detect\sk\mathsf{Detect}_{\sk} to detect any sequence xx generated by Wat\sk(\textscprompt)\mathsf{Wat}_{\sk}(\textsc{prompt}) for some prompt, as it is possible that xx is very short, or that Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) is deterministic or has very low entropy. Instead, we require Detect\sk\mathsf{Detect}_{\sk} to detect watermarks only in responses for which the entropy in the generation process is high enough.

A watermarking scheme W\mathcal{W} is b(L)b(L)-complete if for every security parameter λ\lambda and prompt prompt of length \absolutevalue\textscprompt≤\poly(λ)\absolutevalue{\textsc{prompt}}\leq\poly(\lambda),

Definition 7 guarantees that any output generated by Wat\sk\mathsf{Wat}_{\sk} with empirical entropy at least b(L)b(L), where LL is the length of the output, will be detected as watermarked with high probability. Essentially, this means we will never see a false-negative detection on any output of high enough empirical entropy. In Section 5 we show that it is necessary to consider the empirical entropy of the specific output rather than the standard entropy of the entire model.

We also generalize Definition 7 to capture contiguous substrings of outputs. That is, we should be able to detect a watermarked output of Wat\sk\mathsf{Wat}_{\sk} even if Detect\sk\mathsf{Detect}_{\sk} is only given a long enough contiguous substring from it.

A watermarking scheme W\mathcal{W} is b(L)b(L)-substring-complete if for every prompt prompt and security parameter λ\lambda,

This means that every contiguous part of an output of the watermarking procedure, that has high enough empirical entropy, is detected as watermarked with high probability. We stress that the empirical entropies in Definitions 7 and 8 are defined with respect to the original model Model\mathsf{Model}, without reference to the watermarking procedure Wat\sk\mathsf{Wat}_{\sk}. We also note that the empirical entropy He(Model,\textscprompt,x)H_{e}(\mathsf{Model},\textsc{prompt},x) is only used as part of the definition, and is not necessarily known to Detect\sk\mathsf{Detect}_{\sk}. It is in general not possible to compute He(Model,\textscprompt,x)H_{e}(\mathsf{Model},\textsc{prompt},x) without knowledge of prompt.

5 Undetectable Watermarks

Finally, we define the notion of computationally undetectable watermarking schemes. Intuitively, a scheme is undetectable if it is infeasible to distinguish between the distributions of Model‾\overline{\mathsf{Model}} and Wat\sk\mathsf{Wat}_{\sk}, even when those can be queried adaptively with arbitrary prompts.

A watermarking scheme W=(Setup,Wat,Detect)\mathcal{W}=(\mathsf{Setup},\mathsf{Wat},\mathsf{Detect}) is undetectable if for every security parameter \secpar\secpar and all polynomial-time distinguishers DD,

where the notation DO1,O2D^{\mathcal{O}_{1},\mathcal{O}_{2}} means that DD is allowed to adaptively query both O1\mathcal{O}_{1} and O2\mathcal{O}_{2} with arbitrary prompts.

Note that in the above definition, we allow the distinguisher access to Model\mathsf{Model} itself as well as Model‾\overline{\mathsf{Model}} or Wat\sk\mathsf{Wat}_{\sk}. The only thing that is kept secret from the distinguisher is the secret key.

It is important to remark that in any undetectable watermarking scheme, the quality of outputs must be identical between Model‾\overline{\mathsf{Model}} and Wat\sk\mathsf{Wat}_{\sk}, as otherwise it would be possible to distinguish between them. In particular, embedding the watermark does not degrade the quality of the generated text at all.

We finally note that a watermarking scheme can be made public by publishing the secret key \sk\sk. Then, everyone can run the detection algorithm Detect\sk\mathsf{Detect}_{\sk}. In particular, the scheme is no longer undetectable as Detect\sk\mathsf{Detect}_{\sk} can be used to distinguish between Model‾\overline{\mathsf{Model}} and Wat\sk\mathsf{Wat}_{\sk}. Nevertheless, we still maintain the property that there is no degradation in the quality of watermarked outputs, as long as the definition of “quality” does not depend on the secret key \sk\sk.

6 Statement of our Theorems

We are now ready to formally state the guarantees of the watermarking schemes that we present. To warm up, in Section 3 we give a simple construction of an O(λ)O\left(\lambda\right)-complete scheme, but it only achieves a much weaker notion of soundness, and the watermarking algorithm runs in expected \poly(λ)\poly(\lambda) time rather than strict \poly(λ)\poly(\lambda) time. In Section 4.3, we prove the following theorem by introducing an efficient watermarking scheme with Algorithms 3 and 4.

For any model Model\mathsf{Model} we construct a watermarking scheme W\mathcal{W} that is undetectable, sound, and O(λL)O(\lambda\sqrt{L})-complete.

This means that our watermarking scheme is always undetectable and sound, and is also complete as long as there is enough empirical entropy in the model’s response.

In Section 5 we show that it is necessary for the completeness parameter b(L)b(L) to be reasonably large, with respect to λ\lambda. In fact, we show that it is inherent that low empirical entropy outputs are not watermarked in any undetectable watermarking scheme for any model.

To strengthen Theorem 1, we also present a modified scheme (Algorithms 5 and 6) in Section 4.4 which obtains substring completeness, with similar parameters.

For any model Model\mathsf{Model} we construct a watermarking scheme W\mathcal{W} that is undetectable, sound, and O(λL)O(\lambda\sqrt{L})-substring-complete.

In Section 6 we discuss known attacks on methods of detecting AI-generated text. We also prove that any undetectable watermarking scheme is removable, if the model enables a fairly strong form of query access and if one is willing to expend a number of queries that grows linearly with the size of generated text. Finally, in Section 7 we pose some open problems related to this work.

Simplified Construction

In this section we describe a simple construction of an undetectable watermarking scheme that achieves Θ(λ)\Theta\left(\lambda\right)-completeness. However, this scheme falls short of our main constructions in Section 4 in two important ways. First, it has a false-positive rate of ε=1/\poly(λ)\varepsilon=1/\poly(\lambda) instead of \negl\negl. We call such a scheme ε\varepsilon-weakly-sound. Second, the watermarking procedure Wat\sk\mathsf{Wat}_{\sk} is not very efficient: Its expected run-time is polynomial in the length of the output and in 1ε\frac{1}{\varepsilon}, but the worst-case running time of Wat\sk\mathsf{Wat}_{\sk} is unbounded.

Later, in Section 4 we present our main construction which is undetectable, sound, complete (in fact, it is even substring-complete) and efficient, yet achieves suboptimal completeness. Bridging this gap is an interesting open problem discussed in Section 7.

We begin by adding another strong assumption, that the min-entropy of the response to any prompt is at least 5\secpar5\secpar. Equivalently, let prompt be a prompt and assume that for every xx, we have He(Model,\textscprompt,x)≥5λH_{e}(\mathsf{Model},\textsc{prompt},x)\geq 5\lambda. We define the watermarking scheme as follows. The distribution of WatO(\textscprompt)\mathsf{Wat}^{\mathcal{O}}(\textsc{prompt}) is defined as the distribution of x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) conditioned on O(x)=0b\mathcal{O}(x)=0^{b}. Equivalently, WatO(\textscprompt)\mathsf{Wat}^{\mathcal{O}}(\textsc{prompt}) repeatedly draws outputs from Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) until the first time it gets a response xx for which O(x)=0b\mathcal{O}(x)=0^{b}, and then it returns xx. Note that this requires 2b2^{b} calls to Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) in expectation. To detect whether a string xx is watermarked, DetectO\mathsf{Detect}^{\mathcal{O}} simply checks whether O(x)=0b\mathcal{O}(x)=0^{b}. We assume that b≤λb\leq\lambda and sketch a proof for the above scheme being weakly sound, complete and undetectable.

For any string xx, the value of O(x)\mathcal{O}(x) is truly random by the assumption. Thus, it is detected as watermarked with probability 2−b2^{-b}.

Complete:

By definition, WatO(\textscprompt)\mathsf{Wat}^{\mathcal{O}}(\textsc{prompt}) only produces outputs xx such that O(x)=0b\mathcal{O}(x)=0^{b}, which are detected as watermarked by DetectO\mathsf{Detect}^{\mathcal{O}}.

Undetectable:

Let DD be a distinguisher that can query WatO(\textscprompt)\mathsf{Wat}^{\mathcal{O}}(\textsc{prompt}) at most 2λ2^{\lambda} times. In expectation, the total number of times WatO(\textscprompt)\mathsf{Wat}^{\mathcal{O}}(\textsc{prompt}) queries Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) to answer all queries is at most 2λ⋅2b≤22λ2^{\lambda}\cdot 2^{b}\leq 2^{2\lambda} (since b≤\secparb\leq\secpar by assumption). As the probability of each output xx to be output by Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) is at most 2−5λ2^{-5\lambda}, and as 22λ≪25λ2^{2\lambda}\ll\sqrt{2^{5\lambda}}, with high probability O\mathcal{O} is never queried twice on the same input. If O\mathcal{O} is never queried on the same input twice, then it simply outputs an independent random value for each query. In particular, the process of repeatedly sampling x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) until O(x)=0b\mathcal{O}(x)=0^{b} is equivalent to repeatedly sampling x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) until an independent, fresh random string is 0b0^{b} — which is identical to simply sampling x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}).

2 Removing the high min-entropy assumption

We next define a scheme that no longer requires the assumption about the min-entropy of the model. We do so by only watermarking outputs with empirical entropy higher than 6λ6\lambda, corresponding to the definition of (6λ)(6\lambda)-complete schemes.

Let prompt be any prompt and consider the probability

Denote by M≤M_{\leq} the distribution x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) conditioned on He(Model,\textscprompt,x)≤6λH_{e}\left(\mathsf{Model},\textsc{prompt},x\right)\leq 6\lambda. Similarly, denote by M>M_{>} the distribution x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) conditioned on He(Model,\textscprompt,x)>6λH_{e}\left(\mathsf{Model},\textsc{prompt},x\right)>6\lambda. Drawing x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) is equivalent to the following process: with probability pp, we draw a string out of the distribution M>M_{>}, otherwise, we draw a string out of M≤M_{\leq}.

Therefore, we consider the following natural algorithm for WatO\mathsf{Wat}^{\mathcal{O}}. We first flip a biased coin c∼Bernoulli(p)c\sim\text{Bernoulli}(p). If c=0c=0 then we draw an output from the distribution M≤M_{\leq}. If c=1c=1, then we apply the algorithm of Section 3.1 — that is, we draw an output from the distribution x∼M>x\sim M_{>} conditioned on O(x)=0b\mathcal{O}(x)=0^{b}.

This scheme is again weakly sound, and it is complete for every output xx with empirical entropy at least 6λ6\lambda because these outputs will always satisfy O(x)=0b\mathcal{O}(x)=0^{b}. If p≤2−λp\leq 2^{-\lambda}, then undetectability is straightforward: with all but negligible probability, the distinguisher will only see outputs from M≤M_{\leq}, which we did not change. Otherwise, p>2−λp>2^{-\lambda} and thus the distribution M>M_{>} is of min-entropy at least 6λ−λ=5λ6\lambda-\lambda=5\lambda. In particular, the construction of Section 3.1 applied to M>M_{>} is guaranteed to be undetectable.

We finally note that it is intractable to compute the value of pp or the conditional distributions M≤,M>M_{\leq},M_{>}. We avoid their explicit computation as follows. To implement WatO\mathsf{Wat}^{\mathcal{O}}, we first draw a string x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}). Computing the empirical entropy He(Model,\textscprompt,x)H_{e}(\mathsf{Model},\textsc{prompt},x) given Model,\textscprompt,x\mathsf{Model},\textsc{prompt},x is straightforward. The probability that He(Model,\textscprompt,x)>6λH_{e}(\mathsf{Model},\textsc{prompt},x)>6\lambda is of course exactly pp. Thus, we can check if He(Model,\textscprompt,x)≤6λH_{e}(\mathsf{Model},\textsc{prompt},x)\leq 6\lambda. If so, we simply output xx. Otherwise, we need to sample a response from M>M_{>} conditioned on its output under O\mathcal{O} being 0b0^{b}. We can do so by repeatedly sampling x∼Model‾(\textscprompt)x\sim\overline{\mathsf{Model}}(\textsc{prompt}) until both He(Model,\textscprompt,x)>6λH_{e}(\mathsf{Model},\textsc{prompt},x)>6\lambda and O(x)=0b\mathcal{O}(x)=0^{b}. Note that the probability of success is now p⋅2−bp\cdot 2^{-b}, and thus in expectation 1p2b\frac{1}{p}2^{b} tries are needed, which may be very large if pp is small. On the other hand, we only reach this loop with probability pp; hence, the expected number of queries from Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) our algorithm makes is 1+p⋅1p2b=1+2b1+p\cdot\frac{1}{p}2^{b}=1+2^{b}.

3 Removing the random oracle assumption

The construction presented so far uses a random oracle O\mathcal{O}, which is impossible to implement.Note that we cannot sample the values of O\mathcal{O} on-the-fly, because Wat\mathsf{Wat} and Detect\mathsf{Detect} need to agree on all of the used values. Often, as we also do later in Section 4, a random oracle can be replaced with a cryptographic pseudorandom function (PRF, defined in Section 2.1). However, the inefficiency of WatO\mathsf{Wat}^{\mathcal{O}} requires being careful about this switch.

A PRF with a security parameter λ\lambda requires memory and runtime \poly(λ)\poly(\lambda) and is guaranteed to be indistinguishable from a random oracle only to distinguishers that run in time \poly(λ)\poly(\lambda) as well. As WatO\mathsf{Wat}^{\mathcal{O}} runs in (expected) time 2b2^{b}, we must choose b=O(log⁡λ)b=O(\log\lambda) for the PRF to behave as a random oracle. This implies that the soundness is no longer \negl\negl, but is at least 1\poly(λ)\frac{1}{\poly(\lambda)}.

Pseudo-code for this simplified scheme is presented in Algorithms 1 and 2. We state the properties of this scheme in Theorem 3 without proof; the proofs of these properties were sketched in the preceding two sections.

For any λ,Model\lambda,\mathsf{Model} and b≤O(log⁡λ)b\leq O(\log\lambda), Algorithms 1 and 2 are a watermarking scheme W\mathcal{W} that is undetectable, (6λ)(6\lambda)-complete, and 2−b2^{-b}-weakly-sound. On expectation, Wat\sk\mathsf{Wat}_{\sk} makes 1+2b1+2^{b} calls to Model‾\overline{\mathsf{Model}} to generate each response.

This construction already demonstrates the importance of our completeness definition (Definition 7): Only trying to watermark outputs of high empirical entropy was crucial for this simple construction’s undetectability. As we will see in Section 5, only watermarking high empirical entropy outputs is in fact inherent to undetectable watermarking schemes.

Constructing Undetectable Watermarks

For ease of presentation and analysis, we describe our watermarking scheme as operating on text encoded as a binary string. That is, we assume that the token set is T={0,1}\mathcal{T}=\{0,1\}.

Note that this assumption is without loss of generality: We can easily convert a model MM with an arbitrary token set T\mathcal{T} into a model M′M^{\prime} with a binary token set. First, we encode each token in T\mathcal{T} as a distinct string in {0,1}log⁡∣T∣\{0,1\}^{\log|\mathcal{T}|}; note that every codeword has length at most log⁡∣T∣\log|\mathcal{T}|. For GPT-4, the number of tokens is \absolutevalueT=100,277\absolutevalue{\mathcal{T}}=100,277, and thus log⁡∣T∣≈17\log|\mathcal{T}|\approx 17 [Ope23]. Let EE denote this encoding function, and let pip_{i} be a distribution over T\mathcal{T} output by MM. We convert pip_{i} into a series of distributions pi,j′p^{\prime}_{i,j} for M′M^{\prime}, where pi,1′p^{\prime}_{i,1} is the distribution of the first bit of the codeword corresponding to a token sampled from pip_{i}. That is, pi,1′(0)=Pr⁡t←pi[E(t)1]p^{\prime}_{i,1}(0)=\Pr_{t\leftarrow p_{i}}[E(t)_{1}], where E(t)1E(t)_{1} denotes the first bit of E(t)E(t). Let bi,1b_{i,1} denote the bit sampled by M′M^{\prime} from pi,1′p^{\prime}_{i,1}. Each subsequent pi,j′p^{\prime}_{i,j} is then sampled according to the distribution of the jthj^{\text{th}} bit of the codeword corresponding to a token sampled from pip_{i}, conditioned on the previous bits being equal to bi,1,bi,2,…,bi,j−1b_{i,1},b_{i,2},\ldots,b_{i,j-1}. After M′M^{\prime} samples the last bit of the current token from pi,∣T∣′p^{\prime}_{i,|\mathcal{T}|}, it calls MM to obtain the distribution pi+1p_{i+1} for the next token.

Therefore, a watermarking scheme for binary alphabets can be used on models with token alphabets of arbitrary size using the above reduction. We note that the expected length of the encoding can be reduced by using a Huffman encoding of the token set instead of an arbitrary encoding.

2 Overview of the Construction

In Section 3, we saw a simple scheme that plants a watermark by sampling only texts for which an easily checkable predicate holds. In order to make this scheme more efficient, a natural idea is to sample tokens one at a time. If we don’t require undetectability, an easy way to do this is to use a {0,1}\{0,1\}-valued hash function hh and sample tokens xjx_{j} with preference for those satisfying h(xj)=1h(x_{j})=1. Given some text, we can determine whether a watermark is present by computing the hash of each token. In watermarked text, more tokens should hash to 1 than to 0; in un-watermarked text, there should be no bias. This is a classic idea in steganography, discussed in [HvAL09]. It is essentially the idea used in [KGW+23].

Unfortunately, this strategy significantly alters the output distribution, making it easily detectable: It prefers half of the words in the token set. As long as a biasing strategy yields a significant expected gap between the incidence of some predicate in watermarked text versus natural text, the resulting scheme should yield an observable watermark. Our objective is to plant a signal without noticeably changing the distribution of each token.

We first discuss a watermarking scheme that can only be used to generate a single output text of a predetermined maximum length LL, for an arbitrary prompt. The secret key shared by the watermarked model and the detection algorithm will be a sequence u⃗=u1,…,uL\vec{u}=u_{1},\dots,u_{L} of uniformly chosen real numbers in the range $.Eventhoughthisstateisindependentofthepromptthemodelwillreceive,weshowthatthissharedstateisenoughtoplantawatermarkinanysingleresponse.Fromtheperspectiveofauserwhodoesn’tknowthesecretkey. Even though this state is independent of the prompt the model will receive, we show that this shared state is enough to plant a watermark in any single response. From the perspective of a user who doesn’t know the secret key\vec{u}$, the distribution of outputs is not changed at all.

When generating a response, the watermarked model will use the secret key to decide on each output token. Consider the generation of the jj-th token in the response, after the previous tokens are already decided. Let pj(1)p_{j}(1) denote the probability, according to the real model, of this token being 11. The watermarked model outputs xj=1x_{j}=1 if uj≤pj(1)u_{j}\leq p_{j}(1) and xj=0x_{j}=0 otherwise. As uju_{j} was drawn uniformly from $,theprobabilitythatthewatermarkedmodeloutput, the probability that the watermarked model outputx_{j}=1isexactlyis exactlyp_{j}(1).Therefore,thedistributionofgeneratedtext(inasingleresponse)doesnotchangeatall.Nevertheless,wenextshowthatthedetectionalgorithmcancomparethegeneratedtexttothesharedsequence. Therefore, the distribution of generated text (in a single response) does not change at all. Nevertheless, we next show that the detection algorithm can compare the generated text to the shared sequence\vec{u}$, and deduce that the generated output was drawn from the watermarked model.

For each text bit xjx_{j}, the detection algorithm can compute a score

Given a string x=(x1,…,xL)x=(x_{1},\ldots,x_{L}), the detection algorithm sums the score of all text bits

Crucially, the detection algorithm does not need to know the distributions with which the model produces output bits. Since the detection algorithm does not have access to the prompt, it would not be able to compute those distributions.

We observe that the expected score is higher in watermarked text, as uju_{j} is correlated with the output bit xjx_{j}. In non-watermarked text, the value of uju_{j} is independent of the value of xjx_{j}. Therefore, s(xj,uj)s(x_{j},u_{j}) is simply an exponential random variable with mean 11:

For watermarked outputs, on the other hand,

We’ve shown that there’s a substantial gap between the expected scores of watermarked and natural text, as long as the text generation has high entropy. This should give us hope that this biasing strategy yields a reliable detector, but there are a few obstacles left on the way.

First, the expectation argument turns out to not be very useful because the variance of the score could be large. In Section 5 we discuss why this implies that we must consider empirical entropy instead of the entropy of the entire model. In Sections 4.3 and 4.4 we use empirical entropy to build effective distinguishers.

Second, the scheme described above is only indistinguishable for a single response, and that response must be shorter than the secret key. A natural idea is to use a psuedorandom function (refer to Section 2.1 for a definition) to determine the values uju_{j}, instead of drawing them all in advance. For example, by setting uj=F\sk(j)u_{j}=F_{\sk}(j) the length of any single response no longer has to be bounded. As F\skF_{\sk} is queried on each input jj at most once, the values of uju_{j} are pseudorandom and the distribution of a single watermarked output is computationally indistinguishable from the original distribution. The question becomes: Can we deal with multiple responses? One of our main contributions, and the most substantial difference from all prior work, is to answer this question in the affirmative.

Let r(i)r^{(i)} be a unique identifier assigned to each response. This might be a global counter or a random string (usually referred to as a nonce). To sample the jj-th token of the ii-th response we can use uj(i)=F\sk(r(i),j)u_{j}^{(i)}=F_{\sk}(r^{(i)},j). If all pairs (r(i),j)(r^{(i)},j) are unique, then the values of uj(i)u^{(i)}_{j} are pseudorandom. However, the detection algorithm needs to know r(i)r^{(i)} to compute the detection score. If r(i)r^{(i)} is a counter, then we would need to keep a global state to maintain it. Moreover, to use the detection algorithm we would need to enumerate over all possible counter values. If r(i)r^{(i)} is a long random string, no global state is needed, but the detection algorithm still needs to know r(i)r^{(i)}. While r(i)r^{(i)} must be recoverable by the detection algorithm, it cannot simply be written in the output text, as we might as well just append “WATERMARK!” to it instead (which would obviously change the distribution of outputs). Our solution is to use real randomness to generate the first few tokens of each output, keeping track of how much entropy we used in the process. Once this entropy passes some specified threshold, we use the high-entropy prefix as r(i)r^{(i)}. Since these prefixes have high enough entropy, all choices of r(i)r^{(i)} will be unique with all but negligible probability. The detection algorithm will test whether any prefix in the text, if used as r(i)r^{(i)}, will yield an unusually high score for the remainder of the text. The details of this construction are presented in Section 4.3.

In the above sketch the detector needs the entire output from the model to detect the watermark. We describe a modification of this scheme in Section 4.4 which is able to detect the watermark, even when it is given only an contiguous substring of the output with sufficiently high entropy. Essentially, this modification works the same except it “resets” the choice of r(i)r^{(i)} whenever enough new entropy is observed.

3 Constructing Undetectable Watermarks

Let \poly1(⋅),\poly2(⋅)\poly_{1}(\cdot),\poly_{2}(\cdot) be polynomials. Let F\sk:{0,1}\poly1(\secpar)→{0,1}\poly2(\secpar)F_{\sk}:\{0,1\}^{\poly_{1}(\secpar)}\to\{0,1\}^{\poly_{2}(\secpar)} be a PRF, where \sk∈{0,1}\secpar\sk\in\{0,1\}^{\secpar}. We wish to interpret the output of F\skF_{\sk} as a real number in $.Wedosobyletting. We do so by lettingzbetheintegerrepresentationoftheoutputandtakingbe the integer representation of the output and taking\frac{z}{2^{\poly_{2}(\secpar)}}.Weconsider. We consider\poly_{2}tobealargepolynomialandignorefloatingpointerrors.Inthebelowalgorithms,weallowto be a large polynomial and ignore floating point errors. In the below algorithms, we allowF_{\sk}totakestringsofvaryinglengthasinput;weassumethatto take strings of varying length as input; we assume that\poly_{1}(\cdot)ischosensuchthatthesestringsarenevertoolong,andiftheyaretooshortwepadthem.InthissectionweassumethatthetokenalphabetisbinaryasdiscussedinSection4.1.Weletdonedenotethebinaryencodingofthe“done"token,andwewriteis chosen such that these strings are never too long, and if they are too short we pad them. In this section we assume that the token alphabet is binary as discussed in Section 4.1. We let done denote the binary encoding of the “done" token, and we write\texttt{done}\in(x_{1},\ldots,x_{k})ifandonlyifthedecodingofif and only if the decoding of(x_{1},\ldots,x_{k})$ in the original token alphabet includes done.

In this section we let W=(Setup,Wat,Detect)\mathcal{W}=(\mathsf{Setup},\mathsf{Wat},\mathsf{Detect}) denote the watermarking scheme where Wat\mathsf{Wat} is Algorithm 3, Detect\mathsf{Detect} is Algorithm 4, and Setup(1\secpar)\mathsf{Setup}(1^{\secpar}) samples \sk←{0,1}\secpar\sk\leftarrow\{0,1\}^{\secpar}. This scheme is outlined above in Section 4.2.

Let WatO\mathsf{Wat}^{\mathcal{O}} and DetectO\mathsf{Detect}^{\mathcal{O}} be the same algorithms as Wat\sk\mathsf{Wat}_{\sk} and Detect\sk\mathsf{Detect}_{\sk}, except that they use a random oracle O\mathcal{O} instead of F\skF_{\sk}. Since both algorithms only make black-box use of F\skF_{\sk}, these are well-defined. Denote this random oracle scheme by WO\mathcal{W}^{\mathcal{O}} (which does not need a Setup\mathsf{Setup} algorithm). Undetectability, b(L)b(L)-(substring-)completeness, and soundness are defined identically for WO\mathcal{W}^{\mathcal{O}}, except we replace the probabilities over \sk←Setup(1\secpar)\sk\leftarrow\mathsf{Setup}(1^{\secpar}) with probabilities over O←{f:{0,1}\poly1(\secpar)→{0,1}\poly2(\secpar)}\mathcal{O}\leftarrow\{f:\{0,1\}^{\poly_{1}(\secpar)}\to\{0,1\}^{\poly_{2}(\secpar)}\}. Note that in the definition of undetectability for WO\mathcal{W}^{\mathcal{O}}, the distinguisher will not be given access to the random oracle O\mathcal{O} (since the distinguisher for W\mathcal{W} is not given access to F\skF_{\sk}).

The watermarking scheme W\mathcal{W} is undetectable/b(L)b(L)-(substring-)complete/sound if and only if WO\mathcal{W}^{\mathcal{O}} is undetectable/b(L)b(L)-(substring-)complete/sound, assuming the security of the PRF used in W\mathcal{W}.

The security of the PRF says that black-box access to F\skF_{\sk} (for random \sk\sk) is indistinguishable from black-box access to a random O\mathcal{O}, for any polynomial-time distinguisher. Observe that Algorithms 3 and 4 both only make black-box use of F\skF_{\sk}. Therefore it is possible to efficiently test, using only black-box access to F\skF_{\sk}, whether a given text/prompt/distinguisher violates soundness/b(L)b(L)-(substring-)completeness/undetectability. The security of the PRF then implies that the advantage of any given text/prompt/distinguisher is at most \negl\negl different between W\mathcal{W} and WO\mathcal{W}^{\mathcal{O}}. ∎

Let E1,…,EnE_{1},\dots,E_{n} be i.i.d. exponential random variables with rate 1, and let E‾:=∑i=1nEi\overline{E}:=\sum_{i=1}^{n}E_{i} be their sum. Then for any τ>0\tau>0,

Pr⁡[E‾≥n+τn]≤(45)τ\Pr[\overline{E}\geq n+\sqrt{\tau n}]\leq\left(\frac{4}{5}\right)^{\sqrt{\tau}}, and

Pr⁡[E‾≤n−τn]≤e−τ/2\Pr[\overline{E}\leq n-\sqrt{\tau n}]\leq e^{-\tau/2}.

We start with part (a). By [Jan18, Theorem 5.1(i)],

If τ≥n\tau\geq n, then since 1+z≤2z1+z\leq 2^{z} for z≥1z\geq 1 we have

If τ≤n\tau\leq n, then using ez≥1+z+z2/2e^{z}\geq 1+z+z^{2}/2 for z≥0z\geq 0 we have

where we have also used the fact that (1+zn)n(1+\frac{z}{n})^{n} is monotonically increasing in nn.

We now turn to part (b). By [Jan18, Theorem 5.1(iii)],

If τ≥n\tau\geq n, the probability becomes 0. If τ<n\tau<n, then taking the natural logarithm the above becomes

where for 0<z<10<z<1 we have used the facts that ln⁡(1−z)z≤−22−z\frac{\ln(1-z)}{z}\leq\frac{-2}{2-z} and 22−z≥1+z2\frac{2}{2-z}\geq 1+\frac{z}{2}. ∎

W\mathcal{W} is a sound watermarking scheme.

Recall the definition of soundness in Definition 6. By Lemma 1 it suffices to show that for any text x=x1,…,xLx=x_{1},\dots,x_{L},

For i,j∈[L]i,j\in[L], define r(i)r^{(i)}, vj(i)v_{j}^{(i)} as in Algorithm 4 and let uj(i):=O(r(i),j)u_{j}^{(i)}:=\mathcal{O}(r^{(i)},j). Recall that vj(i)=xj⋅uj(i)+(1−xj)⋅(1−uj(i))v_{j}^{(i)}=x_{j}\cdot u_{j}^{(i)}+(1-x_{j})\cdot(1-u_{j}^{(i)}).

Since uj(i)u_{j}^{(i)} is independent from xjx_{j}, we have vj(i)∼U()v_{j}^{(i)}\sim U(). Therefore, Ej(i):=ln⁡(1/vj(i))E_{j}^{(i)}:=\ln(1/v_{j}^{(i)}) are independent exponential random variables with rate parameter 1. By Lemma 2,

By a union bound over all LL possible values of ii, the probability of Algorithm 4 returning \true\true is at most L⋅(4/5)λ=\neglL\cdot(4/5)^{\lambda}=\negl, completing the proof. ∎

W\mathcal{W} is a (4ln⁡2λL)\left(\frac{4}{\ln 2}\lambda\sqrt{L}\right)-complete watermarking scheme.

Recall the definition of completeness in Definition 7. By Lemma 1 it suffices to show that for every prompt,

where b(L)=4ln⁡2λLb(L)=\frac{4}{\ln 2}\lambda\sqrt{L}. In fact, we will prove something stronger: For every fixed x∈T⋆x\in\mathcal{T}^{\star} and prompt such that He(Model,\textscprompt,x)≥4ln⁡2λ\absolutevaluexH_{e}(\mathsf{Model},\textsc{prompt},x)\geq\frac{4}{\ln 2}\lambda\sqrt{\absolutevalue{x}}, if each bit xix_{i} of xx has empirical entropy Hei(Model,\textscprompt,x)≤λH_{e}^{i}(\mathsf{Model},\textsc{prompt},x)\leq\lambda,

Inequality 2 says that for any possible fixed output xx that has high empirical entropy (which isn’t too concentrated on any particular bit), conditioning on WatO\mathsf{Wat}^{\mathcal{O}} outputting it, it is likely to be detected as watermarked. Note that the probability here is over the choice of outputs of O\mathcal{O} and not over xx, which is fixed.

Observe that Inequality 2 is not falsifiable, so we cannot do the PRF switch (Lemma 1) with it. However, since each bit has at most a 2−λ2^{-\lambda} chance of having empirical entropy more than λ\lambda, Inequality 2 implies Inequality 1 via the law of total probability.

Denote by sjs_{j} the random variable ln⁡1vj\ln\frac{1}{v_{j}}, conditioned on WatO(\textscprompt)=x\mathsf{Wat}^{\mathcal{O}}(\textsc{prompt})=x, or equivalently, on the value of xjx_{j}. Recall that the variable E=ln⁡1uE=\ln\frac{1}{u} for u∼U()u\sim U() is exponentially distributed with rate 11. In particular, if xj=1x_{j}=1 the variable sjs_{j} is distributed the same as EE conditioned on u≤pj(1)u\leq p_{j}(1), or equivalently on E≥ln⁡1pj(1)E\geq\ln\frac{1}{p_{j}(1)}. By the memorylessness property of exponential distributions, hence, sjs_{j} is distributed as ln⁡1pj(1)+Ej\ln\frac{1}{p_{j}(1)}+E_{j}, where EjE_{j} is an exponentially distributed random variable with rate 11. Symmetrically, if xj=0x_{j}=0 the variable sjs_{j} is distributed as ln⁡1pj(0)+Ej\ln\frac{1}{p_{j}(0)}+E_{j}. We conclude that

W\mathcal{W} is an undetectable watermarking scheme.

Recall Definition 9, which says that a watermark is undetectable if no efficient adversary can distinguish between query access to the watermarked model and the original one. Consider any fixed history of responses x(1),…,x(t−1)x^{(1)},\dots,x^{(t-1)}, and suppose that the adversary submits prompt as the next query. We will show that

Since the adversary can only make \poly(λ)\poly(\lambda) queries, it follows that the entire interaction with WatO\mathsf{Wat}^{\mathcal{O}} is statistically indistinguishable from interaction with Model‾\overline{\mathsf{Model}}. Finally, we will obtain the theorem by invoking Lemma 1.

For k∈[t−1]k\in[t-1] and i∈[L(k)]i\in[L^{(k)}], we define

Note that qi(k)(z)q^{(k)}_{i}(z) is the probability that xi(t)=zx^{(t)}_{i}=z, given that xj(t)=xj(k)x^{(t)}_{j}=x^{(k)}_{j} for j∈[i−1]j\in[i-1]. We compute

4 Constructing Substring-Complete Watermarks

The detector presented in Section 4.3 receieves as an input the entire text output by Wat\sk\mathsf{Wat}_{\sk}. In this section we generalize the scheme into a substring-complete one, which is able to detect watermarks in any contiguous sequence of text with sufficiently high empirical entropy.

We use the same notation as in Section 4.3, except that now W\mathcal{W} refers to the scheme defined in Algorithms 5 and 6.

W\mathcal{W} is a sound watermarking scheme.

W\mathcal{W} is a (8ln⁡2λL)\left(\frac{8}{\ln 2}\lambda\sqrt{L}\right)-substring-complete watermarking scheme.

We argue that any substring with empirical entropy at least 8ln⁡2λL\frac{8}{\ln 2}\lambda\sqrt{L} must include the entirety of a pair of consecutive blocks r(a),r(a+1)r^{(a)},r^{(a+1)}. We then refer to the proof of Theorem 5 to argue that the bias planted in r(a+1)r^{(a+1)} with the seed r(a)r^{(a)} can be detected with overwhelming probability.

Recall the definition of completeness in Definition 7. By Lemma 1 it suffices to show that for every prompt,

where b(L)=8ln⁡2λLb(L)=\frac{8}{\ln 2}\lambda\sqrt{L}. We’ll show that for every fixed x∈T⋆x\in\mathcal{T}^{\star}, i,L∈[∣x∣]i,L\in[|x|], and prompt such that He[i:i+L](Model,\textscprompt,x)≥8ln⁡2λLH_{e}^{[i:i+L]}(\mathsf{Model},\textsc{prompt},x)\geq\frac{8}{\ln 2}\lambda\sqrt{L}, if each bit xjx_{j} of x[i:i+L]x[i:i+L] has empirical entropy Hej(Model,\textscprompt,x)≤λH_{e}^{j}(\mathsf{Model},\textsc{prompt},x)\leq\lambda,

Therefore, after r(a)r^{(a)} has been fixed, there is sufficient entropy in the remainder of our substring x[d+1:i+L]x[d+1:i+L] so that r(a+1)r^{(a+1)} will be contained entirely within it. Since r(a+1)r^{(a+1)} has empirical entropy at least 2ln⁡2λk−d\frac{2}{\ln 2}\lambda\sqrt{k-d}, we can now follow the analysis in the proof of Theorem 5 to conclude that this choice of c,d,kc,d,k in the detection algorithm results in an output of \true\true. ∎

W\mathcal{W} is an undetectable watermarking scheme.

Recall Definition 9, which says that a watermark is undetectable if no efficient adversary can distinguish between query access to the watermarked model and the original one. Let RW\mathcal{R}_{W} and RM\mathcal{R}_{M} be the distributions over the next block r(t)r^{(t)} under WatO\mathsf{Wat}^{\mathcal{O}} and Model‾\overline{\mathsf{Model}}, respectively.

For any fixed history of blocks r(1),…,r(t−1)r^{(1)},\dots,r^{(t-1)}, if

then RW=RM\mathcal{R}_{W}=\mathcal{R}_{M} and

Inductively, any \poly(λ)\poly(\lambda)-many blocks output by WatO\mathsf{Wat}^{\mathcal{O}} are at most \negl\negl-far in statistical distance from outputs of Model‾\overline{\mathsf{Model}}. Since only \poly(λ)\poly(\lambda) blocks can appear in the experiment, the entire interaction with WatO\mathsf{Wat}^{\mathcal{O}} is statistically indistinguishable from interaction with Model‾\overline{\mathsf{Model}}. Finally, we will obtain the theorem by invoking Lemma 1.

Depending on whether tt is the first block in the response, we reason that RW=RM\mathcal{R}_{W}=\mathcal{R}_{M} differently:

If r(t)r^{(t)} is the first block in the response, then RW=RM\mathcal{R}_{W}=\mathcal{R}_{M} because WatO\mathsf{Wat}^{\mathcal{O}} and Model‾\overline{\mathsf{Model}} behave identically until after the first block is sampled.

If r(t)r^{(t)} is not the first block in the response (i.e., r(t−1)r^{(t-1)} is a part of the same response as r(t)r^{(t)}), then RW=RM\mathcal{R}_{W}=\mathcal{R}_{M} because r(t−1)∉{r(1),…,r(t−2)}r^{(t-1)}\not\in\{r^{(1)},\dots,r^{(t-2)}\} and therefore WatO\mathsf{Wat}^{\mathcal{O}} uses fresh randomness to generate r(t)r^{(t)}. (Note that r(t−1)≠⊥r^{(t-1)}\neq\bot, since the subsequent block r(t)r^{(t)} is a part of the same response.)

In either case, once we know that RW=RM\mathcal{R}_{W}=\mathcal{R}_{M}, Inequality 5 follows from the exact same argument as in the proof of Theorem 6. ∎

Necessity of Assumptions

In this section we show that the assumptions we use for our construction are necessary. Informally, the two main statements we prove in this section are:

Undetectability is possible only against a computationally bounded adversary. That is, using a polynomial number of queries and exponential running time we can detect any nontrivial watermarking scheme. This is proven in Lemma 4.

Undetectability is impossible if outputs of low empirical entropy are watermarked: For any tt, if a non-negligible fraction of outputs with empirical entropy ≤t\leq t are watermarked then we can detect the watermark using exp⁡(t)\exp(t) queries and time. This is proven in Theorem 10.

To warm up, we first observe that there exist models that generate text with arbitrarily high entropy, and nevertheless in any undetectable watermark only a negligible fraction of outputs can be watermarked. Hence, the natural attempt to only consider the model’s entropy is insufficient.

For every λ,b,ε>0\lambda,b,\varepsilon>0 there exists a prompt-independent model Model\mathsf{Model} such that H(Model‾(∅))≥bH(\overline{\mathsf{Model}}(\emptyset))\geq b, the maximum length of an output of Model‾\overline{\mathsf{Model}} is 1εb\frac{1}{\varepsilon}b, and the following holds. If W\mathcal{W} is any undetectable and sound watermarking scheme for Model\mathsf{Model}, then

We define the output distribution of Model‾\overline{\mathsf{Model}} as follows. With probability 1−ε1-\varepsilon, Model‾\overline{\mathsf{Model}} outputs done. Otherwise, it outputs a uniformly random binary string of length 1εb\frac{1}{\varepsilon}b. The entropy of Model‾\overline{\mathsf{Model}} is larger than ε⋅1εb>b\varepsilon\cdot\frac{1}{\varepsilon}b>b.

Due to soundness, with high probability (done)(\texttt{done}) is not detected as watermarked, that is

On the other hand, due to undetectability, Wat\sk(∅)\mathsf{Wat}_{\sk}(\emptyset) must output (done)(\texttt{done}) with probability (1−ε)±\negl(1-\varepsilon)\pm\negl, so the statement of the lemma holds. ∎

Next, we show that computational assumptions are necessary for undetectability of watermarks. That is, while we can construct watermarks where the output distributions of Wat\sk\mathsf{Wat}_{\sk} and of Model‾\overline{\mathsf{Model}} are indistinguishable to any efficient distinguisher, those distributions must not be identical and thus a distinguisher with unbounded running time is able to distinguish between them. We prove a strong version of this statement: we show that for every model and every watermarking scheme it is possible to statistically distinguish Model‾\overline{\mathsf{Model}} from Wat\sk\mathsf{Wat}_{\sk}, using a polynomial number of queries from any prompt that produces watermarked outputs with non-negligible probability.

Let Model\mathsf{Model} be a model and W\mathcal{W} a watermarking scheme for it that is sound. Let KK be an upper bound on the size (in bits) of any possible secret key \sk\sk for W\mathcal{W}. Let ε>1\poly(λ)\varepsilon>\frac{1}{\poly(\lambda)} and let prompt be a prompt for which

Then, for randomly chosen \sk←Setup(1\secpar)\sk\leftarrow\mathsf{Setup}(1^{\secpar}), it is possible to distinguish between Model‾\overline{\mathsf{Model}} and Wat\sk\mathsf{Wat}_{\sk} with probability at least 12ε\frac{1}{2}\varepsilon, using \poly(Kε)\poly\left(\frac{K}{\varepsilon}\right) queries and exp⁡(K)\exp(K) running time.

As W\mathcal{W} is sound, we in particular have that a random output is unlikely to be detected as watermarked,

Let’s call this property sound on average. As soundness on average and the completeness assumption are distributional, we may assume that Detect\sk\mathsf{Detect}_{\sk} is deterministic by Yao’s minimax principle, while maintaining both properties.This means that we can always replace Detect\sk\mathsf{Detect}_{\sk} with a deterministic algorithm that still has those two properties. This is done by fixing the randomness used by Detect\sk\mathsf{Detect}_{\sk}. Therefore, for every possible secret key \sk\sk there exists a subset W\skW_{\sk} of possible outputs such that Detect\sk(x)=\true\mathsf{Detect}_{\sk}(x)=\true if and only if x∈W\skx\in W_{\sk}.

As W\mathcal{W} is sound on average, we have that

In particular, due to both assumptions and Markov’s inequality, with probability at least 1−12ε1-\frac{1}{2}\varepsilon the following hold for the drawn secret key \sk\sk:

Pr⁡x←Model‾(\textscprompt)[x∈W\sk]<12ε2\Pr_{x\leftarrow\overline{\mathsf{Model}}(\textsc{prompt})}\left[x\in W_{\sk}\right]<\frac{1}{2}\varepsilon^{2}.

Pr⁡x←Wat\sk(\textscprompt)[x∈W\sk]>ε2\Pr_{x\leftarrow\mathsf{Wat}_{\sk}(\textsc{prompt})}\left[x\in W_{\sk}\right]>\varepsilon^{2}.

Let O\mathcal{O} be any distribution of strings, and WW any set of strings. Let SS be set of 10ε2K\frac{10}{\varepsilon^{2}}K independent strings drawn from O\mathcal{O}. A Chernoff bound yields that

Given access to two distributions O1,O2\mathcal{O}_{1},\mathcal{O}_{2}, we can draw 10ε2K\frac{10}{\varepsilon^{2}}K samples from each, denote them by S1,S2S_{1},S_{2} respectively, and then compute for every possible key kk the quantities ∣S1∩Wk∣∣S1∣\frac{|S_{1}\cap W_{k}|}{|S_{1}|} and ∣S2∩Wk∣∣S2∣\frac{|S_{2}\cap W_{k}|}{|S_{2}|}. Due to the Chernoff bound above and to a simple union bound, with probability at least 1−2⋅1.5−K1-2\cdot 1.5^{-K}, those quantities approximate up to ±14ε2\pm\frac{1}{4}\varepsilon^{2} the probabilities Pr⁡x←Oj[x∈Wk]\Pr_{x\leftarrow\mathcal{O}_{j}}\left[x\in W_{k}\right] for every choice of possible key kk and j∈{1,2}j\in\{1,2\}. In that case, if O1=O2=Model‾\mathcal{O}_{1}=\mathcal{O}_{2}=\overline{\mathsf{Model}} there will not exist any kk for which ∣S1∩Wk∣∣S1∣<34ε2\frac{|S_{1}\cap W_{k}|}{|S_{1}|}<\frac{3}{4}\varepsilon^{2} and ∣S2∩Wk∣∣S1∣>34ε2\frac{|S_{2}\cap W_{k}|}{|S_{1}|}>\frac{3}{4}\varepsilon^{2}, but if O1=Model‾\mathcal{O}_{1}=\overline{\mathsf{Model}} and O2=Wat\sk\mathcal{O}_{2}=\mathsf{Wat}_{\sk}, there would. Thus, we can distinguish between those two cases by making 20ε2K\frac{20}{\varepsilon^{2}}K queries and enumerating over all 2K2^{K} possible keys. ∎

An important remark about Lemma 4 is that it requires the size of the secret key to be bounded (with respect to the number of queries the distinguisher makes). If we wanted the distributions to be indistinguishable only to a much weaker distinguisher that is only allowed to sample each distribution once, or a bounded number of times, then we could achieve statistically identical distributions. This can be achieved by the construction presented in Section 4, if the PRF is replaced with a long secret key containing many random values that will each be used exactly once.

Finally, we show that any sound watermarking scheme that successfully watermarks outputs with empirical entropy smaller than tt, is detectable with exp⁡(t)\exp(t) queries and time. This means that any watermarking scheme can only work for outputs with empirical entropy that is high enough with respect to the time the distinguisher is allowed to spend.

Let Model\mathsf{Model} be a model and W\mathcal{W} a watermarking scheme for it that is sound with respect to a security parameter λ\lambda. Let tt be a parameter, and prompt a prompt for which

Then, it is possible to distinguish between the distributions Wat\sk\mathsf{Wat}_{\sk} and Model‾\overline{\mathsf{Model}} with O(exp⁡(t)⋅\poly(λ))O\left(\exp\left(t\right)\cdot\poly(\lambda)\right) queries and time, with a non-negligble probability.

By making O(exp⁡(t)⋅\poly(λ))O\left(\exp\left(t\right)\cdot\poly(\lambda)\right) queries to a distribution O\mathcal{O} we may approximate with accuracy ±10−λ\pm 10^{-\lambda} the probability in the distribution O\mathcal{O} of every output xx that has empirical entropy ≤t\leq t. Note that there are at most 2t2^{t} such outputs. By Lemma 4 and the assumption, there is a statistical difference between the distributions Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) and Wat\sk(\textscprompt)\mathsf{Wat}_{\sk}(\textsc{prompt}), even when we condition on the output being of empirical entropy ≤t\leq t. Hence, approximating both distributions on all such outputs is enough to distinguish between them. Note that unlike in the proof of Lemma 4, we are now not enumerating over all possible keys (that may be longer than tt or λ\lambda), we simply approximate both distributions and compute the statistical difference between them. ∎

Removing Watermarks

A natural question is how robust an undetectable watermarking scheme can be to active attempts to remove it. While we would ideally like to have an undetectable watermarking scheme that is robust to any efficient adversary attempting to remove a watermark, there are both practical and theoretical barriers to achieving this property. In Section 6.1 we first describe several attacks that work well at removing watermarks in practice. Then in Section 6.2 we present an (expensive) attack that provably removes a watermark from any undetectable scheme. We conclude that no undetectable watermarking scheme can be completely unremovable. Still, it might require significantly more resources for a user to generate unwatermarked text from the model.

We highlight some relevant practical attacks, described for an attacker wishing to generate an unwatermarked response to a prompt prompt. [KGW+23] gives a nice overview of practical attacks removing watermarks, including a few of those mentioned here.

In the “emoji attack,” the attacker asks the model to output a response to prompt with an emoji inserted between every pair of words.https://twitter.com/goodside/status/1610682909647671306 The attacker then removes the emojis to obtain the desired response. This attack removes any watermark that relies on the detector seeing consecutive sequences of tokens, including ours as well as those of [KGW+23] and [Aar22]. In general this attack may not preserve the output distribution, but any provable robustness guarantee for contiguous-text watermarks would have to rest on the dubious assumption that it doesn’t.

Translation attack.

The attacker can ask the model to write in a different language, and then translate the response to their language of choice. Depending on the fluency of the model in the other language, and the quality of the translation tool, this attack may significantly degrade the quality of text.

Paraphrasing and substitution attacks.

The attacker obtains a response from the model. In the substitution attack, the attacker replaces some words with their synonyms. In the paraphrasing attack, the attacker paraphrases the text either manually or using a model as in [KSK+23] or the span replacement attack of [KGW+23]. Depending on how many words are changed, these attacks might remove the watermark from our scheme and those of [KGW+23, Aar22]. Of course, changing more of the text also increases the risk of degrading its quality.

Post-hoc attacks.

For post-hoc detection schemes, there are two simple attacks that are empirically quite effective at evading detection. First, current LLMs are so powerful that they are often capable of simply evading detection themselves if you ask them to: See, for instance, this Reddit post.https://www.reddit.com/r/ChatGPT/comments/11pqmqm/you_can_ask_chat_gpt_to_write_a_text_than_alter/. Second, in some models, e.g. OpenAI’s “Playground”, one can change model parameters. By increasing the temperature, frequency penalty, and presence penalty, one can often produce text that evades post-hoc detection.

2 Removing any Undetectable Watermark

In this section, we describe an attack that removes a watermark from any undetectable watermarking scheme, assuming that the model is “prefix-specifiable.” The attack is simple: Just sample tokens from the watermarked model one at a time.

We say that a model is prefix-specifiable if the user can specify a prefix of the model’s response. More formally, we require that for any prompt and text x1,…,xkx_{1},\dots,x_{k}, the user can efficiently compute a new prompt \textscprompt′\textsc{prompt}^{\prime} such that Model‾(\textscprompt′)\overline{\mathsf{Model}}(\textsc{prompt}^{\prime}) is distributed identically to Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) conditioned on the response’s prefix matching (x1,…,xk)(x_{1},\ldots,x_{k}). This property is also assumed in the definition of a language model in [KGW+23].

Any language model according to Definitions 1 and 2 can be given a prefix-specifiable interface, but real-world user interfaces may or may not allow it. For instance, ChatGPT does not allow the user to specify prefixes of the response, but the OpenAI Playground allows the user to submit text under the “Assistant” role which the model will use as a prefix for its next response. We do not know for certain if the resulting distribution is actually identical to the model’s response conditioned on the given prefix.

We note that a user can always attempt to “trick” a model into being prefix-specifiable: Simply include in the prompt a request to start the response with the given prefix. We also note that when we are defining a model, we can always design it to be “prefix-specifiable” by forcing it to follow such requests. In particular, a watermarking scheme that works for every model would need to work also for prefix-specifiable models.

Let W=(Setup,Wat\sk,Detect\sk)\mathcal{W}=(\mathsf{Setup},\mathsf{Wat}_{\sk},\mathsf{Detect}_{\sk}) be any undetectable watermarking scheme. Assume that the underlying model Model‾\overline{\mathsf{Model}} is prefix-specifiable. Then there exists an efficient algorithm \adv\adv making queries to Wat\sk\mathsf{Wat}_{\sk} such that, for any prompt and a random \sk←Setup(\secparam)\sk\leftarrow\mathsf{Setup}(\secparam), the distributions \advWat\sk(\textscprompt)\adv^{\mathsf{Wat}_{\sk}}(\textsc{prompt}) and Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}) are \negl\negl-close in statistical distance. The number of queries made by \adv\adv to Wat\sk\mathsf{Wat}_{\sk} is exactly the length of text output by \adv\adv.

The attacker generates an unwatermarked response to prompt as follows. It lets y1y_{1} be the first token of Wat\sk(\textscprompt)\mathsf{Wat}_{\sk}(\textsc{prompt}). It then lets y2y_{2} be the first token of Wat\sk(\textscprompt,y1)\mathsf{Wat}_{\sk}(\textsc{prompt},y_{1}), and so on, in general computing yjy_{j} as the first token in Wat\sk(\textscprompt,y1,…,yj−1)\mathsf{Wat}_{\sk}(\textsc{prompt},y_{1},\ldots,y_{j-1}) until yj=doney_{j}=\texttt{done}.

Let Y=(Y1,…,YLY)Y=(Y_{1},\ldots,Y_{L_{Y}}) be random variables denoting the attacker’s output. Let X=(X1,…,XLX)X=(X_{1},\ldots,X_{L_{X}}) be random variables denoting the output of Model‾(\textscprompt)\overline{\mathsf{Model}}(\textsc{prompt}); note that LYL_{Y} and LXL_{X} are random variables here.

We argue that for each ii, Δ((Yi ∣ Yj=yj ∀j<i),(Xi ∣ Xj=yj∀j<i))≤\negl\Delta((Y_{i}\ |\ Y_{j}=y_{j}\ \forall j<i),(X_{i}\ |\ X_{j}=y_{j}\forall j<i))\leq\negl. Suppose for the sake of contradiction that the total variation distance between these distributions for some ii is at least 1\poly(\secpar)\frac{1}{\poly(\secpar)} for some polynomial \poly\poly. A distinguisher trying to determine whether it has oracle access to Model‾\overline{\mathsf{Model}} or Wat\sk\mathsf{Wat}_{\sk} can make O(\poly(∣T∣)⋅\secpar)O(\poly(|\mathcal{T}|)\cdot\secpar) queries to the oracle with input \textscprompt,(x1,…,xi−1)\textsc{prompt},(x_{1},\dots,x_{i-1}), and approximate the distribution of the first token in the response up to additive error ±10−\secpar\pm 10^{-\secpar} in total variation distance. Since 10−\secpar<<1/\poly(λ)10^{-\secpar}<<1/\poly(\lambda), this contradicts the undetectability of Wat\sk\mathsf{Wat}_{\sk}.

This tells us that for any partial response (x1,…,xi)(x_{1},\ldots,x_{i}) to prompt, the distribution of the next token must have \negl\negl total variation distance from that of the unwatermarked model. Therefore, the entire response produced by this attack using the watermarked model must be have negligible total variation distance from the unwatermarked model. ∎

By soundness, the watermark cannot be detected in the output of \adv\adv with non-negligible probability. Therefore, this attack succeeds in removing the watermark.

Fortunately, for reasonable text sizes this attack is probably impractical. For instance, while generating an 8,0008,000-token response from GPT-4 currently costs \frac{\0.06}{1000}\times 8000=\0.480.48, generating the same text using the above attack would cost \0.48+\frac{\0.03}{1000}\times 8000\times 7999/2=\960.36.(CurrentGPT−4pricingis. (Current GPT-4 pricing is\0.030.03 per 1000 prompt tokens and \0.06$ per 1000 sampled tokens.) Still, it shows that we cannot hope to achieve an overly sweeping definition of completeness/unremovability; it cannot allow an adversary powerful enough to run this attack.

Open Problems

Section 6 implies that undetectable watermarking schemes cannot be made “unremovable” in a general sense. Nevertheless, it is intriguing to find the most general sense in which undetectable watermarks can be made robust to removal attempts. For example, our construction of substring-complete watermarks guarantees detection as long as a consecutive substring of the output with high enough empirical entropy remains intact. Can this property be generalized to non-consecutive subsets of the output? Are there larger classes of removal techniques against which undetectable watermarks can be made robust?

Quantitatively, our main schemes in Section 4 might not achieve an optimal completeness parameter. The simplified scheme we present in Section 3 achieves completeness with a parameter that only depends on λ\lambda, but not soundness or worst-case polynomial runtime. Our full construction in Section 5, on the other hand, achieves all required properties yet has a possibly non-optimal Θ(λL)\Theta\left(\lambda\sqrt{L}\right) completeness parameter.

Can we close this gap, either by improving our scheme to require less entropy for detection, or by showing a stronger lower bound for schemes that are sound (or efficient)?

Acknowledgments

This research was supported in part by NSF Grants CCF-2107187, CCF-1763970, and CCF-2212233, by JPMorgan Chase & Co, by LexisNexis Risk Solutions, and by the Algorand Centres of Excellence programme managed by Algorand Foundation. Any opinions, findings, and conclusions or recommendations expressed in this material are solely those of the authors.

References