Robust Distortion-free Watermarks for Language Models

Rohith Kuditipudi, John Thickstun, Tatsunori Hashimoto, Percy Liang

Introduction

The ability of language models to mass produce human-like text creates an acute, renewed emphasis on the importance of provenance of generated content. For example, the website StackOverflow has banned users from posting answers using OpenAI’s ChatGPT model to mitigate the spread of misinformation on the platform . A reliable forensic tool for attributing text to a particular language model would empower individuals—such as platform moderators and teachers—to enact and enforce policies on language model usage; it would also better enable model providers to track the (mis)use of their models, e.g., to scrub synthetic text from the training data of future language models.

To achieve provenance, a watermark is a signal embedded within some generated content—in our case, text from a language model—that encodes the source of the content. We consider a setting where a (untrusted) third party user queries a language model (LM) by sending prompts to a trusted provider (Figure 1): the LM provider generates text from their language model with a watermark so that a detector may later identify the source of the text if the user publishes it. The ideal watermark should satisfy at least the following three desiderata:

distortion-free—the watermark should preserve the original text distribution;

agnostic—it should be detectable without the language model and/or prompt;

robust—it should withstand perturbations of the watermarked text.

Existing watermarks either distort the model’s sampling distribution, thus altering the API functionality , or are not robust to editing or cropping the text . Meanwhile, classical steganographic techniques for covertly encoding messages within samples of text from a language model are neither agnostic nor robust . We develop the first watermarks for attributing text to a language model that achieve all three desiderata.

Our methodology consists of two components, which the LM provider and detector respectively use to execute the two steps of the protocol in Figure 1 under their control: a generate\mathtt{generate} method that deterministically maps a sequence ξ\xi of random numbers encoded by a (secret) watermark key Whether the watermark key is secret or not (e.g., if the LM provider publishes the key to allow anyone to detect watermarked text) is an implementation choice that does not affect the main parts of our analysis. —which we call the watermark key sequence—to a sample from the language model, and a detect\mathtt{detect} method that aligns a putative watermarked text with the watermark key sequence using the shared key. Informally, our watermarks are distortion-free in the sense that—marginalizing over the watermark key sequence—each call to generate\mathtt{generate} is equal in distribution to a sample from the original language model, i.e., P(text)=∫ξ1 ⁣{text=generate(ξ,prompt)}dν(ξ)P(\textbf{text})=\int_{\xi}\mathbf{1}\!\left\{\textbf{text}=\mathtt{generate}(\xi,\textbf{prompt})\right\}d\nu(\xi) is equal to the original language model’s sampling distribution.

The challenge of detecting watermarked text is that the detector cannot simply recompute generate\mathtt{generate} and compare its output against the text since they do not necessarily know the prompt which produced the text: in practice, users often crop the prompt when publishing text from a language model. Our watermarks are agnostic in the sense that they are easily detectable with a suitable model-agnostic and prompt-agnostic test statistic ϕ\phi such that ϕ(generate(ξ,prompt),ξ)≪ϕ(text,ξ)\phi(\mathtt{generate}(\xi,\textbf{prompt}),\xi)\ll\phi(\textbf{text},\xi) for any text that is independent of the watermark key sequence. The idea here is that the detector may use ϕ\phi within detect\mathtt{detect} to compute a pp-value with respect to the null hypothesis that the text is independent of the watermark key sequence, i.e., that the text is not watermarked.

To ensure detect\mathtt{detect} is robust to edits of the watermarked text, the core idea underpinning the design of each test statistic ϕ\phi is to leverage techniques for robust sequence alignment to align a putative watermarked text with the watermark key sequence; we quantify the quality of the alignment using an “alignment cost” specific to each watermark. The sequence alignment procedure ensures the watermark is detectable from even a small, corrupted block of watermarked text planted within some other larger text. Of course, a sufficiently motivated and/or sophisticated user can still evade detection by simply rewriting the text from scratch themselves (or, using another language model to generate the text); the point of a robust watermark is simply that the amount of effort and/or resources a user requires to produce text that evades watermark detection should be commensurate to what they would have expended had they not had access to the watermarked language model in the first place.

Whereas generate\mathtt{generate} is a deterministic function, if our watermark produced the same text every time for each prompt it would not be very useful. We resolve this limitation by designing a wrapper around generate\mathtt{generate} that calls generate\mathtt{generate} using a randomly chosen subsequence of ξ\xi instead of generating tokens from the same starting point each time. For the same reasons that detect\mathtt{detect} is robust to editing and cropping watermarked text, calling generate\mathtt{generate} in this fashion does not affect watermark detectability. In practice, the statistical power of our watermarks improves exponentially with respect to the length of the putative watermarked text and diminishes only linearly with the length of the random number sequence; thus, by increasing the length of the random number sequence, we can reduce the probability of reusing the same random subsequence while still ensuring our watermark has good statistical power (i.e., that it yields low pp-values for watermarked text).

To remark briefly on the work most closely related to ours, we contrast the distortion-free property of our watermarks with the hashing-based watermarks of Kirchenbauer et al. and Aaronson that bias the distribution of watermarked text towards certain kk-grams by hashing a sliding window of the previous k−1k-1 tokens to determine the next token pseudorandomly. We give examples of prompts (e.g., “Give me a list of 20 movies.”) for which the bias due to hashing is clearly noticeable in our experiments. Christ et al. propose a variation of hashing in which the window size changes based on the entropy of the generated tokens to avoid hash collisions with high probability. Their motivation is similar to ours in that they focus on preserving the original text distribution; however, like Kirchenbauer et al. and Aaronson , using larger window sizes hurts robustness as an adversary can break the watermark by replacing a single token in each window. Our watermark is not only distortion-free but also robust to substantial corruption of the text, which is crucial in practice. We defer a more thorough discussion of related work to the next section (Section 1.1).

We describe the details of our methodology in Section 2, wherein we give two instantiations of watermarks—using inverse transform sampling and exponential minimum sampling—and provide analyses of their statistical power. We experimentally validate the power and robustness of our watermarks using the OPT-1.3B, LLaMA-7B and Alpaca-7B language models in Section 3. Across all models, we find the second instantiation using exponential minimum sampling to be the most powerful. For both the OPT-1.3B and LLaMA-7B models, using this watermark we can reliably detect watermarked text (p≤0.01p\leq 0.01) from 3535 tokens even after corrupting between 4040-5050% of the tokens via random edits (i.e., substitutions, insertions or deletions); the watermark also remains detectable from 5050 tokens even after paraphrasing the text by translating to French/Russian and back. For the Alpaca-7B model, we conduct a case study on the feasibility of watermarking responses to typical user instructions. Due to the lower entropy of the responses, detection is more difficult: around 25%25\% of the responses—whose median length is around 100100 tokens—are detectable with p≤0.01p\leq 0.01, and the watermark is also less robust to paraphrasing. We release code for implementing the watermark and reproducing the experiments in this paper, as well as additional supplementary material including an in-browser demo of the watermark detectorFor assets and supplemental material, see: https://github.com/jthickstun/watermark..

Text watermarking is a special case of linguistic steganography, in that the goal is to convey a hidden message—the watermark—within a passage of text. Existing approaches to linguistic steganography fall under two broad categories: edit-based methods that modify a pre-existing text, and generative methods that construct a distribution over cover text . Crucially, in contrast to steganography, the literature on digital watermarking has historically foregrounded robustness to corruption as a key attribute of a good watermark . In this light, a text watermark should be able to withstand some perturbations of the text, thus precluding the direct application of many existing techniques for linguistic steganography .

Older work on text watermarking considers editing a pre-existing text to include a watermark ; for a survey of edit-based watermarks, see Kamaruddin et al. . In contrast, we are interested in generating watermarked text while preserving the distribution over the text from a language model. Work on generative watermarking is nascent, underwritten by recent advances in open-ended text generation . Pioneering work by Venugopal et al. proposed a generative watermark for the output of a machine translation system, biasing the system towards translations with particular features that can later be detected using a hypothesis test.

Also concurrent to our work, Christ et al. propose watermarking blocks of text from a language model by hashing each block to seed a sampler for the next block. Christ et al. vary their block sizes—which are analogous to the hyperparameter kk of Kirchenbauer et al. and Aaronson —as a function of the empirical entropy of the constituent tokens to avoid using the same seed twice with high probability. Their work is similar to ours in that they preserve the original text distribution; however, the resulting watermark is not robust since in order to mitigate the distortion induced by hashing the block sizes must be sufficiently large to avoid hash collisions with high probability over all blocks and—similar to Kirchenbauer et al. and Aaronson —replacing any token in the previous block breaks the watermark in the next block. Whereas Christ et al. —who do not run experiments—choose their block sizes to be sufficiently large to minimize distortion, Kirchenbauer et al. and Aaronson recommend choosing kk to be a small constant in practice, which ensures a moderate amount of robustness by introducing some distortion.

An alternative approach for detecting synthetic text is to learn a classifier between synthetic and human text . A key advantage of such methods over watermarking is that they do not require coordination with the original producer of the text (i.e., the LM provider); however, their effectiveness is distribution dependent and they do not provide a priori (distribution-free) guarantees on the significance level of detection (i.e., Type I errors).

Finally, we note that our setting is different from the literature on planting watermarks in the training data of machine learning models, e.g., to infer the model’s training set or otherwise influence the model’s output . Such watermarks are not distortion-free by design, since the point is to plant some learnable signal in the training data that influences the behavior of models which train on the watermarked data.

Methodology and theoretical analysis

Let V\mathcal{V} be a discrete set, i.e., the vocabulary, and let p∈V∗→Δ(V)p\in\mathcal{V}^{*}\to\Delta(\mathcal{V}) be an autoregressive language model which maps a string of arbitrary length to a distribution over the vocabulary, with p(⋅∣x)p(\cdot\mid x) denoting the distribution of the next token given the prefix x∈V∗x\in\mathcal{V}^{*}. Let Ξ\Xi denote the space in which lie the elements of the watermark key sequence. Recall the main protocol (Figure 1) which defines our problem setting:

The LM provider shares a random watermark key sequence ξ∈Ξ∗\xi\in\Xi^{*} with the detector;

The user sends a prompt x∈V∗x\in\mathcal{V}^{*} to the LM provider;

The LM provider generates text Y∈V∗Y\in\mathcal{V}^{*} by Y=generate(x,ξ)Y=\mathtt{generate}(x,\xi);

The user publishes text Y~∈V∗\widetilde{Y}\in\mathcal{V}^{*}, which may be either (i) (an edited version of) the generated text YY or (ii) text independent of YY (e.g., text that they wrote themselves);

The detector determines if Y~\widetilde{Y} is watermarked—i.e., if Y~\widetilde{Y} depends on the watermark key sequence—by computing a pp-value p^=detect(Y~,ξ)\widehat{p}=\mathtt{detect}(\widetilde{Y},\xi) with respect to the null hypothesis that Y~\widetilde{Y} is independent of ξ\xi (i.e., not watermarked).

We relate Definition 1 to our informal definition of distortion-free text in the introduction through the following simple lemma. Assuming the conditions of the lemma are met, the only material difference between an LM provider using generate\mathtt{generate} versus sampling directly from the language model is that the sequence ξ\xi is an input to the method rather than resampled i.i.d. within the method for each call. We treat the language model pp, the decoder Γ\Gamma, and generation length mm as internal parameters of the generate\mathtt{generate} method.

As n≥mn\geq m, we have {ξi}i=1m∼i.i.d.ν\{\xi_{i}\}_{i=1}^{m}\overset{\text{i.i.d.}}{\sim}\nu. The claim then follows immediately from applying Definition 1 to Line 1 of generate\mathtt{generate} for i∈[m]i\in[m]. ∎

This alignment-based detection strategy makes the watermark robust, since even if the user crops or otherwise corrupts YY, a single block of preserved watermarked text within some larger body of unwatermarked text will suffice to trigger a low pp-value from detect\mathtt{detect}. The actual form of the alignment cost will be specific to each watermark—in particular, it will depend on the nature of the decoder Γ\Gamma in generate\mathtt{generate}. Our most robust watermarks incorporate a soft notion of edit distance (i.e., Levenshtein distance) into the computation of the alignment cost via dynamic programming, with runtime scaling quadratically in the block size. Thus, letting mm be the length of the input text yy, nn be the length of the watermark key sequence ξ\xi, and kk be the block size, the cost of computing the test statistic is O(mnk2)O(mnk^{2}).

To illustrate how the decoder and the alignment cost fit together, we give a simple example for the toy setting of a binary vocabulary.

Example 1 (): Consider a binary vocabulary V={0,1}\mathcal{V}=\{0,1\}. To generate Y∈{0,1}∗Y\in\{0,1\}^{*} from the model, the LM provider shares {ξi}i=1n∼i.i.d.Unif()\{\xi_{i}\}_{i=1}^{n}\overset{\text{i.i.d.}}{\sim}\textup{Unif}() with the detector and let Yi=0Y_{i}=0 if ξi≤p(0∣Y:i−1)\xi_{i}\leq p(0\mid Y_{:i-1}) and Yi=1Y_{i}=1 otherwise. In particular, defining the decoder Γ\Gamma by

In the above example, the LM provider generates the same text each time from the watermark key sequence, which is not ideal in practice. One solution for avoiding reusing elements of the watermark key sequence across queries is to make generate\mathtt{generate} stateful, thus enabling the LM provider to generate a total of ⌊n/m⌋\lfloor n/m\rfloor independent watermarked text samples of mm tokens each from the language model. Instead, to avoid persisting state, we provide a randomized wrapper shift-generate\mathtt{shift\textup{-}generate} (Algorithm 4) around generate\mathtt{generate} and modify the watermarking protocol from the start of the section to allow the LM provider to call the shift-generate\mathtt{shift\textup{-}generate} instead of generate\mathtt{generate} in the second step of the protocol. The wrapper shift-generate\mathtt{shift\textup{-}generate} randomly shifts the watermark key sequence before passing the shifted sequence to generate\mathtt{generate}. Shifting the watermark key sequence does not affect the value of the test statistic in detect\mathtt{detect}, since to compute the test statistic the detector anyways searches over all subsequences of the watermark key sequence to find the best match for each block of text. There are nn possible shifts, each of which may produce a distinct text; while in principle these nn texts will correlate with each other due to sharing elements of the watermark key sequence, in practice we find the effects of these correlations are not noticeable. The so-called birthday paradox implies the LM provider can typically expect to call shift-generate\mathtt{shift\textup{-}generate} on the order of n1/2{n}^{1/2} times, each time generating a different text, before reusing the same offset twice.

2 Terminology: watermark strategies and watermark potential

Henceforth, we use the term watermarking strategy to refer to a concrete instantiation of the shift-generate\mathtt{shift\textup{-}generate}, generate\mathtt{generate} and detect\mathtt{detect} methods by specifying the internal parameters of both algorithms (i.e., the decoder Γ\Gamma, the test statistic ϕ\phi and the watermark key sequence distribution ν\nu). We give concrete watermarking strategies in the following sections (Sections 2.3 and 2.4). For each watermarking strategy, we show two main results: we prove the decoder is distortion-free and also obtain high probability upper bounds on the pp-values of watermarked text—as a function of the length of the text and the watermark key sequence. We emphasize that only the former result (i.e., that the decoder is distortion-free) is critical to the validity of our main claims; we intend the latter collection of results to provide intuition for when we would expect the detector to have sufficient power and to anticipate the forthcoming experimental results in Section 3. The strength of the pp-value upper bounds will depend on the observed token probabilities of (watermarked) text, through a quantity which we evocatively term the watermark potential.

Observe the watermark potential of text from a deterministic language model is always zero, whereas for a high-entropy model it will approach one. The degree to which it is possible for the detector to reliably distinguish watermarked text from unwatermarked text necessarily depends on the watermark potential of the LM provider’s language model. For example, if the language model is deterministic, then any distortion-free watermark will necessarily have zero statistical power. We formalize this intuition by establishing the following general lower bound on the detection accuracy of any watermarking strategy as a function of the watermark potential of the original language model. In particular, we lower bound the error of any classifier h:V∗×Ξ∗→{−1,+1}h:\mathcal{V}^{*}\times\Xi^{*}\to\{-1,+1\} that tries to distinguish watermarked (positive label) versus nonwatermarked text (negative label) given some watermark key ξ\xi (we make no assumption on the distribution of ξ\xi except that it is independent of unwatermarked text by definition). We defer the proof of Lemma 2.2 to Appendix A.

Let Yi′∼p(⋅∣Y:i−1′)Y_{i}^{\prime}\sim p(\cdot\mid Y_{:i-1}^{\prime}) for i∈[m]i\in[m]. Let Y=dY′Y\stackrel{{\scriptstyle d}}{{=}}Y^{\prime} and let ξ∈Ξ∗\xi\in\Xi^{*} be a random variable that is independent of Y′Y^{\prime}. Let h:V∗×Ξ∗→{−1,+1}h:\mathcal{V}^{*}\times\Xi^{*}\to\{-1,+1\} be a classifier. Let c>0c>0 and define the set Vc⊂Vm\mathcal{V}_{c}\subset\mathcal{V}^{m} by

Lemma 2.2 implies it is impossible to test between any watermarked and non-watermarked text (i.e., between YY versus Y′Y^{\prime}) that are equal in distribution (i.e., distortion-free) if the text typically has low watermark potential, irrespective of the design of the watermark key; in particular, the sum of the Type I and II error rates of hh will be close to one if the watermark potential is close to zero. The theorem is not tight: depending on the language model, its result may be vacuous for small values of cc (e.g., the constants which appear in our upper bounds) since only texts whose token likelihoods all exceed exp⁡(−c/2)\exp(-c/2) contribute to the lower bound. Also our upper bounds scale inverse exponentially with the square of the watermark potential, which will always be smaller than the watermark potential itself since the watermark potential is bounded between zero and one.

The point of the forthcoming pp-value upper bounds for the watermarking strategies in Sections 2.3 and 2.4 is to establish the existence of test statistics for each watermark such that the statistical power of the watermark improves exponentially with the length of the text and decays at most linearly with the length of the watermark key sequence. The test statistics we use to prove these upper bounds differ slightly from those we employ in our experiments: in the former case, we prioritize the simplicity of stating the bounds in terms of watermark potential, whereas in the latter case, we prioritize empirical performance.

3 Watermarking via inverse transform sampling

Inverse transform sampling is a general technique for sampling from a univariate distribution by taking the pushforward of a uniform random variable through its inverse cumulative distribution function (CDF). Crucially, the technique is valid irrespective of the ordering of the CDF, a property which we presently leverage to construct a watermarking strategy in which generate\mathtt{generate} is distortion-free and also detect\mathtt{detect} is agnostic. In particular, we implement generate\mathtt{generate} with a decoder that maps a sequence of uniform random variables and permutations to tokens using inverse transform sampling. To detect watermarked text, the detector correlates the sequence of permuted indices of the tokens in the text with the sequence of uniform random variables to detect watermarked text. Meanwhile, for any nonwatermarked text, the sequence of permuted token indices will be i.i.d. uniform irrespective of the text itself and thus not correlate with the sequence of uniform random variables.

Formally, with Π\Pi as the space of permutations over the vocabulary [N][N], for ξ=(u,π)∈×Π=:Ξ\xi=(u,\pi)\in\times\Pi=:\Xi and any distribution μ∈Δ([N])\mu\in\Delta([N]), define the decoder by

i.e., Γ(ξ,μ)\Gamma(\xi,\mu) is the token with the smallest index in the permutation π\pi such that CDF of μ\mu with respect to π\pi is at least uu. Generalizing the intuition from Example 3, we show this decoder is distortion-free in the following theorem.

Define Γ\Gamma by equation (1). Let π∈Π\pi\in\Pi be arbitrary and let U∼Unif()U\sim\textup{Unif}(), with ξ:=(U,π)\xi:=(U,\pi). Then Γ\Gamma is distortion-free with respect to ξ\xi.

As the width of this interval is exactly μ(y)\mu(y), the result follows immediately. ∎

i.e., the negative covariance (each UiU_{i} and η(πi(Yi))\eta(\pi_{i}(Y_{i})) both have expectation 1/21/2).

We exactly characterize in Lemma 2.3 the difference in the expected value of our alignment cost on some text assuming the text is watermarked (i.e., generated using the same key as the detector) versus not watermarked in terms of the watermark potential of the text (Definition 2). To state the result, we define the constant C0:=Var(η(Unif([N])))C_{0}:=\textup{Var}(\eta(\textup{Unif}([N]))), where we abuse notation slightly to temporarily treat η\eta as a pushforward map over distributions. Note that C0=Var(Unif())+oN(1)=1/12+oN(1)C_{0}=\textup{Var}(\textup{Unif}())+o_{N}(1)=1/12+o_{N}(1). We defer the proof of Lemma 2.3 to Appendix B.

Summing the result of Lemma 2.3 over i∈[m]i\in[m] implies for any j∈[n]j\in[n] that

Thus, we can upper bound the pp-value output by detect\mathtt{detect} in Lemma 2.4 using a standard concentration argument and taking a union bound over j∈[n]j\in[n]. We defer the proof of Lemma 2.4 to Appendix B. In fact, we actually prove a more general result for k≤mk\leq m wherein we allow Y~\widetilde{Y} to be a subsequence of YY which the user may choose adaptively. We defer this more general result to Appendix B as it is more cumbersome to state.

Lemma 2.4 implies that with high probability the value of the test statistic on watermarked text with the correct key will be lower than with a resampled key. In particular, ignoring discretization errors due to the finite number of resamples TT in detect\mathtt{detect}, the lemma implies watermarked samples with watermark potential bounded away from zero (i.e., if the language model is not effectively deterministic) will have exponentially small expected pp-values with respect to the length mm of the text. The bound grows only linearly with the length nn of the random number sequence, implying for moderately large mm (e.g., m=50m=50) an LM provider can generate plenty of distortion-free watermarked text (i.e., n=2Ω(m)n=2^{\Omega(m)} total tokens) while still enabling detection of the watermark from snippets of mm tokens (e.g., 5050 tokens typically amount to a couple sentences of text). Of course, recall the computational complexity of detection scales linearly with nn, which in practice may be a more relevant limitation than the statistical power of the watermark. Note that both detect\mathtt{detect} and the test statistic (Algorithm 3) are easily parallizeable.

We show in Lemma 2.5 an analogous result to Lemma 2.4 holds even if an adversary corrupts the original watermarked text by substituting tokens. To state the lemma, we introduce a quantity α~\widetilde{\alpha} which depends on both the corrupted and original watermarked text and accounts for the decrease in the expected value of the test statistic (which recall for the original text is equal up to a numerical constant to the watermark potential of the text) due to token substitutions. We defer the proof of Lemma 2.5 to Appendix B.

Lemma 2.5 implies that even if an adversary replaces the vast majority of tokens in a watermarked text, detection with low pp-values will still be possible so long as the remaining tokens have watermark potential bounded away from zero. In particular, the permuted indices of the original tokens will still positively correlate with the corresponding uniform random variables from the watermark key sequence, while those of the substituted tokens will exhibit a small negative correlation scaling as O(1/N)O(1/N).

To handle insertions and deletions, we can robustify our test statistic by incorporating a soft notion of edit distance into our original alignment cost. The parameter γ\gamma in Definition 3 assigns a cost to each insertion and deletion operation when aligning the tokens yy with the sequence ξ\xi, while the base alignment cost d0d_{0} defines the quality of the alignment via a cost function over substitutions. In practice, we drop the minimizations over y′∈Vy^{\prime}\in\mathcal{V} and ξ′∈Ξ\xi^{\prime}\in\Xi in the second and third cases respectively of the definition; we include them here to make our subsequent theoretical analysis cleaner.

with dγ(y,(u,π)):=γ⋅len(y)d_{\gamma}(y,(u,\pi)):=\gamma\cdot\mathtt{len}(y) if ξ\xi is empty and vice versa (as base cases). For y∈V∗y\in\mathcal{V}^{*} (resp., ξ∈Ξ∗\xi\in\Xi^{*}), we let ylen(y)+1:y_{\mathtt{len}(y)+1:} (resp., ξlen(ξ)+1\xi_{\mathtt{len}(\xi)+1}) denote the empty string/sequence.

Redefining the test statistic ϕ\phi using dγd_{\gamma} as the alignment cost—using d0d_{0} from equation (2)—ensures detect\mathtt{detect} is robust not only to substituting tokens, but also inserting and deleting tokens from watermarked text, as we show in Lemma 2.6. We defer the proof of Lemma 2.6 to Appendix B. To state the lemma, we first recursively define a notion of edit distance between two strings. The definition is equivalent to the minimum number of insertion and/or deletion operations needed to transform one string into the other (see Lemma B.2).

(edit distance) For y,y~∈V∗y,\widetilde{y}\in\mathcal{V}^{*}, define the edit distance by

with dedit(y,y~)=len(y)d_{\textup{edit}}(y,\widetilde{y})=\mathtt{len}(y) if y~\widetilde{y} is empty and vice versa.

We prove the result by showing there must exist a length kk substring of the corrupted text Y~\widetilde{Y} within edit distance kεk\varepsilon of a substring of YY that the detector will be able to distinguish as watermarked. For fixed kk, the set of strings within edit distance εk\varepsilon k of an original block watermarked text blows up combinatorially with ε\varepsilon. To ensure we can detect the watermark, the result implies we must set γ=Ω(1/ε)\gamma=\Omega(1/\varepsilon), which means our bound on the expected pp-value is vacuous as soon as ε=Ω(1/log⁡k)\varepsilon=\Omega(1/\log k). Admittedly, our analysis is not tight; for example, as a preview of the experimental results to come, in practice we find smaller values of γ\gamma (i.e., γ<1\gamma<1) to perform significantly better. However, one takeaway from the result is that using a block size k<mk<m, where here mm is the length of the input text, for detection can be an effective strategy when the user has substantially corrupted the text. The assumption that kk divides evenly into mm is an artifact of our analysis and not important in practice.

3.2 What we run in practice

In practice, to reduce overhead in both generate\mathtt{generate} and detect\mathtt{detect}, we use a single random permutation In principle, with a single random permutation the permuted token indices of both watermarked and nonwatermarked text are no longer conditionally independent of each other, and so the results of Lemmas 2.4, 2.5 and 2.6 no longer apply. However, in practice we observe no degradation in statistical power. Also, irrespective of the lemmas, the pp-values from detect\mathtt{detect} are still valid by construction. instead of a full sequence, i.e., we let πi=π\pi_{i}=\pi for all i∈[n]i\in[n] for π∼Unif(π)\pi\sim\textup{Unif}(\pi). Recall Theorem 1 makes no assumption about the distribution of the permutations; thus, the watermark is still distortion-free. Also, for the test statistic, we find using

as the alignment cost performs better empirically than the alignment cost in equation (2). To reiterate, the output of detect\mathtt{detect} is a valid pp-value irrespective of the test statistic we use.

Henceforth, we refer to this version of the watermarking strategy as ITS\mathtt{ITS}, and we refer to the corresponding Levenshtein version as ITS\mathtt{ITS}-edit\mathtt{edit}, wherein we define the base alignment cost d0d_{0} by equation (3) and use the following simplified notion of Levenshtein cost:

with dγ(y,(u,π)):=γ⋅len(y)d_{\gamma}(y,(u,\pi)):=\gamma\cdot\mathtt{len}(y) if ξ\xi is empty and vice versa (as base cases). For y∈V∗y\in\mathcal{V}^{*} (resp., ξ∈Ξ∗\xi\in\Xi^{*}), we let ylen(y)+1:y_{\mathtt{len}(y)+1:} (resp., ξlen(ξ)+1\xi_{\mathtt{len}(\xi)+1}) denote the empty string/sequence.

In summary, for ITS\mathtt{ITS} we use the decoder from equation (1), the test statistic from Algorithm 3 with the alignment cost from equation (3), and the watermark key distribution as the uniform distribution over n×Π^{n}\times\Pi, where recall nn is the length of the watermark key sequence. Meanwhile, ITS\mathtt{ITS}-edit\mathtt{edit} differs from ITS\mathtt{ITS} only in that we define the test statistic using the Levenshtein cost from Definition 5 with the base cost again from equation (3).

4 Watermarking via exponential minimum sampling

Aaronson proposes mapping variables in N^{N} to tokens in the vocabulary [N][N] using exponential minimum sampling to generate watermarked text. Whereas Aaronson proposes the use of distortion-inducing hashes much like Kirchenbauer et al. , we use exponential minimum sampling to implement the decoder in generate\mathtt{generate}, which (after defining a suitable corresponding test statistic) enables an alternative distortion-free and robust watermarking strategy to inverse transform sampling. In particular, for ξ∈N=:Ξ\xi\in^{N}=:\Xi and μ∈Δ([N])\mu\in\Delta([N]), define the decoder by

We show this decoder is distortion-free in Theorem 2, whose proof we defer to Appendix C.

Define the decoder Γ\Gamma by equation (4) and let ξ∼Unif(N)\xi\sim\textup{Unif}(^{N}). Then Γ\Gamma is distortion-free with respect to ξ\xi.

For the sake of analysis, we define the alignment cost as a slight variation of the proposal of Aaronson (see Section 2.4.2) by

again defining the test statistic ϕ\phi by Algorithm 3. Similar to Lemma 2.3 for ITS, we exactly characterize the difference in the expected values of the alignment cost on watermarked versus non-watermarked text in terms of the watermark potential of the text. We defer the proof of Lemma 2.7 to Appendix C.

Summing the result of Lemma 2.7 over i∈[m]i\in[m] implies for any j∈[n]j\in[n] that

Thus, defining the test statistic ϕ\phi by Algorithm 3 with respect to the alignment cost dd from Eqn (5), we can again upper bound the pp-value output by detect\mathtt{detect} in Lemma 2.8 using a standard concentration argument and taking a union bound over j∈[n]j\in[n]. We defer the proof of Lemma 2.8 to Appendix C. Once again, we actually prove a more general result that allows Y~\widetilde{Y} to be any length kk subsequence of YY.

Showing high probability pp-value upper bounds for corruptions of watermarked text that hold almost surely given the corrupted text—i.e., analogues of Lemmas 2.5 and 2.6—is more difficult, primarily due to the fact that the summands in the alignment metric from equation (5) are no longer bounded and thus bounding the influence of each substitution and/or insertion operation on the test statistic requires more careful analysis. Of course, we could in principle tweak the alignment metric by truncating the summands in order to prove the analogous results; however, as the main intuitions would carry over from Lemmas 2.5 and 2.6 and the results are not critical to the main thrust of the paper, we do not carry this plan out.

4.2 What we run in practice

As in the case of ITS, in practice we find using a slight variation of the alignment cost in equation (5) performs better. Namely, following the prescription of Aaronson , we modify the previous alignment cost to instead be

Henceforth, we refer to this version of the watermarking strategy as EXP\mathtt{EXP}, and we refer to the corresponding Levenshtein version wherein we define the base alignment cost d0d_{0} by equation (6) as EXP\mathtt{EXP}-edit\mathtt{edit}.

In summary, for EXP\mathtt{EXP} we use the decoder from equation (4), the test statistic from Algorithm 3 with the alignment cost from equation (6), and the watermark key distribution as the uniform distribution over Ξn\Xi^{n}, where recall nn is the length of the watermark key sequence and Ξ=N\Xi=^{N}. Meanwhile, EXP\mathtt{EXP}-edit\mathtt{edit} differs from EXP\mathtt{EXP} only in that we define the test statistic using the Levenshtein cost from Definition 5 with the base cost again from equation (6).

Experimental results

We empirically validate the statistical power of our watermarking strategies (i.e., ITS\mathtt{ITS}, ITS\mathtt{ITS}-edit\mathtt{edit}, EXP\mathtt{EXP}, and EXP\mathtt{EXP}-edit\mathtt{edit}) via experiments with the OPT-1.3B and LLaMA-7B models. We will also at times collectively refer to ITS\mathtt{ITS} and ITS\mathtt{ITS}-edit\mathtt{edit} as the ITS watermarks and/or strategies and EXP\mathtt{EXP} and EXP\mathtt{EXP}-edit\mathtt{edit} as the EXP watermarks and/or strategies. We run experiments using generate\mathtt{generate} rather than shift-generate\mathtt{shift\textup{-}generate}, mainly for the sake of reproducibility; recall however that this choice has no impact on the pp-values we report. We test for all watermarks using a block size kk (in Algorithm 3) equal to the length mm of the text. Following the methodology of Kirchenbauer et al. , we generate watermarked text continuations of prompts sampled from the news-like subset of the C4 dataset . We vary the generation length mm (Experiment 1) and the random number sequence length nn (Experiment 2), and we report median pp-values of watermarked text over 500500 samples. The median pp-value corresponds to the significance level (i.e., Type I error rate) at which the power of our watermark detector is at least 0.50.5.

We also evaluate robustness to four kinds of paraphrasing attacks: randomly substituting a fraction of the generated tokens with tokens chosen uniformly at random from the vocabulary (Experiment 3); randomly inserting a fraction of tokens among the generated tokens (Experiment 4); randomly deleting a fraction of the generated tokens (Experiment 5); using another language model to translate the text from English to French and back (Experiment 6). The first three attacks allow us to systematically vary the level of corruption, while the last attack is an example of an attack we might encounter in the wild. We defer the details of the translation procedures to Appendix D.2.

Finally, using the Alpaca-7B model and evaluation dataset , we conduct a case-study on the feasibility of watermarking the responses of a performant instruction-tuned language model to user queries. We also show for certain kinds of instructions that hashing-based watermarks produce noticeably worse responses than our distortion-free watermarks, thus underlining the importance of the distortion-free property in practice.

In all our experiments—except for Experiment 2, where the control variable nn is a hyperparameter that is unique to our watermarks—we also replicate the watermark of Kirchenbauer et al. as a baseline, setting the greenlist fraction γ=0.25\gamma=0.25 and varying the logit bias δ∈{1.0,2.0}\delta\in\{1.0,2.0\}. We respectively refer to these versions of their watermark as KGW\mathtt{KGW}-1.0\mathtt{1.0} and KGW\mathtt{KGW}-2.0\mathtt{2.0} after the first three authors’ last names. We emphasize their watermark is not directly comparable to our watermarks as it is not distortion-free (e.g., Kirchenbauer et al. report that even the weakest version we employ with δ=1.0\delta=1.0 and γ=0.25\gamma=0.25 typically increases perplexity by 5–10%).

In their work, Kirchenbauer et al. report approximate pp-values, which they obtain from computing the zz-score of a certain test statistic. To ensure a fair comparison, we use detect\mathtt{detect} (with T=5000T=5000) to report pp-values for all watermarks; This setting of TT means we never report pp-values less than 1/50001/5000 (i.e., 0.00020.0002) in any of our experiments. in the case of KGW\mathtt{KGW}-1.0\mathtt{1.0} and KGW\mathtt{KGW}-2.0\mathtt{2.0}, we run detect\mathtt{detect} using the original inexact pp-values they report as the test statistic. We report error bars for the median pp-value based on a bootstrapped estimate of the standard deviation using 10001000 resamples.

Instead of recomputing the test statistic TT times for each prompt—as we originally prescribe in detect\mathtt{detect}—to save computation we simply sample TT prompts and compute the test statistic once for each ground-truth length mm completion; we then use the empirical distribution of these test statistics as the reference distribution within detect\mathtt{detect}, which gives a proper pp-value with respect to the null hypothesis that the text is an original completion from the dataset. For reference, we include the full pseudocode for this modified version of detect\mathtt{detect} in Appendix D.3, and we also plot the full distributions of pp-values for nonwatermarked generations (i.e., regular samples from the language models) to verify they are indeed roughly uniform over the interval $$.

We defer further details regarding our experimental protocol to Appendix D.

We vary the length mm of watermarked text in Figure 2, fixing the watermark key length n=256n=256 for each of our watermarks and setting γ=0.4\gamma=0.4 for ITS\mathtt{ITS}-edit\mathtt{edit} and γ=0.0\gamma=0.0 for EXP\mathtt{EXP}-edit\mathtt{edit} (see Appendix D.4 for the details of tuning γ\gamma). Our ITS watermarks slightly outperform KGW\mathtt{KGW}-1.0\mathtt{1.0} while our EXP watermarks slightly outperform KGW\mathtt{KGW}-2.0\mathtt{2.0}, despite the fact that KGW\mathtt{KGW}-1.0\mathtt{1.0} and KGW\mathtt{KGW}-2.0\mathtt{2.0} both distort the text distribution. The EXP watermarks are notably more powerful than the ITS watermarks, requiring roughly two to three times fewer tokens to achieve a comparably low median pp-value. One conceivable advantage of the ITS watermarks over the EXP watermarks is that they have comparatively less overhead: the watermark key for EXP\mathtt{EXP} and EXP\mathtt{EXP}-edit\mathtt{edit} is a sequence of nn vectors in N^{N}, where recall NN is the size of the vocabulary, while for ITS\mathtt{ITS} and ITS\mathtt{ITS}-edit\mathtt{edit} it is simply a sequence of nn numbers in $.AllwatermarkingstrategiesperformworseonLLaMA−7BthanOPT−1.3B,duetothefactthatLLaMA−7BtypicallyproduceslowerentropytextthanOPT−1.3B.DuetothediscretenatureoftheteststatisticofKirchenbaueretal.,i.e.,thenumberoftokensinthetextbelongingtoa“greenlist”versusa“redlist”,themedian. All watermarking strategies perform worse on LLaMA-7B than OPT-1.3B, due to the fact that LLaMA-7B typically produces lower entropy text than OPT-1.3B. Due to the discrete nature of the test statistic of Kirchenbauer et al. , i.e., the number of tokens in the text belonging to a “greenlist” versus a “redlist”, the medianp−valuesforthe-values for the\mathtt{KGW}−-\mathtt{1.0}andand\mathtt{KGW}−-\mathtt{2.0}watermarksareoccasionallyunstable,particularlyforsmallvaluesofwatermarks are occasionally unstable, particularly for small values ofm$.

We vary the length nn of the watermark key sequence ξ\xi in Figures 3 and 4 for different lengths mm of watermarked text from the ITS and EXP watermarks respectively. Recall nn corresponds to the total number of tokens we can generate while maintaining our distortion-free guarantee. As our theory predicts, the pp-values of watermarked text grow linearly with nn. The rate of growth is fairly mild and decreases rapidly with mm; even for n=4096n=4096, which is larger than the maximum generation length of both the OPT-1.3B and LLaMA-7B models, slightly increasing the number of tokens (by 4–8 tokens in the case of EXP, and 10–20 tokens in the case of ITS) suffices to distinguish watermarked text with roughly the same statistical power as n=64n=64.

2 Robustness to corruption and paraphrasing

We now proceed to evaluate the robustness of our watermark strategies to various forms of corruption and paraphrasing. We focus on comparing our strongest watermarks (EXP\mathtt{EXP} and EXP\mathtt{EXP}-edit\mathtt{edit}) against KGW\mathtt{KGW}-2.0\mathtt{2.0}, deferring results for all other watermarks to Appendix D.5. As larger nn increases the computational overhead of computing our test statistics and the effect of larger nn on statistical power is mild (as shown in Figure 4), we run all experiments with n=256n=256, which in any case is sufficiently large to ensure the watermarked text across all experiments is distortion-free. Decreasing the insertion/deletion penalty γ\gamma improves robustness (at least up to a point) but hurts the statistical power of the ITS\mathtt{ITS}-edit\mathtt{edit} and EXP\mathtt{EXP}-edit\mathtt{edit} watermarks for larger nn, since reducing the penalizer for edits effectively increases the number of candidate alignments under consideration. We run ITS\mathtt{ITS}-edit\mathtt{edit} and EXP\mathtt{EXP}-edit\mathtt{edit} with the same choices of γ\gamma as in the previous section. We defer the details of tuning γ\gamma to Appendix D.4.

We vary the fraction of substituted tokens in Figure 5, and we vary the fraction of inserted and deleted tokens in Figures 6 and 7 respectively. For the insertion experiment, we pass only the first mm tokens to the detector; similarly, for the deletion experiment, we initially generate more than mm watermarked tokens so that even after deleting a fraction thereof, there are at least mm tokens remaining. The EXP\mathtt{EXP} and EXP\mathtt{EXP}-edit\mathtt{edit} watermarks are comparably robust to substitution errors, but the latter is far more robust to insertion and deletion errors.

We compare our watermarks against the most robust version of KGW\mathtt{KGW}-2.0\mathtt{2.0}, in the sense that we hash only the previous token to determine the next token distribution and thus bias the distribution towards some subset of bigrams. If instead we hash the previous kk tokens for k>1k>1, then substituting any one of the previous kk tokens will break the watermark signal in a particular token, and thus the statistical power of their watermark will be worse than what we report in our experiments.

Finally, in Figures 9 and 10 we implement a “roundtrip translation” attack, wherein we attempt to paraphrase watermarked texts of varying lengths by translating the (English) texts into another language (i.e., French and Russian respectively) and back again using a machine translation model (details in Appendix D.2). We include a representative example of the original and (re-)translated texts in Figure 8. Using Russian is a noticeably more effective attack than French: none of the watermarks aside from EXP\mathtt{EXP}-edit\mathtt{edit} are able to reliably detect watermarked text with p<0.05p<0.05 irrespective of mm.

In many cases, both using French and Russian, the roundtrip translation still preserves large chunks of the original text, which suffices for watermark detection even using EXP\mathtt{EXP}, which is substantially less robust to insertion and deletion errors than EXP\mathtt{EXP}-edit\mathtt{edit}. Aside from inspecting a few examples, we did not verify that the roundtrip translations preserve the basic semantics of the original text; thus, it is possible our results provide an overly pessimistic view of the robustness of our watermarks to these attacks, since in practice users would presumably not publish such examples. It is also possible that using different machine translation models—or more generally, different forms of automated paraphrasing—might be far more effective in evading watermark detection than those we employed. We publish the full set of watermarked generations for each watermarking strategy, along with their (roundtrip) translations, as part of our code release.

3 Case study: instruction following

In the wild, most users interact with language models by prompting the model with instructions (e.g., “give me code for…”), and the most widely-used language models (e.g., ChatGPT) are specifically fine-tuned to follow such instructions. Thus, using the instruction fine-tuned Alpaca-7B model, we presently conduct a case study on the effectiveness of watermarking a performant instruction following model. In particular, we sample 200200 instructions from the Alpaca-7B evaluation dataset and generate watermarked responses of at most 200200 tokens for each. We then compute conditionally valid pp-values for each response using the original version of detect\mathtt{detect} with T=500T=500. We also replicate the roundtrip translation attack from Experiment 6. We publish the full set of watermarked generations for each method, along with their (roundtrip) translations, and the instruction prompts as part of our code release.

We plot the distribution of pp-values for the EXP\mathtt{EXP}-edit\mathtt{edit} and KGW\mathtt{KGW}-2.0\mathtt{2.0} watermarks in Figure 11, as well as the pp-values versus the watermark potential of the watermarked text in Figure 12. In general, the Alpaca-7B responses have considerably lower per-token watermark potential than both the OPT-1.3B and LLaMA-7B models, and thus the statistical power of our watermark is worse despite the responses typically being longer than in the previous experiments (i.e., Experiments 1 and 6). In particular, based on the same random sample of 200200 prompts (from the Alpaca evaluation set in the case of Alpaca-7B, and from the news-like subset of the C4 dataset in the cases of LLaMA-7B and OPT-1.3B), the average per-token watermark potential of text from Alpaca-7B is 0.280.28, compared to 0.590.59 for LLaMA-7B and 0.670.67 for OPT-1.3B. Unlike the previous experiments, KGW\mathtt{KGW}-2.0\mathtt{2.0} noticeably outperforms the EXP\mathtt{EXP}-edit\mathtt{edit} watermark. Figure 12 indicates this difference in performance is largely due to the fact KGW\mathtt{KGW}-2.0\mathtt{2.0} distorts the distribution of the text and produces responses with noticeably larger watermark potential than regular responses from the model. For responses whose unnormalized watermark potential (i.e., watermark potential multiplied by the number of tokens in the response, to account for the varying lengths of the responses) exceeds roughly 6060, both watermarks tend to yield pp-values close to zero. Paraphrasing the responses via roundtrip translation attacks into both French and Russian degrades the statistical power of both watermarks, as we show in Figures 13 and 14.

Finally, recall the main distinguishing feature of our watermark compared to Kirchenbauer et al. and Aaronson is that we do not hash previous tokens to determine the distribution of the next token. To demonstrate the pitfalls of hashing, we implement a version of the watermark Aaronson proposes by modifying the generate\mathtt{generate} method of EXP\mathtt{EXP} to obtain the vector ξi∈N\xi_{i}\in^{N} from seeding a random number generator using the previous kk tokens instead of using the watermark key; we call this version EXP\mathtt{EXP}-hash\mathtt{hash}. We then prompt Alpaca-7B with requests for various kinds of lists. Because Alpaca-7B tends to separate items in lists by the same recurring token, e.g., a comma or a newline character, and because this recurring token determines the next token, for k=1k=1 the lists degenerate into repetition (Figure 15). The authors would like to pat themselves on the back by drawing the reader’s attention to the fact that the title of this paper is not among those suggested by Alpaca-7B.

From inspection, hashing with k>1k>1 substantially improves the quality of samples; however, even using k=4k=4 can sometimes produce noticeably repetitive text. We reiterate that while increasing kk may improve sample quality by making the distortions of watermarked text less noticeable, doing so harms the robustness of the watermark (e.g., replacing just 20%20\% of the tokens would suffice to evade detection for k=4k=4). Moreover, using a more robust hash function does not avoid this trade-off between robustness and distortion-freeness, as there is a direct trade-off between the likelihood of a hash collision and the robustness of the hash. In addition to Figure 15, we include more examples (for both k=1k=1 and k=4k=4) and different prompts in Appendix D.5.5 and our code release.

Discussion

In this paper, we give the first distortion-free watermarking strategies for language models that are robust to editing and/or cropping. The key idea underpinning our approach is to leverage methods for robust sequence alignment to align a putative watermarked text to a watermark key sequence which the LM provider uses to generate watermarked text. The statistical power of our watermarks improves exponentially with respect to the length of the text and diminishes only linearly with respect to the length of the watermark key sequence.

The computational complexity of our watermark detection algorithms grows linearly with the length of the watermark key sequence, which is also the total number of distortion-free watermarked tokens the LM provider may generate. In contrast, the complexities of the watermark detection algorithms of both Christ et al. and also Aaronson and Kirchenbauer et al. depend only on the length of the input text; however, the former watermark is not robust to corruption and the latter two watermarks are not distortion-free. Whether this apparent trade-off between computational complexity, robustness and distortion-freeness is a fundamental trade-off is an interesting open question.

The underlying assumption behind all of the above watermarking strategies including ours is that the LM provider and the watermark detector coordinate by sharing information in advance, e.g., a watermark key. Indeed, the main inherent limitation of watermarking is that the detector must trust the LM provider to faithfully apply the watermark when generating text. A second limitation, which is not inherent but does presently apply to all known watermarks, is that the LM provider cannot release the model weights, since then users could simply query the model directly instead of through the LM provider. Planting robust watermarks directly into the weights of a language model without degrading the quality of the model is an important direction for future work.

Recently, several major language model providers (among others: OpenAI, Anthropic, Google and Meta) have pledged to watermark the text from their models . Thus, we conclude with some salient recommendations for practitioners. First, we recommend practitioners use our EXP\mathtt{EXP}-edit\mathtt{edit} watermark, as it is by far the most robust watermark of those we tested. Second, though in principle the length of the watermark key sequence nn—which recall imposes a cap on the total number of distortion-free watermarked tokens the LM provider can generate—can grow (nearly) exponentially in the block size kk of the test statistic while still enabling watermark detection from as few as kk tokens, in practice we find that using a fairly small watermark key sequence (e.g., n=256n=256) does not noticeably affect the quality of watermarked text (i.e., even when generating more than nn tokens total). Our watermark detection procedures (i.e., both detect\mathtt{detect} and the test statistic therein from Algorithm 3) are easily parallizeable, so we expect even with a very large watermark key sequence (e.g., n=100000n=100000) the computational demands of watermark detection will not be a significant bottleneck—though we caveat this speculation by noting that we did not ever run such large nn with our implementation.

Acknowledgement

We thank Saminul Haque, Gary Cheng and Padma Kuditipudi for pointing out errors in preliminary drafts of this work and for their helpful feedback in general. This work is supported by an Open Philanthropy Project Award (OpenPhil) and an NSF Frontier Award (NSF Grant no. 1805310).

References

Appendix A Proof of Lemma 2.2

To show the claim, we first lower bound the probability that Y=Y′Y=Y^{\prime}. In particular,

where (⋆\star) follows from exp⁡(−cx)≤1−x\exp(-cx)\leq 1-x for 0≤x≤1−exp⁡(−c/2)0\leq x\leq 1-\exp(-c/2). It then follows immediately that

The desired result thus follows from letting AA be the event that hh predicts −1-1. ∎

Appendix B Analysis of inverse transform sampling

To prove the main theorems, we introduce the following supporting lemma. Recall C0=Var(η(Unif([N])))C_{0}=\textup{Var}(\eta(\textup{Unif}([N]))).

Let μ∈Δ([N])\mu\in\Delta([N]). Let (U,π)∼Unif()×Unif(Π)(U,\pi)\sim\textup{Unif}()\times\textup{Unif}(\Pi) and Y=Γ((U,π),μ)Y=\Gamma((U,\pi),\mu). Then 1C0Cov(U,η(π(Y))∣Y)=1−μ(Y)\frac{1}{C_{0}}\textup{Cov}(U,\eta(\pi(Y))\mid Y)=1-\mu(Y) almost surely.

We first characterize the conditional distribution of π\pi given YY and the conditional distribution of UU given both π\pi and YY, where recall π\pi and YY are discrete. Applying Bayes’ formula and Theorem 1, we have

where (aa) follows from Bayes’ formula and the independence of UU and π\pi; (bb) follows from the definition (1) of the decoder Γ\Gamma; and (cc) follows from I(Y,π)⊂I(Y,\pi)\subset having width equal to μ(Y)\mu(Y). The displays (7) and (8) respectively imply π∣Y∼Unif(Π)\pi\mid Y\sim\textup{Unif}(\Pi) and U∣π,Y∼Unif(I(Y,π))U\mid\pi,Y\sim\textup{Unif}(I(Y,\pi)), from which it follows that

from which the desired result follows immediately from recalling π(Y)∣Y∼Unif([N])\pi(Y)\mid Y\sim\textup{Unif}([N]) and the definition of the constant C0C_{0}. ∎

B.2 Proof of Lemma 2.4

We prove the following more general result, from which Lemma 2.4 follows as a corollary.

Lemma 2.3 and the conditional independence of τ\tau and ξ\xi given YY imply for any j∈[n]j\in[n] that

Each summand in equation (9) lies between −1/4-1/4 and 1/41/4, and also (Ui,πi)(U_{i},\pi_{i}) is conditionally independent of U−iU_{-i} and π−i\pi_{-i} given YY. Thus, Hoeffding’s inequality [27, Proposition 2.5] implies for j∈[n]j\in[n] that

Recalling the definition of the test statistic ϕ\phi via Algorithm 3, the main claim then follows from taking a union bound over all j∈[n]j\in[n]. ∎

B.3 Proof of Lemma 2.5

We begin with the following observation for a single token.

Let P∈Δ([N])P\in\Delta([N]). Let (U,π)∼Unif()×Unif(Π)(U,\pi)\sim\textup{Unif}()\times\textup{Unif}(\Pi) and Y=Γ((U,π),P)Y=\Gamma((U,\pi),P). Let Y~∈[N]\widetilde{Y}\in[N] be conditionally independent of (U,π)(U,\pi) given YY. If Y~≠Y\widetilde{Y}\neq Y, then almost surely

Observe the conditional distribution of π(Y~)\pi(\widetilde{Y}) given YY is uniform over [N]∖{π(Y)}[N]\setminus\{\pi(Y)\}. Let XX be a random variable that is equal to η(π(Y))\eta(\pi(Y)) with probability 1/N1/N and otherwise equal to η(π(Y~))\eta(\pi(\widetilde{Y})). Observe XX is independent of YY and thus also UU by assumption—in particular, (N−1)X+1∣Y∼Unif([N])(N-1)X+1\mid Y\sim\textup{Unif}([N]) irrespective of the value of YY. The claim thus follows from rearranging terms in the equality

Lemma 2.3 and Observation B.1 together imply for any j∈[n]j\in[n] that

i.e., by adding the two results together using Observation B.1 to account for the influence of each substituted token on the expectation. Using the same concentration argument as in the proof of Theorem 2.4, we then have

Recalling the definition of the test statistic ϕ\phi via Algorithm 3, the main claim then follows from taking a union bound over all j∈[n]j\in[n] and recalling k=mk=m by assumption. ∎

B.4 Proof of Lemma 2.6

We begin with the following useful facts about edit distance. Throughout, let S(y)\mathcal{S}(y) denote the set of substrings of a string y∈V∗y\in\mathcal{V}^{*}, including the empty string.

Let y,y~∈V∗y,\widetilde{y}\in\mathcal{V}^{*}. Then dedit(y,y~)d_{\textup{edit}}(y,\widetilde{y}) is the length of the smallest sequence of insertion and/or deletion operations to obtain y~\widetilde{y} from yy.

We proceed via induction on the sum len(y)+len(y~)\mathtt{len}(y)+\mathtt{len}(\widetilde{y}). The base case where yy and y~\widetilde{y} are both empty is trivial. Now suppose the claim holds all strings whose lengths sum to at most len(y)+len(y~)−1\mathtt{len}(y)+\mathtt{len}(\widetilde{y})-1. Recalling the definition of deditd_{\textup{edit}} (Definition 4), there are three cases.

First, suppose dedit(y,y~)=dedit(y2:,y~2:)d_{\textup{edit}}(y,\widetilde{y})=d_{\textup{edit}}(y_{2:},\widetilde{y}_{2:}). Then by induction there exists a sequence of dedit(y,y~)d_{\textup{edit}}(y,\widetilde{y}) insertion and/or deletion operations to obtain y~2:\widetilde{y}_{2:} from y2:y_{2:}. Because y1=y~1y_{1}=\widetilde{y}_{1}, the same sequence suffices to obtain y~\widetilde{y} from yy and thus the claim follows.

Second, suppose dedit(y,y~)=1+dedit(y2:,y~)d_{\textup{edit}}(y,\widetilde{y})=1+d_{\textup{edit}}(y_{2:},\widetilde{y}). Again by induction, there exists a sequence of dedit(y,y~)−1d_{\textup{edit}}(y,\widetilde{y})-1 insertion and/or deletion operations to obtain y~\widetilde{y} from y2:y_{2:}. It follows immediately (i.e., by first deleting y1y_{1}) there exists a sequence of dedit(y,y~)d_{\textup{edit}}(y,\widetilde{y}) such operations to obtain y~\widetilde{y} from yy, and so the claim holds.

The third case follows by symmetry with the second case. ∎

Let y,y~∈V∗y,\widetilde{y}\in\mathcal{V}^{*}. Then for any τ<len(y)\tau<\mathtt{len}(y), we have

Observation B.2 implies there exists a sequence of dedit(y,y~)d_{\textup{edit}}(y,\widetilde{y}) insertion and/or deletion operations to obtain y~\widetilde{y} from yy. We may partition this sequence of operations into sequences based respectively on whether they occur on y:τy_{:\tau} or yτ+1:y_{\tau+1:}. Let y~pre\widetilde{y}_{\textup{pre}} be the result of performing the first sequence of operations on y:τy_{:\tau} and let y~suf\widetilde{y}_{\textup{suf}} be the result of performing the second sequence of operations on yτ+1:y_{\tau+1:}. Then y~\widetilde{y} is the concatenation of y~pre\widetilde{y}_{\textup{pre}} and y~suf\widetilde{y}_{\textup{suf}}, and so the claim follows from the fact that

Let y,y~∈V∗y,\widetilde{y}\in\mathcal{V}^{*} and ξ∈Ξ∗\xi\in\Xi^{*}. Then dγ(y,ξ)≤γdedit(y,y~)+dγ(y~,ξ)d_{\gamma}(y,\xi)\leq\gamma d_{\textup{edit}}(y,\widetilde{y})+d_{\gamma}(\widetilde{y},\xi).

We claim dγ(yi:,ξj:)≤dγ(y~i:,ξj:)+γd_{\gamma}(y_{i:},\xi_{j:})\leq d_{\gamma}(\widetilde{y}_{i:},\xi_{j:})+\gamma. If yi+1:=y~i:y_{i+1:}=\widetilde{y}_{i:}, then the claim obtains as

with (⋆)(\star) following from the fact that d0(yi,ξ′)=0d_{0}(y_{i},\xi^{\prime})=0 for ξ′=(1/2,π)\xi^{\prime}=(1/2,\pi) irrespective of yiy_{i} and π\pi.

Otherwise, if yi:=y~i+1:y_{i:}=\widetilde{y}_{i+1:}, then from unrolling the recursive definition of dγ(y~i:,ξj:)d_{\gamma}(\widetilde{y}_{i:},\xi_{j:}) there must exist some index j′≥jj^{\prime}\geq j such that either

In the first case, we have γ+min⁡ξ′∈Ξd0(y~i,ξ′)>0\gamma+\min_{\xi^{\prime}\in\Xi}d_{0}(\widetilde{y}_{i},\xi^{\prime})>0 since γ>1/2\gamma>1/2 by assumption, and so the claim follows as

In the second case, we have d0(y~j)d_{0}(\widetilde{y}_{j}) the claim follows as

Thus, assuming dedit(y,y~)≤1d_{\textup{edit}}(y,\widetilde{y})\leq 1, we have shown dγ(yi:,ξj:)≤dγ(y~i:,ξj:)+γd_{\gamma}(y_{i:},\xi_{j:})\leq d_{\gamma}(\widetilde{y}_{i:},\xi_{j:})+\gamma, from which it follows that dγ(y,ξ)≤dγ(y~,ξ)+γd_{\gamma}(y,\xi)\leq d_{\gamma}(\widetilde{y},\xi)+\gamma. The general result follows immediately by applying Observation B.2 and summing the bound for a single edit over the (smallest) sequence of edits to obtain y~\widetilde{y} from yy. ∎

Proceeding with the main proof, define for convenience the quantity

while Observation B.3 together with our assumption that dedit(Y,Y~)≤εmd_{\textup{edit}}(Y,\widetilde{Y})\leq\varepsilon m implies

The displays (10) and (11) together imply there exists an index τ\tau and Y′∈S(Y~)Y^{\prime}\in\mathcal{S}(\widetilde{Y}) such that α^τ−1kmin⁡Y′∈S(Y~)dedit(Yτ+1:τ+k,Y′)≥α(Y)−ε\widehat{\alpha}_{\tau}-\frac{1}{k}\min_{Y^{\prime}\in\mathcal{S}(\widetilde{Y})}d_{\textup{edit}}(Y_{\tau+1:\tau+k},Y^{\prime})\geq\alpha(Y)-\varepsilon. Reusing the same concentration argument as in the proof of Theorem 2.4, for t≥0t\geq 0 we have

and thus from Observation B.4 it follows that

Letting t=(C0α−γε)/2t=(C_{0}\alpha-\gamma\varepsilon)/2 and recalling the definition of the test statistic, we have

All that remains to bound the probability of ϕ(Y~,ξ′)\phi(\widetilde{Y},\xi^{\prime}) exceeding the threshold from the above display. To this end, define the set-valued map Nβ(y):={y′ : dedit(y,y′)≤β/(4γ−1)}\mathcal{N}_{\beta}(y):=\{y^{\prime}\ :\ d_{\textup{edit}}(y,y^{\prime})\leq\beta/(4\gamma-1)\}. Then we make the following observation.

For any y∈V∗y\in\mathcal{V}^{*} and ξ∈Ξ∗\xi\in\Xi^{*}, there exists y′∈Nlen(ξ)(y)y^{\prime}\in\mathcal{N}_{\mathtt{len}(\xi)}(y) such that

We proceed via induction. The base case where yy and ξ\xi both have length 11 follows trivially by taking y′=yy^{\prime}=y; in particular, γ>1/2\gamma>1/2 implies d(y,ξ)≤γ+min⁡y′d(y′,ξ)d(y,\xi)\leq\gamma+\min_{y^{\prime}}d(y^{\prime},\xi) and likewise d(y,ξ)≤γ+min⁡ξ′d(y,ξ′)d(y,\xi)\leq\gamma+\min_{\xi^{\prime}}d(y,\xi^{\prime}). Now suppose the result holds so long as len(y)+len(ξ)≤n−1\mathtt{len}(y)+\mathtt{len}(\xi)\leq n-1. We claim that the result must then also hold if the lengths sum to at most nn.

We prove this inductive claim by considering three exhaustive cases. First, suppose that dγ(y,ξ)=dγ(y2:,ξ2:)+d(y1,ξ1)d_{\gamma}(y,\xi)=d_{\gamma}(y_{2:},\xi_{2:})+d(y_{1},\xi_{1}). By our induction hypothesis, there exists y^∈Nlen(ξ)−1(y2:)\hat{y}\in\mathcal{N}_{\mathtt{len}(\xi)-1}(y_{2:}) such that dγ(y2:,ξ2:)=γ⋅dedit(y2:,y^)+d(y^,ξ2:)d_{\gamma}(y_{2:},\xi_{2:})=\gamma\cdot d_{\textup{edit}}(y_{2:},\hat{y})+d(\hat{y},\xi_{2:}). The desired result then obtains with y′y^{\prime} as the concatenation of y1y_{1} and y^\hat{y}. Second, suppose dγ(y,ξ)=dγ(y,ξ2:)+min⁡ξ′∈Ξd(y1,ξ′)+γd_{\gamma}(y,\xi)=d_{\gamma}(y,\xi_{2:})+\min_{\xi^{\prime}\in\Xi}d(y_{1},\xi^{\prime})+\gamma. By our induction hypothesis, there exists y^∈Nlen(ξ)=1(y)\hat{y}\in\mathcal{N}_{\mathtt{len}(\xi)=1}(y) such that dγ(y2:,ξ)=γ⋅dedit(y2:,y^)+d(y^,ξ2:)d_{\gamma}(y_{2:},\xi)=\gamma\cdot d_{\textup{edit}}(y_{2:},\hat{y})+d(\hat{y},\xi_{2:}). The result obtains with y′=y^y^{\prime}=\hat{y}. Finally, suppose dγ(y,ξ)=dγ(y2:,ξ)+d(y′′,ξ1)+γd_{\gamma}(y,\xi)=d_{\gamma}(y_{2:},\xi)+d(y^{\prime\prime},\xi_{1})+\gamma for some y′′∈Vy^{\prime\prime}\in\mathcal{V}. By our induction hypothesis, there exists y^∈Nlen(ξ)−1(y)\hat{y}\in\mathcal{N}_{\mathtt{len}(\xi)-1}(y) such that dγ(y2:,ξ)=γ⋅dedit(y2:,y^)+d(y^,ξ)d_{\gamma}(y_{2:},\xi)=\gamma\cdot d_{\textup{edit}}(y_{2:},\hat{y})+d(\hat{y},\xi). The result then obtains by concatenating y′′y^{\prime\prime} with y^\widehat{y}. ∎

Let Ij:={(j+i)%n}i=1k\mathcal{I}_{j}:=\{(j+i)\%n\}_{i=1}^{k}. For any 0≤i≤len(Y~)−k0\leq i\leq\mathtt{len}(\widetilde{Y})-k and j∈[n]j\in[n], Observations B.4 and B.5 together imply that

where (⋆\star) follows from the fact that dedit(Y~i+1:i+k,y)>k/4(γ−1)d_{\textup{edit}}(\widetilde{Y}_{i+1:i+k},y)>k/4(\gamma-1) implies

and therefore the minimizer in equation (13) must be an element of Nk/4(γ−1)(Y~i+1:i+k)\mathcal{N}_{k/4(\gamma-1)}(\widetilde{Y}_{i+1:i+k}).

By construction, Nβ(y)\mathcal{N}_{\beta}(y) consists of the set of strings obtainable from yy by a sequence of at most β\beta insertion and/or deletion operations. Now define another set-valued map Nβ,−(y)\mathcal{N}_{\beta,-}(y) as the restriction of Nβ(y)\mathcal{N}_{\beta}(y) such that we may only insert a particular token into yy (which token is immaterial). As the specific identity of each token we insert into yy can only influence the value of dγd_{\gamma} by ±1/2\pm 1/2, for any β\beta it follows that

and so, letting β=k/4(γ−1)\beta=k/4(\gamma-1), from equation (14) we have

Combining the displays (12) and (15) via another union bound gives the desired result. ∎

Appendix C Analysis of exponential minimum sampling

To prove the main theorems, we introduce the following supporting lemma. The result is well known and we restate it here only for completeness.

Let μ∈Δ([N])\mu\in\Delta([N]) and ξ∼Unif(N)\xi\sim\textup{Unif}(^{N}). Then for any y∈[N]y\in[N] we have

Suppose μ(y)>0\mu(y)>0 as otherwise the claim is trivial. Recalling ξi∼i.i.d.Unif()\xi_{i}\overset{\text{i.i.d.}}{\sim}\textup{Unif}(), for any λ>0\lambda>0 we have −λlog⁡ξi∼i.i.d.Exp(λ)-\lambda\log\xi_{i}\overset{\text{i.i.d.}}{\sim}\textup{Exp}(\lambda), i.e.,

where in (⋆\star) we use the fact that the density of −log⁡(ξy)/μ(y)-\log(\xi_{y})/\mu(y) at uu is μ(y)exp⁡(−μ(y)u)\mu(y)\exp(-\mu(y)u). ∎

The result follows immediately from integrating the result of Lemma C.1 over t≥0t\geq 0. ∎

C.2 Proof of Lemma 2.7

C.3 Proof of Lemma 2.8

We prove the following general result, from which Lemma 2.8 follows as a corollary.

Lemma 2.7 and the conditional independence of τ\tau and ξ\xi given YY imply for any j∈[n]j\in[n] that

From Lemma C.1, we have −log⁡ξτ+i,Y~i∣Y~,Y∼Exp(γi)-\log\xi_{\tau+i,\widetilde{Y}_{i}}\mid\widetilde{Y},Y\sim\textup{Exp}(\gamma_{i}) for some γi≤1\gamma_{i}\leq 1 for all i∈[m]i\in[m]. Also, from the independence of Y~\widetilde{Y} and ξ′\xi^{\prime}, we have −log⁡ξj,Y~i′∣Y~,Y∼Exp(1)-\log\xi_{j,\widetilde{Y}_{i}}^{\prime}\mid\widetilde{Y},Y\sim\textup{Exp}(1) for all i∈[m]i\in[m] and j∈[n]j\in[n]. The following observation thus implies −log⁡ξi,Y~i∣Y~,Y-\log\xi_{i,\widetilde{Y}_{i}}\mid\widetilde{Y},Y and −log⁡ξj,Y~i′∣Y~,Y-\log\xi_{j,\widetilde{Y}_{i}}^{\prime}\mid\widetilde{Y},Y are both (2,2)(2,2)-subexponential random variables.

Let X∼Exp(1)X\sim\textup{Exp}(1). Then XX is a (2,2)(2,2) subexponential random variable.

where (a) follows from the fact that t<1t<1 (otherwise, the integral would not be finite); (b) follows from Taylor expanding e−te^{-t} and 1/(1−t)1/(1-t) and applying the fact that t<1/2t<1/2 to bound the higher-order terms; and (c) again follows from t<1/2t<1/2. The claim follows immediately. ∎

Thus, using the fact that ξi\xi_{i} is conditionally independent of ξ−i\xi_{-i} given YY, a standard Chernoff bound [27, Proposition 2.9] implies for each j∈[n]j\in[n] that

Recalling the definition of the test statistic ϕ\phi via Algorithm 3, the main claim then follows from taking a union bound over all j∈[n]j\in[n]. ∎

Appendix D Details of experiments

In Experiments 1-6, for each watermark we first generate a sequence tokens, decode the tokens into text (i.e., a string) using the appropriate tokenizer for the language model, and then encode the text back into tokens before running detect\mathtt{detect}. Each generation is coditioned on a prompt; we obtain the prompts by sampling documents from the news-like subset of the C4 dataset and truncating the last mm tokens. We enforce a minimum prompt size of 5050 tokens in all experiments; we skip over any document that is not long enough. The retokenization is not always equal to the original tokens; in order to ensure detect\mathtt{detect} always receives at least mm tokens, we pad its input with special pad tokens (specific to each model’s tokenizer). We also initially generate a number of buffer tokens beyond mm, so in most cases the padding is unnecessary. We set the number of buffer tokens to be 2020 in every experiment except for Experiment 5, where we set it to be 100100 in order to ensure that even after deleting tokens there are typically still at least mm tokens remaining. We always truncate the number of tokens given to detect\mathtt{detect} to be at most mm, irrespective of the number of buffer tokens.

D.2 Roundtrip translation

In Experiment 6, we perform round-trip translations from English to French and from English to Russian using the OPUS-MT collection of translation models . Specifically, we use the versions of these models hosted on the HuggingfaceHubhttps://huggingface.co/, associated with the identifiers:

Helsinki-NLP/opus-mt-tc-big-en-fr - English to French,

Helsinki-NLP/opus-mt-tc-big-fr-en - French to English,

Helsinki-NLP/opus-mt-en-ru - English to Russian,

Helsinki-NLP/opus-mt-ru-en - Russian to English.

D.3 Computing p-values

As we mention previously, to save computation we modify detect\mathtt{detect} to use a fixed reference distribution to compute pp-values. For the sake of concreteness, we give the full pseudocode for the modified version of detect\mathtt{detect} in Algorithm 5; in Experiments 1-6, we compute pp-values using Algorithm 6 to construct the reference distribution using the news-like subset of the C4 dataset as the text distribution.

As a sanity check, we include histograms of the pp-values we compute for nonwatermarked text for each method to verify that they are roughly uniformly distributed on the interval $(setting(settingm=50andsamplingpromptsfromthenews−likesubsetoftheC4dataset,asinExperiment1).Inthecasesofand sampling prompts from the news-like subset of the C4 dataset, as in Experiment 1). In the cases of\mathtt{KGW}−-\mathtt{1.0}andand\mathtt{KGW}−-\mathtt{2.0}$, the distribution is not quite uniform due to the discrete nature of their test statistics.

D.4 Hyperparameter tuning

There are two hyperparameters involved in computing each of our watermark test statistics (i.e., Algorithm 3), the block size kk and the alignment score dd. We do not tune the block size kk for our experiments, instead simply letting k=mk=m, i.e., the text length, and the alignment score is also fixed for each of our watermarks, except for the hyperparameter γ\gamma in both ITS\mathtt{ITS}-edit\mathtt{edit} and EXP\mathtt{EXP}-edit\mathtt{edit}. Smaller values of γ\gamma (at least to a certain point) tend to make these watermarks more robust to insertion and deletion errors, as Figure 22 illustrates, but also hurts their statistical power for large values of nn, i.e., the watermark key length, as Figure 23 illustrates. We set γ=0.4\gamma=0.4 for ITS\mathtt{ITS}-edit\mathtt{edit} and γ=0.0\gamma=0.0 for EXP\mathtt{EXP}-edit\mathtt{edit} to balance these two competing desiderata.

D.5 Deferred results

D.5.2 Experiment 4

D.5.3 Experiment 5

D.5.4 Experiment 6

D.5.5 Instruction following case study

We give three examples of instructions for which hashing produces qualitatively worse responses than regular samples from the language model:

“Give me 20 ideas for the title of a paper on watermarking language models.”

We format each of the instructions as described by Taori et al. before calling the model.

We compare samples from our EXP\mathtt{EXP} watermark strategy, Recall both EXP\mathtt{EXP} and EXP\mathtt{EXP}-edit\mathtt{edit} use the same generate\mathtt{generate} method. which are equivalent to regular samples from the language model, to samples from KGW\mathtt{KGW}-2.0\mathtt{2.0} and the hashing-based version of EXP\mathtt{EXP} we describe in the main text (i.e., the watermark of Aaronson ), i.e., EXP\mathtt{EXP}-hash\mathtt{hash}. For both EXP\mathtt{EXP} and KGW\mathtt{KGW}-2.0\mathtt{2.0}, we generate the samples using five different random seeds (the hash function in KGW\mathtt{KGW}-2.0\mathtt{2.0} is fixed in the implementation of Kirchenbauer et al. ), whereas in the case of EXP\mathtt{EXP}-hash\mathtt{hash} we use five different hash functions (namely, we let the previous kk tokens {yi}i=1k\{y_{i}\}_{i=1}^{k} hash to j+∑i=1kyij+\sum_{i=1}^{k}y_{i} for j∈{0,…,4}j\in\{0,\dots,4\}). We label each sample using the seed/hash we used to generate it. We include samples from two versions of EXP\mathtt{EXP}-hash\mathtt{hash}: one where we hash the previous tokens (k=1k=1) and another where we hash the previous four tokens (k=4k=4). For KGW\mathtt{KGW}-2.0\mathtt{2.0}, we only hash the previous token since the public implementation of Kirchenbauer et al. does not include the option to hash more tokens.

We find that EXP\mathtt{EXP}-hash\mathtt{hash} with k=1k=1 often produces qualitatively worse responses that degenerate into repetition. With k=4k=4, the repetition is substantially less noticeable, though occasionally it still manifests. In contrast, even when we only hash the previous token, the repetition of KGW\mathtt{KGW}-2.0\mathtt{2.0} is not nearly as noticeable as in EXP\mathtt{EXP}-hash\mathtt{hash}. We speculate this is due to stochasticity of KGW\mathtt{KGW}-2.0\mathtt{2.0} (i.e., KGW\mathtt{KGW}-2.0\mathtt{2.0} biases the distribution over the next token to a subset of tokens but still ultimately samples from this distribution randomly). Of course, this stochasticity comes at a price: KGW\mathtt{KGW}-2.0\mathtt{2.0} was generally less powerful compared to the EXP\mathtt{EXP} and EXP\mathtt{EXP}-edit\mathtt{edit} strategies in our other experiments.

We include sample sheets for all methods for the first instruction below. To avoid excessive clutter, we defer the sample sheets for the remaining two instructions to our code release.