January 01, 1970
Modern large language models (LLMs) such as GPT, Claude, and Gemini have transformed the way we learn, work, and communicate. Yet, their ability to produce highly human-like text raises serious concerns about misinformation and academic integrity, making it an urgent need for reliable algorithms to detect LLM-generated content. In this paper, we start by presenting a geometric approach to demystify rewrite-based detection algorithms, revealing their underlying rationale and demonstrating their generalization ability. Building on this insight, we introduce a novel rewrite-based detection algorithm that adaptively learns the distance between the original and rewritten text. Theoretically, we demonstrate that employing an adaptively learned distance function is more effective for detection than using a fixed distance. Empirically, we conduct extensive experiments with over 100 settings, and find that our approach demonstrates superior performance over baseline algorithms in the majority of scenarios. In particular, it achieves relative improvements from 54.3% to 75.4% over the strongest baseline across different target LLMs (e.g., GPT, Claude, and Gemini). A python implementation of our proposal is publicly available at https://github.com/Mamba413/L2D.
The past few years have witnessed the emergence and rapid development of large language models (LLMs) such as GPT [1], DeepSeek [2], Claude [3], Gemini [4], Grok [5] and Qwen [6]. Their impact is everywhere, from education, academia and software development to healthcare and everyday life [7]–[9]. On one side of the coin, LLMs can support users with conversational question answering, help students learn more effectively, draft emails, write computer code, prepare presentation slides and more. On the other side, their ability to closely mimic human-written text also raises serious concerns, including the generation of biased or harmful content, the spread of misinformation in the news ecosystem, and the challenges related to authorship attribution and intellectual property [10]–[14].
Addressing these concerns requires effective algorithms to distinguish between human-written and LLM-generated text, which has become an active and popular research direction in recent literature [15], [16]. Existing works either actively detect LLM-generated text, by embedding watermarks into LLM-generated text during the design of the model [17]–[24], or passively, without any prior knowledge of the watermarking process. This paper focuses on the latter category of passive detection algorithms. We review these algorithms below.
Most existing passive detection algorithms fall into the following two categories: (i) zero-shot methods and (ii) machine learning (ML)-based approaches, depending on whether they rely on external data for training the detector. Within each category, methods can be further classified into three subtypes: (1) logits-based; (2) rewrite-based, and (3) other approaches. This yields a total of 6 combinations.
Zero-shot detection. Zero-shot methods use only the observed text and a surrogate LLM for detection, without utilizing any additional dataset for training. They compute a statistical measure from the observed text to determine whether it was authored by a human or an LLM. The underlying rationale is that human-written text tends to produce statistics that differ (either larger or smaller) from those of LLM-generated text, and this difference can be exploited for detection [25]. Based on the type of statistical measure employed, these methods can be further categorized into three subtypes:
Logits-based methods construct the statistic using the logits of tokens computed by the surrogate LLM across the observed text [26]–[30].
Rewrite-based methods define the statistic as a suitable distance between the observed text and its rewritten (or regenerated) version [31]–[34]. A similar principle has also been adopted for detecting machine-generated images [35], [36].
Beyond logits or rewrite-based distances, other statistics have been introduced, including the intrinsic dimensionality of the observed text [37], its latent representation patterns [38], N-gram distributions [39] and maximum mean discrepancy [40], [41].
ML-based detection. ML-based methods leverage external human- and LLM-authored text to enhance the detection power of zero-shot methods. A primary approach is to formulate the detection task as a classification problem and utilize external data to train the classifier. Similar to zero-shot methods, ML-based approaches can also be categorized into three subtypes:
Logits-based methods fine-tune the surrogate LLM’s logits to improve the classification accuracy. Various LLMs have been employed in the literature, including RoBERTa [39], [42], BERT [43], DistilBERT [44], and reward models for aligning LLMs with human feedback [45]. Recent works have extended these methods to more challenging scenarios, including handling adversarial attacks [46]–[48], short texts such as tweets and reviews [49], black-box settings under diverse prompts [50], [51], and accommodating statistical inference [52].
Rewrite-based methods either use the distance between the observed text and its rewritten version as an input feature for training the classifier [53]–[56], or apply ML to fine-tune the the rewriting model itself to improve the detection accuracy [57].
Other methods extract features beyond logits or rewrite-based distances, and then apply ML algorithms to these features for classification. Examples of features being utilized range from classical N-grams and term frequency–inverse document frequency widely used in natural language processing [39], to more complex representations such as various combinations of features constructed based on token probabilities [58], cross-entropy loss between the text and a surrogate LLM [59], hidden latent representations [60] and features learned via multi-level contrastive learning [61], and even classification probabilities of fine-tuned LLMs [62].
Our proposal falls under the category of ML-based, rewrite-based detection. We study a commonly encountered setting in practice, where LLM-authored text is generated using prompts that are unobserved by the detector. Our main contributions are as follows:
Methodologically, we develop a new rewrite-based method for detecting LLM-generated text. Unlike existing approaches that primarily employ a fixed distance to compare the original text with its rewritten version, we propose to adaptively learn this distance via ML. Our proposal better discriminates between LLM- and human-authored text (see Figure 2 for a graphical illustration), leading to substantial performance gains.
Theoretically, we develop a geometric approach to demystify the rationale behind rewrite-based methods (see Figure 1 for illustration and Proposition 1 for the detailed statement). We next show that these methods generalize well to unobserved prompts (Proposition 2). Finally, we demonstrate the rationale for learning a distance function rather than relying on a fixed distance (Proposition 3).
Empirically, we conduct comprehensive experiments across 24 datasets, 7 target language models, and 3 types of unseen prompts, covering over 100 settings. Our results show that: (i) our approach outperforms 12 state-of-the-art methods, achieving average relative improvements of 41.5% to 75.4% over the strongest baseline across different target LLMs baseline (Sections 4.1 and 4.2); (ii) our approach is more robust than existing methods under adversarial attacks (Section 4.3); (iii) learning the distance function provides substantial benefits, with an average relative improvement of 96% over using a fixed distance (see the ablation study in Section 4.4).
In this section, we present a geometric framework for understanding rewrite-based detection methods, revealing their underlying rationale and demonstrating their robustness to unseen prompts.
Let \(\boldsymbol{X}\) denote the target text under detection. We study the problem of determining whether \(\boldsymbol{X}\) is authored by a suspected target LLM, or by a human. Rewrite-based methods are straightforward to describe: they first prompt the target LLM to rephrase the original text and then measure the discrepancy between the original text \(\boldsymbol{X}\) and the LLM’s reconstruction (denoted by \(\mathcal{R}(\boldsymbol{X})\)) under a distance metric \(d\). These methods rely on the observation that, compared to human-authored text, machine-generated text should be closer to its reconstruction [33], [53]. In the following, we will formally prove this assertion from a geometric perspective.
Building intuition. We begin with some notations and hypotheses. Let \((\mathcal{X}, \mathcal{B})\) denote a measurable space of texts (after embedding).
Assumption 1. Assume \(\mathcal{X}\) is a Hilbert space with inner product \(\langle \cdot, \cdot \rangle\), induced norm \(|\cdot|\), and metric \(d^*(x,y) \mathrel{\vcenter{:}}= |x - y|\) for any \(x, y \in \mathcal{X}\).
This assumption is reasonable since texts are typically mapped into a vector space where each token is represented by a scalar [63], and padding is commonly applied to ensure all texts share the same dimensionality.
Let \(\mathcal{H}\) and \(\mathcal{M}\) denote the subspaces corresponding to texts authored by humans and the target LLM, respectively. We use \(p\) and \(q\) to represent their respective probability distributions. We also define the projection operator \(\Pi\) onto \(\mathcal{M}\), \[\label{eq:projection-operator} \Pi_{\mathcal{M}}(x)\;=\;\arg\min_{y\in\mathcal{M}} d^*(x,y),\tag{1}\] which projects a given text \(x\in \mathcal{X}\) to its closest point in \(\mathcal{M}\), produced by the target LLM.
Assumption 2. \(q\) is the projection of \(p\) under \(\Pi_{\mathcal{M}}\), i.e., if \(\boldsymbol{X}\sim p\) then \(\Pi_{\mathcal{M}}(\boldsymbol{X})\sim q\).
Assumption 2 is our key hypothesis, which reflects the geometric relationship between human- and LLM-authored text. Intuitively, it implies that all LLM-generated texts can be viewed as a projection of human-written text onto a specific subspace. This assumption is reasonable because (i) LLMs are trained on massive corpora of human-authored text with the objective of approximating the distribution of human language; (ii) LLM’s output space is constrained by the model’s architecture and learned parameters, and is thus different from the human text space. Therefore, the mapping from human text to LLM-generated text can be interpreted as a projection: a transformation that preserves semantic meanings while restricting outputs to the region defined by the model.
Assumption 3. For any human-written text \(x\in \mathcal{H}\), \(\mathcal{R}(x)\) has the same probability distribution function to \(\mathcal{R}(\Pi_{\mathcal{M}}(x))\).
Here, for a fixed text \(x\), we allow its reconstruction \(\mathcal{R}(x)\) to be random. This is because LLM outputs are typically stochastic due to the use of a nonzero temperature during inference. Assumption 3 essentially requires the reconstructions of a human-written text \(x\) and its projection \(\Pi_{\mathcal{M}}(x)\) to share the same distribution. This holds when the reconstruction can be written as \[\begin{align} \label{eqn:addnoise} \mathcal{R}(x)=\Pi_{\mathcal{M}}(x)+e, \end{align}\tag{2}\] for some random error \(e\) that lies on the space of \(\mathcal{M}\). Equation 2 suggests that the rewriting process can be viewed as a two-step procedure: first, the input text is projected onto the LLM subspace, and then a small perturbation \(e\) is added to the projected text, while preserving the projected text’s semantic meaning.
Proposition 1. Under Assumptions 1, 2 and 3, we have \[\begin{align} \mathbb{E}_{\boldsymbol{X}\sim p}\big[d^*(\boldsymbol{X}, \mathcal{R}(\boldsymbol{X}))\big] \ge \mathbb{E}_{\boldsymbol{X}\sim q}\big[d^*(\boldsymbol{X}, \mathcal{R}(\boldsymbol{X}))\big], \end{align}\] with equality if and only if \(p\) is supported on \(\mathcal{M}\).
Proposition 1 formally establishes the validity of rewrite-based methods, and proves that human-written text’s reconstruction error (the distance between a text and its reconstruction) is on average larger than that of LLM-generated text. The equality holds only under the idealized scenario where the LLM’s output space perfectly replicates the human text space.
Intuitively, this result follows because reconstructions always lie within the LLM subspace \(\mathcal{M}\), whereas human-authored text may lie farther away from \(\mathcal{M}\). Figure 1 provides a graphical illustration: the reconstruction error for human text (\(d_1\)) is clearly larger than that for LLM-generated text (\(d_2\)).
Generalization to unseen prompts. In practice, LLM-generated text is often produced under a variety of writing prompts (e.g., “polish this paragraph” or “help me rephrase”). The presence of such prompts induces a distributional shift: the resulting LLM-generated text no longer follows the original distribution \(q\), but instead depends on the specific prompt, which we denote by \(q_{\textrm{prompt}}\). This shift is illustrated in Figure 1, where the prompt alters the location of the generated text in the embedding space.
Rewrite-based methods can generalize effectively to such shifts, provided that the perturbation \(e\) in equation 2 does not substantially distort the semantic meaning of \(\Pi_{\mathcal{M}}(x)\). We formalize this intuition in the following proposition.
Proposition 2. Assume equation 2 holds. Let \(\epsilon>0\) denote some positive constant such that \(|e|\le \epsilon\) almost surely. Then under Assumption 1, we have \[\begin{align} \mathbb{E}_{\boldsymbol{X}\sim p}\big[d^*(\boldsymbol{X}, \mathcal{R}(\boldsymbol{X}))\big]-\mathbb{E}_{\boldsymbol{X}\sim q_{\textrm{prompt}}}\big[d^*(\boldsymbol{X}, \mathcal{R}(\boldsymbol{X}))\big]\ge \mathbb{E}_{\boldsymbol{X}\sim p} |\boldsymbol{X} - \Pi_{\mathcal{M}}(\boldsymbol{X})|- O(\epsilon). \end{align}\]
Proposition 2 provides a lower bound to quantify the difference in reconstruction error between human- and LLM-authored text. The bound depends on two factors: (i) the average gap between human and LLM-generated text, characterized by the norm of the projection \(\mathbb{E}_{\boldsymbol{X}\sim p} |\boldsymbol{X} - \Pi_{\mathcal{M}}(\boldsymbol{X})|\); (ii) the magnitude of the perturbation \(e\).
Figure 1 offers a graphical illustration: despite the shift introduced by the prompt, as long as \(e\) remains small, the reconstruction error for human text (\(d_1\)) can still be substantially larger than that for LLM-generated text (\(d_3\)). In practice, minimizing \(e\) requires careful design of the rewriting prompt to preserve the input text’s semantic meaning. This can be achieved through prompt engineering or by adaptively learning the rewrite model [57].
Limitations of existing approaches. We begin by discussing the limitations of existing logits-based and rewrite-based detection methods to better motivate our proposed approach:
Logit-based methods, such as DetectGPT [26] and Fast-DetectGPT [28], construct the detection statistics using the log-probability \(\log q(x)\) of the text. However, their performance tends to degrade when the text is generated under unseen prompts (see the first two panels of Figure 2 for illustration). This arises because the true conditional distribution \(\log q(x \mid \text{prompt})\) differs from the marginal distribution \(\log q(x)\) used by the detector, leading to the misspecification of the detection statistic.
The effectiveness of rewrite-based methods relies on choosing an appropriate distance function to distinguish human- from LLM-authored text, and the optimal distance function may differ largely from standard Euclidean distance due to the complex geometry of text embeddings. Nonetheless, existing rewrite-based methods often use fixed, hand-crafted distance, such as N-gram-based distance [33], Levenshtein distance [53], and negative BERTScore or BARTScore [64], [65], which may not generalize well across target language models, datasets or unobserved prompts.
To elaborate on the second point, we provide a proposition below to mathematically characterize the form of the optimal distance function.
Proposition 3. Consider the class of distance functions \(d\) whose range is bounded between \(0\) to and some positive constant \(M>0\). Within this function class, and under mild regularity conditions (see Appendix 6), any distance function \(d_{\tiny{opt}}\) satisfying \[\begin{align} d_{\tiny{opt}}(\boldsymbol{X},\boldsymbol{Y})=\left\{\begin{array}{ll} 0, & \textrm{if~both}~\boldsymbol{X}~\textrm{and}~\boldsymbol{Y}\in \mathcal{M}; \\ M, & \textrm{if~one~of}~\boldsymbol{X}~\textrm{or}~\boldsymbol{Y}\in\mathcal{M}~\textrm{and~the~other}\in\mathcal{H}\cap \mathcal{M}^c, \end{array} \right. \end{align}\] maximizes the gap in the reconstruction error \[\begin{align} \mathbb{E}_{\boldsymbol{X}\sim p}\big[d(\boldsymbol{X}, \mathcal{R}(\boldsymbol{X}))\big]-\mathbb{E}_{\boldsymbol{X}\sim q_{\textrm{prompt}}}\big[d(\boldsymbol{X}, \mathcal{R}(\boldsymbol{X}))\big]. \end{align}\]
Proposition 3 shows that the optimal distance function should assign the smallest possible distance (zero) when both the input and rewritten text are generated with the LLM, and the largest distance \(M\) when one is LLM-generated and the other is human-written. Crucially, this optimal distance depends on the target LLM to be detected, since different LLMs induce different generative subspaces \(\mathcal{M}\). However, existing rewrite-based detectors rely entirely on fixed distance functions (e.g., editing distance, embedding similarity). As a result, a distance that works well for one model may perform poorly with another, limiting their ability to generalize across different LLMs.
Our proposal. Motivated by the aforementioned limitations, we adopt the rewrite-based approach, and propose to adaptively learn the distance function to improve the detection performance. More specifically, assume we have access to a human-authored corpus \(\mathcal{D}_h\) and an LLM-generated corpus \(\mathcal{D}_m\), both of which are readily available in practice. For instance, \(\mathcal{D}_h\) can be obtained by web-scraping Wikipedia, while \(\mathcal{D}_m\) can be constructed by prompting the target LLM (e.g., GPT, Gemini, or Grok). We next learn the distance function \(d\), parameterized by some parameter \(\phi\), that maximizes the discrepancy between the reconstructions errors: \[\begin{align} \mathbb{E}_{\boldsymbol{X}\sim D_h}\big[d(\boldsymbol{X},\mathcal{R}(\boldsymbol{X}))\big]-\mathbb{E}_{\boldsymbol{X}\sim D_m}\big[d(\boldsymbol{X},\mathcal{R}(\boldsymbol{X}))\big]. \end{align}\] In our implementation, we parameterize the distance function via \[\label{eq:practical-distance} d_{\phi}(\boldsymbol{X}_1, \boldsymbol{X}_2) = \left| \frac{\log p_{\phi}(\boldsymbol{X}_1)}{\texttt{len}(\boldsymbol{X}_1)} - \frac{\log p_{\phi}(\boldsymbol{X}_2)}{\texttt{len}(\boldsymbol{X}_2)} \right|,\tag{3}\] where \(p_{\phi}\) is a language model parameterized by \(\phi\) and \(\texttt{len}(\cdot)\) computes the number of tokens of the input text. It is straightforward to show that \(d_{\phi}\) in equation 3 satisfies the property of a (pseudo)-distance: (i) It is non-negative; (ii) It equals zero whenever \(\boldsymbol{X}_1 = \boldsymbol{X}_2\); (iii) It satisfies the triangle inequality.
Our choice of equation 3 is also motivated by the form of the optimal distance function \(d_{\textrm{opt}}\) in Proposition 3. It can be viewed as a soft relaxation of \(d_{\textrm{opt}}\) which is binary and involves hard indicators, making the objective function continuous and the optimization tractable. Notably, when \(p_{\phi}\) assigns any \(\boldsymbol{X}\in \mathcal{M}\) a probability proportional to \(\kappa^{\textrm{len}(\boldsymbol{X})}\) for some \(0<\kappa<1\), the distance between any two texts produced by the LLM will be exactly zero. To the contrary, when \(p_{\phi}\) assigns very low probability to human-written text, the resulting distance between human- and LLM-authored text will be large.
Our above discussion also highlights the need to adaptively learn the language model \(p_{\phi}\) as opposed to using a fixed model. The ideal \(p_{\phi}\) should: (i) assign low probability to human-authored text; (ii) assign probability more uniformly across tokens for LLM-generated text. This differs from conventional LLMs, which aim to produce coherent, human-like text and therefore tend to assign high probability to human-authored text. Empirically, as demonstrated in the last two panels of Figure 2, the learned distance more effectively distinguishes between human- and LLM-authored text compared to a fixed distance. Our experiments in Section 4.4 also show that, the learned distance function yields substantial improvements over using the initial pre-trained LLM.
To solve the optimization, we initialize \(p_{\phi}\) with a pre-trained LLM and fine-tune a small subset of its parameters to facilitate the computation. This can be done by updating only the final layer or employing low-rank adaptation [66]. Furthermore, since the rewritten text \(\mathcal{R}(\boldsymbol{X})\) is stochastic, we mitigate its randomness by generating multiple reconstructions. Given a text \(\boldsymbol{X}\), we obtain \(K\) reconstructions \(\widetilde{\boldsymbol{X}}_1, \ldots, \widetilde{\boldsymbol{X}}_K\), and estimate the reconstruction error as the average: \(K^{-1}\sum_{k=1}^K d(\boldsymbol{X}, \widetilde{\boldsymbol{X}}_k)\). We classify \(\boldsymbol{X}\) as LLM-generated if this value is smaller than a predetermined threshold, and as human-authored otherwise. We summarize our procedure in Figure 3.
We conduct extensive experiments to evaluate the effectiveness of our approach. To save space, we defer additional implementation details to Appendix 9. Our empirical study is designed to answer the following three questions:
How does our method perform compared to state-of-the-art approaches under different prompts?
How robust is our method under adversarial attacks?
To what extent does learning the distance improve the detection accuracy?
To answer the first question, we compare our method, denoted as L2D (short for learn-to-distance), against 12 representative baseline detectors in Sections 4.1 and 4.2, covering both zero-shot (left) and ML-based methods (right):
2
We also employ 24 datasets and consider 6 commonly used target LLMs such as Llama-3-70B-Instruct [68], Claude-3.5, GPT series [1], [69], and Gemini models [4], [70] for generating LLM-written text.
To answer the second and third questions, we further consider settings under paraphrasing and decoherence attacks in Section 4.3 and compare against a variant of our approach that uses the initial pre-trained model \(p_{\phi}\) without fine-tuning as the distance function in Section 4.4.
Throughout, we have taken care to ensure fairness in all experimental comparisons. Specifically: (i) Both the baseline methods and our algorithm use the same base model, google/gemma-2-9b-it, as the rewrite and/or scoring model to maintain
consistency. (ii) For each input text, we use the same set of rewritten texts across all rewrite-based algorithms to ensure a fair comparison. (iii) For algorithms such as ImBD that involve fine-tuning, we use the same optimization hyperparameters (e.g.,
number of epochs, learning rate) as ours across all cases to ensure fairness in training.
Finally, the area under the curve (AUC) is used as the metric for evaluation.
We first evaluate our method on the dataset released by [57]3, which consists of human-written text from 21 domains, including academic writing, business, code, sports and religion. For each human-written sample, four LLM-generated versions were created using Llama-3-70B-Instruct, Gemini 1.5 Pro, GPT-3.5 Turbo and GPT-4o, respectively, yielding a total of 84 settings. Refer to [57] for the detailed prompts used to produce these LLM-generated texts.
Results are reported in Tables ¿tbl:tab:exp-data-GPT-3-Turbo?, ¿tbl:tab:exp-data-GPT-4o? and Tables ¿tbl:tab:exp-data-Llama-3-70B? – ¿tbl:tab:exp-l2r? in Appendix 7. It can be seen that our method achieves the best performance across nearly all combinations of datasets and target models. We focus on comparison against four baselines: (i) FDGPT, a training-free, logits-based zero-shot approach; (ii) ADGPT and (iii) ImBD, both ML-based variants of FDGPT. We include them because, similar to our algorithm, these methods require training. Note that ImBD typically ranks second overall and is the strongest among logits-based approaches; (iv) L2R, a rewrite-based method that also employs ML but learns the rewrite model rather than the distance function. We make two observations:
First, our approach consistently achieves substantially larger AUC scores than FDGPT. Notice that, in Tables ¿tbl:tab:exp-data-GPT-3-Turbo?, ¿tbl:tab:exp-data-GPT-4o? and ¿tbl:tab:exp-data-Gemini-1465-Pro?, the training and testing data differ in terms of models or data contexts, which reduces the inherent advantage of ML-based approaches over zero-shot methods such as FDGPT. Even under these shifts, our method continues to achieve the best performance in most cases. This comparison highlights our algorithm’s robustness to distributional shifts between the training and testing data, as well as its effectiveness relative to zero-shot methods.
Second, as shown in Tables ¿tbl:tab:exp-data-GPT-3-Turbo?, ¿tbl:tab:exp-data-GPT-4o?, ¿tbl:tab:exp-data-Llama-3-70B? and ¿tbl:tab:exp-data-Gemini-1465-Pro?, our approach outperforms ImBD on most datasets (16 – 19 out of 21), and the relative gain can reach up to 89.4% (see the rightmost column). This comparison highlights the advantage of rewrite-based methods over logits-based methods.
Third, since L2R does not provide public code, we directly compare against the reported results in their paper. Table ¿tbl:tab:exp-l2r? shows that our method outperforms L2R on 20 out of 21 datasets, and often by a large margin. This comparison suggests that, compared with learning to rewrite, learning a distance function is more effective for rewrite-based detection.
width=
Next, following [51], we examine three scenarios that use different types of unseen prompts to generate LLM text: (i) rewrite, where the LLM rewrites a human-authored text while preserving its semantic meaning; (ii) expand, where the LLM elaborates on the text according to a style randomly selected from various options (e.g., formal, literary); and (iii) polish, where the LLM refines the text based on the randomly chosen style.
We also consider three widely used benchmark datasets [28], [51]: (i) Wiki, which consists of Wikipedia-style question answering data [71]; (ii) Story, which focuses on story generation [72]; and (iii) News, which is concerned with news summarization [73].
We further generate LLM-authored text using three recent and popular proprietary models: (i) GPT-4o; (ii) Claude-3.5-Haiku and (iii) Gemini-2.5-Flash. This yields a total of 27 settings. Details on how these texts were generated are provided in Appendix 9.
Table 1 presents the AUC scores for all detectors across the 27 combinations of datasets, target models, and types of prompts. Our method achieves the best performance in nearly all cases, whereas ImBD (logits-based) or RAIDAR (rewrite-based) works as the second best. The relative gain over these best baselines is 70.11% on average, which again highlights (i) the advantage of rewrite-based methods over logits-based methods in settings with unseen prompts; and (ii) the effectiveness of learning an adaptive distance function over using a fixed distance in rewrite-based approaches.
| Dataset | Method | Claude-3.5 | GPT-4o | Gemini | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 3-6(lr)7-10(lr)11-14 | rewrite | polish | expand | Avg. | rewrite | polish | expand | Avg. | rewrite | polish | expand | Avg. | |
| News | Likelihood | 0.598 | 0.604 | 0.645 | 0.616 | 0.572 | 0.587 | 0.539 | 0.566 | 0.594 | 0.579 | 0.732 | 0.635 |
| LRR | 0.594 | 0.626 | 0.636 | 0.619 | 0.633 | 0.620 | 0.559 | 0.604 | 0.656 | 0.601 | 0.717 | 0.658 | |
| Binoculars | 0.555 | 0.634 | 0.709 | 0.633 | 0.535 | 0.567 | 0.631 | 0.578 | 0.507 | 0.632 | 0.589 | 0.576 | |
| IDE | 0.606 | 0.686 | 0.726 | 0.673 | 0.577 | 0.736 | 0.696 | 0.670 | 0.608 | 0.672 | 0.716 | 0.665 | |
| FDGPT | 0.524 | 0.610 | 0.686 | 0.607 | 0.508 | 0.561 | 0.641 | 0.570 | 0.507 | 0.617 | 0.586 | 0.570 | |
| BARTScore | 0.728 | 0.583 | 0.563 | 0.625 | 0.653 | 0.526 | 0.549 | 0.576 | 0.567 | 0.606 | 0.671 | 0.615 | |
| RoBERTa | 0.544 | 0.524 | 0.546 | 0.538 | 0.509 | 0.532 | 0.568 | 0.536 | 0.501 | 0.566 | 0.567 | 0.545 | |
| RADAR | 0.744 | 0.805 | 0.912 | 0.821 | 0.774 | 0.966 | 0.994 | 0.911 | 0.807 | 0.858 | 0.920 | 0.862 | |
| ADGPT | 0.518 | 0.616 | 0.569 | 0.567 | 0.617 | 0.644 | 0.561 | 0.608 | 0.514 | 0.543 | 0.502 | 0.520 | |
| RAIDAR | 0.934 | 0.919 | 0.942 | 0.932 | 0.882 | 0.900 | 0.866 | 0.882 | 0.800 | 0.948 | 0.921 | 0.890 | |
| ImBD | 0.920 | 0.915 | 0.986 | 0.940 | 0.866 | 0.978 | 0.985 | 0.943 | 0.877 | 0.952 | 0.966 | 0.932 | |
| L2D | 1.000 | 0.989 | 1.000 | 0.996 | 0.994 | 1.000 | 1.000 | 0.998 | 1.000 | 1.000 | 1.000 | 1.000 | |
| Abs. Gain (%) | 6.6 | 7.0 | 1.4 | 5.6 | 11.2 | 2.2 | 1.5 | 5.5 | 12.3 | 4.8 | 3.4 | 6.8 | |
| Rel. Gain (%) | 100.0 | 86.6 | 100.0 | 94.0 | 94.7 | 100.0 | 100.0 | 96.3 | 100.0 | 100.0 | 100.0 | 100.0 | |
| Wiki | Likelihood | 0.519 | 0.532 | 0.562 | 0.538 | 0.546 | 0.553 | 0.649 | 0.583 | 0.505 | 0.512 | 0.533 | 0.517 |
| LRR | 0.532 | 0.508 | 0.540 | 0.527 | 0.541 | 0.612 | 0.695 | 0.616 | 0.522 | 0.508 | 0.536 | 0.522 | |
| Binoculars | 0.608 | 0.667 | 0.762 | 0.679 | 0.619 | 0.717 | 0.862 | 0.733 | 0.571 | 0.768 | 0.793 | 0.711 | |
| IDE | 0.565 | 0.621 | 0.613 | 0.600 | 0.584 | 0.712 | 0.682 | 0.659 | 0.573 | 0.642 | 0.699 | 0.638 | |
| FDGPT | 0.587 | 0.646 | 0.739 | 0.658 | 0.597 | 0.712 | 0.867 | 0.725 | 0.557 | 0.748 | 0.791 | 0.699 | |
| BARTScore | 0.760 | 0.634 | 0.520 | 0.638 | 0.785 | 0.592 | 0.529 | 0.635 | 0.605 | 0.590 | 0.615 | 0.603 | |
| RoBERTa | 0.635 | 0.659 | 0.759 | 0.684 | 0.565 | 0.590 | 0.522 | 0.559 | 0.638 | 0.740 | 0.782 | 0.720 | |
| RADAR | 0.533 | 0.507 | 0.620 | 0.553 | 0.541 | 0.814 | 0.933 | 0.763 | 0.550 | 0.564 | 0.680 | 0.598 | |
| ADGPT | 0.518 | 0.616 | 0.569 | 0.567 | 0.617 | 0.644 | 0.561 | 0.608 | 0.514 | 0.543 | 0.502 | 0.520 | |
| RAIDAR | 0.889 | 0.900 | 0.920 | 0.903 | 0.845 | 0.871 | 0.851 | 0.856 | 0.848 | 0.927 | 0.950 | 0.908 | |
| ImBD | 0.952 | 0.954 | 0.976 | 0.961 | 0.875 | 0.967 | 0.986 | 0.943 | 0.874 | 0.964 | 0.956 | 0.931 | |
| L2D | 0.955 | 0.942 | 0.953 | 0.950 | 0.963 | 0.987 | 0.993 | 0.981 | 0.983 | 0.982 | 0.988 | 0.984 | |
| Abs. Gain (%) | 0.2 | — | — | — | 8.8 | 1.9 | 0.6 | 3.8 | 10.9 | 1.8 | 3.2 | 5.3 | |
| Rel. Gain (%) | 5.0 | — | — | — | 70.6 | 59.1 | 45.8 | 66.4 | 86.3 | 49.6 | 72.6 | 76.9 | |
| Story | Likelihood | 0.502 | 0.532 | 0.587 | 0.541 | 0.623 | 0.740 | 0.814 | 0.725 | 0.512 | 0.656 | 0.702 | 0.623 |
| LRR | 0.556 | 0.540 | 0.596 | 0.564 | 0.570 | 0.728 | 0.739 | 0.679 | 0.504 | 0.563 | 0.632 | 0.566 | |
| Binoculars | 0.595 | 0.663 | 0.755 | 0.671 | 0.674 | 0.739 | 0.806 | 0.740 | 0.624 | 0.832 | 0.927 | 0.794 | |
| IDE | 0.616 | 0.610 | 0.632 | 0.619 | 0.575 | 0.650 | 0.673 | 0.633 | 0.580 | 0.579 | 0.609 | 0.589 | |
| FDGPT | 0.571 | 0.635 | 0.743 | 0.650 | 0.655 | 0.735 | 0.808 | 0.733 | 0.603 | 0.000 | 0.918 | 0.507 | |
| BARTScore | 0.767 | 0.706 | 0.566 | 0.680 | 0.724 | 0.754 | 0.685 | 0.721 | 0.708 | 0.733 | 0.674 | 0.705 | |
| RoBERTa | 0.588 | 0.586 | 0.660 | 0.611 | 0.540 | 0.504 | 0.539 | 0.527 | 0.571 | 0.569 | 0.657 | 0.599 | |
| RADAR | 0.597 | 0.614 | 0.510 | 0.574 | 0.507 | 0.756 | 0.827 | 0.697 | 0.560 | 0.513 | 0.619 | 0.564 | |
| ADGPT | 0.755 | 0.746 | 0.789 | 0.763 | 0.617 | 0.698 | 0.655 | 0.657 | 0.729 | 0.692 | 0.658 | 0.693 | |
| RAIDAR | 0.861 | 0.767 | 0.847 | 0.825 | 0.831 | 0.872 | 0.831 | 0.845 | 0.848 | 0.866 | 0.907 | 0.874 | |
| ImBD | 0.954 | 0.905 | 0.976 | 0.945 | 0.933 | 0.985 | 0.964 | 0.961 | 0.979 | 0.990 | 0.993 | 0.987 | |
| L2D | 0.999 | 0.955 | 0.995 | 0.983 | 0.982 | 0.997 | 0.980 | 0.986 | 0.984 | 0.999 | 0.997 | 0.993 | |
| Abs. Gain (%) | 4.5 | 5.0 | 1.9 | 3.8 | 4.9 | 1.2 | 1.6 | 2.6 | 0.4 | 0.9 | 0.4 | 0.6 | |
| Rel. Gain (%) | 97.8 | 53.0 | 81.2 | 69.6 | 73.3 | 79.4 | 44.8 | 65.4 | 21.4 | 87.1 | 62.4 | 46.4 | |
3pt
Following [28], we further evaluate the robustness of our method against two types of adversarial attacks: (i) Rephrasing, where the LLM-written text is further paraphrased by a T5-based paraphraser before detection; (ii) Decoherence, where in each LLM-generated sentence containing more than 20 words, two adjacent words are randomly swapped. Both attacks are designed to reduce the coherence of LLM-generated text and have been shown to degrade the detection accuracy of existing detectors [28].
We conduct experiments on the same three datasets used in Section 4.2, resulting in a total of six settings. For comparison, we focus on ImBD and RAIDAR, as they achieve the second best performance on these datasets.
Figure 4 reports the AUC scores with and without adversarial attacks. While RAIDAR achieves comparable or superior AUCs on Story and Wiki in the absence of attacks, its AUC drops substantially under attacks, failing to maintain its lead. Similarly, ImBD’s AUC declines considerably on Wiki under the rephrasing attack. In contrast, our method remains robust: its AUC either increases or remains unchanged on News, and only slightly decreases on other two datasets, achieving the best performance in each setting. This highlights the resilience of our approach to adversarial attacks and demonstrates its potential for reliable deployment in real-world scenarios.
We conduct an ablation study to compare against a version of our approach that uses the initial language model \(p_{\phi}\) to construct the distance (FD, denoting a fixed distance). We consider the same settings to Section 4.2 and report the AUCs in Table 2. Our method consistently outperforms FD, with an average improvement of 97.1%. These results clearly demonstrate the advantage of learning the distance metric over fixing the distance.
This paper studies the detection of LLM-generated text. Our theoretical analysis offers geometric insights to demonstrate the effectiveness of rewrite-based approaches (Proposition 1) and their robustness to unseen prompts (Proposition 2). Methodologically, we go beyond existing rewrite-based methods by adaptively learning the distance function, which is theoretically grounded (Proposition 3) and delivers substantial empirical gains over both fixed-distance approaches (Section 4.4) and state-of-the-art detectors (Sections 4.1 and 4.2), while maintaining robustness against adversarial attacks (Section 4.3).
To conclude this paper, we remark that in our theoretical analysis, the assumptions were intentionally simplified (and thus stronger) to build geometric intuition behind these approaches. In Appendix 6, we have offered a more complex version of our theories under less restrictive assumptions. Finally, although our method achieves state-of-the-art detection accuracy in most settings, its computational cost remains relatively high and comparable to existing rewrite-based algorithms (e.g., RAIDAR), due to the need to generate multiple rewrites (see Appendix 7 for detailed runtime results). This represents a potential limitation. We also note that asynchronous rewriting and distance computation using a vLLM backend can improve computational efficiency for practical deployment.
Hongyi Zhou and Ying Yang’s research was partially supported by NSFC 12271286. The authors thank the anonymous referees and the area chair for their insightful and constructive comments, providing a significant improvement of the initial paper.
The research presented in this paper adheres to the ICLR Code of Ethics (https://iclr.cc/public/CodeOfEthics) in all respects.
We have made substantial efforts to ensure the reproducibility of this paper. The assumptions of our method are declared in Section 2, and the proofs of the theoretical results are provided in Appendix 6. The implementation details of our approach (e.g., the choice of hyperparameters) are described in Appendix 8. Additionally, the experimental setup and data generation procedures are explained in Section 4 and Appendix 9. Together, these descriptions provide sufficient information for others to reproduce both our theoretical and empirical results.
Proof of Proposition 1: We further assume \(\mathcal{M}\) is a closed convex set so that the projection operator is well-defined. Then for any \(x\in\mathcal{X}\) and \(y\in\mathcal{M}\), we have \[\langle x-\Pi_{\mathcal{M}}(x), y - \Pi_{\mathcal{M}}(x)\rangle \leq 0.\] Taking \(y = \mathcal{R}(x)\), it directly follows that \[\begin{align} d^*(x,\mathcal{R}(x)) &=& d^*(x,\mathcal{R}(x) -\Pi_{\mathcal{M}}(x) + \Pi_{\mathcal{M}}(x))\nonumber\\ &=& d^*(x,\Pi_{\mathcal{M}_m}(x))-2\langle x- \Pi_{\mathcal{M}}(x), \mathcal{R}(x) - \Pi_{\mathcal{M}}(x)\rangle + | \mathcal{R}(x) - \Pi_{\mathcal{M}}(x)| \nonumber\\ &\ge& d^*(\Pi_{\mathcal{M}}(x) , \mathcal{R}(x) ) \quad \text{ for all } x\in\mathcal{X}.\nonumber \end{align}\] Taking expectation on both sides with respect to \(\boldsymbol{X}\sim p\), we obtain \[\mathbb{E}_{\boldsymbol{X}\sim p}\left\{d^*(\boldsymbol{X},\mathcal{R}(\boldsymbol{X}))\right\} \geq \mathbb{E}_{\boldsymbol{X}\sim p}\left\{d^*(\Pi_{\mathcal{M}}(\boldsymbol{X}) , \mathcal{R}(\boldsymbol{X}) )\right\} = \mathbb{E}_{\boldsymbol{X}\sim p}\left\{d^*(\Pi_{\mathcal{M}}(\boldsymbol{X}) , \mathcal{R}(\Pi_{\mathcal{M}}(\boldsymbol{X})) )\right\},\] where the last equality follows from Assumption 3. Finally, Assumption 2 yields that \[\mathbb{E}_{\boldsymbol{X}\sim p}\left\{d^*(\Pi_{\mathcal{M}}(\boldsymbol{X}) , \mathcal{R}(\Pi_{\mathcal{M}}(\boldsymbol{X})) )\right\} = \mathbb{E}_{\boldsymbol{X}\sim q}\left\{d^*(\boldsymbol{X} , \mathcal{R}(\boldsymbol{X}) )\right\}.\] Thus, the conclusion of Proposition 1 follows.
Proof of Proposition 2: According to the definition of projection operator \(\Pi_\mathcal{M}\) and the fact that \(\mathcal{R}(\boldsymbol{X})\) is supported on \(\mathcal{M}\), it is obvious that \[\label{eqn:prop2-term1} d^*(\boldsymbol{X},\mathcal{R}(\boldsymbol{X})) \geq d^*(\boldsymbol{X},\Pi_{\mathcal{M}}(\boldsymbol{X})).\tag{4}\] Furthermore, the distribution of \(q_{\texttt{prompt}}\) is also supported on \(\mathcal{M}\). Therefore, combining equation equation 2 , we obtain \[\begin{align} \label{eqn:prop2-term2} \mathbb{E}_{\boldsymbol{X}\sim q_{prompt}}[d^*(\boldsymbol{X},\mathcal{R}(\boldsymbol{X}))] &=& \mathbb{E}_{\boldsymbol{X}\sim q_{prompt}}[d^*(\Pi_{\mathcal{M}}(\boldsymbol{X}),\mathcal{R}(\boldsymbol{X}))] \nonumber\\ &=&\mathbb{E}_{\boldsymbol{X}\sim q_{prompt}}[d^*(\Pi_{\mathcal{M}}(\boldsymbol{X}),\Pi_{\mathcal{M}}(\boldsymbol{X}) + e)]\nonumber\\ &=& \mathbb{E}_{\boldsymbol{X}\sim q_{prompt}}|e| \leq \epsilon. \end{align}\tag{5}\] Combining inequality equation 4 and equation 5 , the conclusion of Proposition 2 then follows.
Additional Results. The geometric assumptions in Section 2 were intentionally simplified to make our propositions interpretable. In fact, these assumptions could be relaxed to a more realistic setting. Specifically, we only assume
Human- and LLM-generated text lie on two nonlinear manifolds \(\mathcal{H}\) and \(\mathcal{M}\subseteq \mathcal{X}\), with their intrinsic dimensions \(d_h>d_m\);
Rewriting satisfies \(\mathbb{E} [d^*(\mathcal{R}(x),x)]\le \varepsilon_0\) for any \(x\in \mathcal{M}\) and some small \(0<\varepsilon_0<1\), whereas \(\sup_{x_1,x_2\in \mathcal{M}\cup \mathcal{H}}d^*(x_1,x_2)=1\);
Human-written text distribution \(p\) is absolutely continuous with respect to some \(d_h\)–dimensional volume measure \(\mu\) on \(\mathcal{H}\) with a bounded density.
Notice that (i) relaxes the linearity condition in Assumption 2 and does not assume that \(\mathcal{M}\) is a projection or subspace of \(\mathcal{H}\). Meanwhile, the assumption \(d_h>d_m\) is well supported by empirical findings [74] which demonstrate that human text typically has intrinsic dimension of 8.5 - 10, whereas LLM-generated text has a dimension of only 6 – 8 [74].
Furthermore, (ii) only requires that, for LLM-generated text, its reconstruction error is on average small relative to the maximum distance in the space. It does not require the error to be almost surely small as in the additive noise model, nor does it require equivalence in Assumption 3. In our empirical study, we find the ratio of this expected reconstruction error to the maximum distance is consistently very small across multiple datasets (see Table ¿tbl:tab:dataset95target95ratio?).
Under these realistic assumptions, we obtain the following proposition:
Proposition. Let \(\kappa := d_h - d_m\). Under Assumptions (i)–(iii), for a human text \(\boldsymbol{X}\) and an LLM-generated text \(\boldsymbol{Y}\), the inequality \[\mathbb{E}_{\widetilde{\boldsymbol{X}}\sim \mathcal{R}(\boldsymbol{X})}[d^*(\boldsymbol{X},\widetilde{\boldsymbol{X}}))]>\mathbb{E}_{\widetilde{\boldsymbol{Y}}\sim\mathcal{R}(\boldsymbol{Y})}[d^*(\boldsymbol{Y},\widetilde{\boldsymbol{Y}})]\] holds with probability at least \(1-O(\varepsilon_0^\kappa)\), where the expectations on both sides average out fluctuations in the rewriting process.
width=0.8
Remark 1: Given that empirical results suggest \(\kappa\) is approximately 1.5 or 2 [74], the probability \(1-O(\varepsilon_0^\kappa)\) can be very close to \(1\) given that \(\varepsilon_0\) is sufficiently small, which in turn proves that the reconstruction error for human-written text is, on average, larger than that for LLM-generated text.
Remark 2: The proof of the proposition relies on leveraging the assumption that \(\mathcal{M}\) has a strictly lower intrinsic dimension than \(\mathcal{H}\). Consequently, its \(\varepsilon-\)neighborhood overlaps with at most an \(O(\varepsilon^\kappa)\) fraction of the human-text manifold. As a result, only a small proportion of human-written text lie within the \(\varepsilon-\)neighborhood of \(\mathcal{M}\); most human text lie farther away, leading to the a larger reconstruction error.
Proof: Formally, for \(\varepsilon>0\), we denote the \(\varepsilon_0\)–tube (w.r.t.\(d^\star\)) around \(\mathcal{M}\) as \[\mathcal{N}_{\varepsilon_0}(\mathcal{M}):=\{x\in \mathcal{X}:\;d^*\left(x,\mathcal{M}\right)\le \varepsilon_0\}.\] Classical tube formulas imply \[\mu\!\big(\mathcal{H}\cap \mathcal{N}_{\varepsilon_0}(\mathcal{M})\big)\;=\;O(\varepsilon_0^{\kappa})\quad\text{as }\varepsilon_0\downarrow 0.\] Hence, under the bounded density assumption in (iii), \[\label{ref:someeq} \mathbb{P}_{\boldsymbol{X}\sim p}\!\big\{d^*(\boldsymbol{X},\mathcal{M})<\varepsilon_0\big\} \;\le\;C\,\mu\!\big(\mathcal{H}\cap \mathcal{N}_{\varepsilon_0}(\mathcal{M})\big) \;=\;O(\varepsilon_0^\kappa)\tag{6}\] for some constant \(C\). Therefore, with probability at least \(1 - O(\varepsilon_0^\kappa)\), \[\begin{align} \mathbb{E}_{\widetilde{\boldsymbol{X}}\sim \mathcal{R}(\boldsymbol{X})}[d^*(\boldsymbol{X},\widetilde{\boldsymbol{X}})]-\mathbb{E}_{\widetilde{\boldsymbol{Y}}\sim \mathcal{R}(\boldsymbol{Y})}[d^*(\boldsymbol{Y},\widetilde{\boldsymbol{Y}})] \ge d^*(\boldsymbol{X},\mathcal{M})-\varepsilon_0>0. \end{align}\] The proof is hence completed.
Proof of Proposition 3: Given that \(d\) is bounded between \(0\) and some positive constant \(M\), we have \(\mathbb{E}_{\boldsymbol{X}\sim p}[d(\boldsymbol{X},\mathcal{R}(\boldsymbol{X})]\leq M\) and \(\mathbb{E}_{\boldsymbol{X}\sim q_{\textrm{prompt}}}[d(\boldsymbol{X},\mathcal{R}(\boldsymbol{X})]\geq 0\). Therefore, the reconstruction error is upper bounded by \(M\). In what follows, we prove that by choosing \(d = d_{\tiny{opt}}\), we can achieve this upper bound.
To prove this, we assume (i) – (iii) hold. As commented earlier, these assumptions are mild and are supported by empirical observations. Under these assumptions, letting the value of \(\epsilon_0\) in equation 6 approach \(0\), it follows that \[\begin{align} \mathbb{P}_{\boldsymbol{X}\sim p}(\boldsymbol{X}\in \mathcal{M})=0. \end{align}\] Additionally, notice that the rewrite \(\mathcal{R}(\boldsymbol{X})\) always lies in \(\mathcal{M}\), it follows that \[\mathbb{E}_{\boldsymbol{X}\sim p}[d_{opt}(\boldsymbol{X},\mathcal{R}(\boldsymbol{X})] = \mathbb{E}_{\boldsymbol{X}\sim p}[d_{opt}(\boldsymbol{X},\mathcal{R}(\boldsymbol{X})\mathbb{I}(\boldsymbol{X}\in\mathcal{H} \backslash \mathcal{M})] = M.\] Additionally, since \(q\) is supported on \(\mathcal{M}\), it follows that \[\mathbb{E}_{\boldsymbol{X}\sim q_{\textrm{prompt}}}[d_{opt}(\boldsymbol{X},\mathcal{R}(\boldsymbol{X})] = 0.\] Thus, under distance \(d_{opt}\), the reconstruction error achieves the upper bound, which completes the proof.
We first provide an outline of our algorithm, which can be summarized into the following four steps:
Collect a dataset of human-authored text (denoted by \(\mathcal{D}_h\)) and prompt the target LLM (e.g., GPT-4o) to obtain an LLM-generated dataset (denoted by \(\mathcal{D}_m\)).
For each text \(X\in \mathcal{D}_h\cup \mathcal{D}_m\), prompt an open-source lightweight LLM (specified below) to rewrite it \(K\) times, and denoted the \(K\) reconstructions by \(\widetilde{\boldsymbol{X}}_1,\cdots,\widetilde{\boldsymbol{X}}_K\).
Learn a distance function \(d_\phi\) that maximizes the difference in reconstruction errors between \(\mathcal{D}_h\) and \(\mathcal{D}_m\): \[\max_\phi \;\mathbb{E}_{X \sim \mathcal{D}_h}\left[ \frac{1}{K}\sum_{k=1}^K d_\phi(\boldsymbol{X}, \widetilde{\boldsymbol{X}}_k) \right] - \mathbb{E}_{X \sim \mathcal{D}_m}\left[ \frac{1}{K}\sum_{k=1}^K d_\phi(\boldsymbol{X}, \widetilde{\boldsymbol{X}}_k) \right],\] where \(d_\phi(\boldsymbol{X}_1, X_2) = | \log p_\phi(\boldsymbol{X}_1)/|X_1| - \log p_\phi(\boldsymbol{X}_2)/|X_2| |\) and \(p_\phi\) is a language model whose architecture will be detailed below.
Given an input text \(X\), obtain its reconstructions \(\widetilde{\boldsymbol{X}}_1,\cdots,\widetilde{\boldsymbol{X}}_K\). If \[\frac{1}{K}\sum_{k=1}^K d_\phi(\boldsymbol{X}, \widetilde{\boldsymbol{X}}_k),\] exceeds a predefined threshold, classify \(X\) as human-authored.
width=
width=
In our experiments, the training and testing data differ in terms of models or data contexts. Specifically, in Tables ¿tbl:tab:exp-data-GPT-3-Turbo? and ¿tbl:tab:exp-data-GPT-4o?, we train the distance function on text generated by GPT-4 and evaluate its performance to detect GPT-3.5-Turbo, and vice versa. In Table ¿tbl:tab:exp-data-Gemini-1465-Pro?, we train the distance function on GPT-generated text but test it on text produced by Gemini. Thus, in all three tables, the training and testing models are either completely different or belong to the same family but correspond to different versions.
Moreover, all reported results therein are obtained via cross-fitting: we use one category of data (e.g., Story in Table 1) for testing and other categories (e.g., News and Wiki) for training. Consequently, the test data differ in content and domain from the training data.
Table 3 reports the average AUC and runtime of our method compared with RAIDAR, a state-of-the-art rewrite-based detector, in the setting of detecting text generated by GPT-3.5-Turbo (same to Table ¿tbl:tab:exp-data-GPT-3-Turbo?). As shown, our runtime is very close to that of RAIDAR – with only a slight increase – while achieving a substantial improvement in AUC. In addition, the reported runtime does not use a vLLM backend; incorporating vLLM could further reduce computational cost.
width=
| Dataset | Method | Claude-3.5 | GPT-4o | Gemini | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 3-6(lr)7-10(lr)11-14 | rewrite | polish | expand | Avg. | rewrite | polish | expand | Avg. | rewrite | polish | expand | Avg. | |
| News | FD | 0.541 | 0.539 | 0.576 | 0.552 | 0.525 | 0.515 | 0.579 | 0.540 | 0.576 | 0.613 | 0.645 | 0.611 |
| L2D | 1.000 | 0.989 | 1.000 | 0.996 | 0.994 | 1.000 | 1.000 | 0.998 | 1.000 | 1.000 | 1.000 | 1.000 | |
| Wiki | FD | 0.532 | 0.522 | 0.532 | 0.529 | 0.589 | 0.614 | 0.738 | 0.647 | 0.510 | 0.605 | 0.579 | 0.565 |
| L2D | 0.955 | 0.942 | 0.953 | 0.950 | 0.963 | 0.987 | 0.993 | 0.981 | 0.983 | 0.982 | 0.988 | 0.984 | |
| Story | FD | 0.612 | 0.647 | 0.728 | 0.662 | 0.683 | 0.821 | 0.892 | 0.799 | 0.641 | 0.800 | 0.856 | 0.766 |
| L2D | 0.999 | 0.955 | 0.995 | 0.983 | 0.982 | 0.997 | 0.980 | 0.986 | 0.984 | 0.999 | 0.997 | 0.993 | |
1.2pt
width=
| Method | AUC | Runtime (s) | Gain (Abs. & Rel.) | |
|---|---|---|---|---|
| RAIDAR | 0.762 | 6.348 | – | |
| L2D | 0.941 | 6.468 | 17.90% & 75.2% |
It is well known that varying the sampling temperature produces different outputs from LLMs, and adjusting temperature is a commonly used strategy in real-world LLM usage [75]. In practice, when collecting text from an LLM, the specific temperature setting is typically unknown. It is therefore important to evaluate whether our method remains robust when training and test data are generated with different temperatures.
Following the same data generation process described in Section 4.3, we extend the setting to include six temperature values: \(\{0.01, 0.2, 0.4, 0.6, 0.8, 1.0\}\). For evaluation, we partition the datasets into training and testing splits based on temperature. Specifically, one split uses \(\{0.2, 0.6, 0.8\}\) for training and \(\{0.01, 0.4, 1.0\}\) for testing, and the roles are reversed in the other split. This design mimics realistic scenarios where data collected at one set of temperatures are used to detect text generated at unseen temperatures.
As shown in Figure 6, our method achieves performance nearly identical to the case where training and test data share the same temperature. These results highlight the robustness of our approach under temperature variation.
Prompt for rewriting. The prompt is set as:
You are a rewriting expert and you would rewrite the text without missing the original details. Return ONLY the rewritten version. Do not explain changes, do not give multiple options, and do not add commentary. Original text:.
To generate rewritten texts, we employ an open-source model available on HuggingFace, i.e., google/gemma-2-9b-it. We recommend using an instruction fine-tuned variant, as it is more likely to produce faithful rewrite. In addition, the model
should contain at least a billion parameters, since smaller models often fail to generate reliable rewrite. Choosing a open-source LLM does not require access to proprietary models like ChatGPT and Grok, making our approach being affordable and
accessibility. We set the max_new_tokens as the 1.2 times of the number of tokens in \(\boldsymbol{X}\), and the min_new_tokens as the 0.8 times of the number of tokens in \(\boldsymbol{X}\).
Rewrite times \(K\). The parameter \(K\) plays a critical role in balancing computational cost and detection performance. Increasing \(K\) improves the accuracy of estimating \(\tau\), but at the expense of longer training time—since probabilities \(p_{\phi}(\widetilde{\boldsymbol{X}}_1), \ldots, p_{\phi}(\widetilde{\boldsymbol{X}}_K)\) must all be computed—and higher GPU memory requirements during backpropagation. Figure 5 illustrates the trade-off: while larger \(K\) generally improves performance, the gains diminish beyond small values, whereas the runtime and memory usage grow roughly linearly. Notably, as long as \(K > 1\), the AUC remains strong. Motivated by this observation, we adopt a modest choice of \(K=4\) throughout all experiments, striking a balance between accuracy and efficiency.
Fine-tuning setting. In our specific fine-tuning, we set the distance function as \(d_{\phi}(\boldsymbol{X}_1, \boldsymbol{X}_2) = |\log p_{\phi}(\boldsymbol{X}_1) / \texttt{len}(\boldsymbol{X}_1) - \log
p_{\phi}(\boldsymbol{X}_2) / \texttt{len}(\boldsymbol{X}_2)|\) where \(\texttt{len}(\boldsymbol{X}_k)\) is the number of tokens of \(\boldsymbol{X}_k\) (\(k=1,2\)). This normalization accounts for text length, as a longer text are expected to correspond to smaller log-likelihood. Without loss of generality, we set \(p_{\phi}\) as the model used
for generating the rewritten text. We fine-tune the model, employ LoRA [66] implemented in the peft library, with rank parameter set to 8,
lora_alpha set to 32, and lora_dropout set to 0.1, and the other parameters use the default settings.
This section describes the experimental setup in detail. It is worth noting that throughout all experiments, we use AUC as the evaluation metric, and the relative gain over the strongest baseline is computed as: \((\mathrm{Our AUC} - \mathrm{StrongestBaseline's AUC}) / (1.0 - \mathrm{StrongestBaseline's AUC})\).
Setup for learning-based methods. For fairness, we follow a consistent training protocol across training-based detectors. Specifically, for each method, we train on 10 out of the 21 datasets and evaluate on the remaining ones. We then repeat the process by swapping the training and test splits, ensuring that no evaluation data leaks into training and guaranteeing a fair comparison. For RoBERTa and RADAR, since only pre-trained checkpoints are publicly available, we directly use the models released on HuggingFace45. This setup also enables a reasonable comparison with L2R, which uses 70% of each dataset for training and the remainder for testing. In contrast, our method trains on fewer datasets and the evaluation datasets are out of domains yet still achieves better performance, highlighting the effectiveness of the learning procedure.
Setup for zero-shot methods. For zero-shot detectors, we employ the same open-source LLMs as surrogate models to compute their statistical measures. These include Likelihood, IDE, and LRR. Notice that, the implementation of IDE6 provide two method for estimating intrinsic dimension, one is based on persistence homology and another is based on maximum likelihood estimation [76]. Since the former requires a large amount of time on computing, we use maximum likelihood estimation in the experiments. For Binoculars and FDGPT, which require both a sampling model and a scoring model, we set \(p_{\phi}\) as the scoring model and use its corresponding base model as the sampling model. For BARTScore, which also involves rewriting, we align its rewriting step with our own method while using the pre-trained BARTScore model from HuggingFace7 to compute distances.
Data generation. We generate machine-generated texts with three state-of-the-art LLMs: GPT-4o, Claude-3.5-Haiku, and Gemini-2.5-Flash. They specific version are: gpt-4o-2024-08-06,
claude-3-5-haiku-20241022.
We next describe the specific system prompts and user prompts that are used for generating texts. First, for the rewrite task, the system prompt is:
You are a professional rewriting expert and you can help paraphrase this paragraph in English without missing the original details. Please keep the length of the rewritten text similar to the original text.
For the polish task, the system prompt is:
You are a professional polishing expert and you can help polish this paragraph.
For the expand task, the system prompt is:
You are a professional writing expert and you can help expand this paragraph.
For Gemini-2.5-Flash and Claude-3.5-Haiku, we additionally append the instruction in the system prompt:
Return ONLY the rewritten/polished/expanded version. Do not explain changes, do not give multiple options, and do not add commentary.
This ensures the output is strictly aligned with the assigned task.
The user prompt depends on the task. For rewriting, it takes the form: Please rewrite: [a human text]. For the expansion task, one of several predefined style prompts8 is selected (e.g., “Expand but not extend the paragraph in an oral style” or “Expand but not extend the paragraph in a literary style”). For polishing, a prompt is similarly chosen from a
predefined set9 (e.g., “Help me refine a paragraph with a lyrical touch. Enhance the flow and imagery, making the words sing together in perfect harmony”).
Given these settings, each LLM generates texts from human-written texts randomly sampled from one of source datasets. In the generation process, we set the temperature parameter of LLM as 0.8. This process is repeated 100 times on one source dataset and one task, yielding a dataset of 100 machine-generated and 100 human-written texts. With three tasks, three LLMs, and three data sources, we obtain a total of 27 evaluation datasets.
Setup of Baselines. Baseline setups largely follow the procedure in Section 9.1, with slight modifications to the training data. For instance, when evaluating performance on the News dataset, the Wiki and Story datasets are used for training. The process is repeated analogously when evaluating on the Wiki or Story datasets.
To evaluate the robustness of our approach against adversarial attacks, we adopt the attacks in [28]. In particular, for the rephrasing attack, we use the T5-based paraphraser available on HuggingFace10 to paraphrase text generated by Claude-3.5 prior to detection.
In the ablation study, both FD and our method rely on the exact same rewritten texts to compute distance. This setup reflects the contribution of our adaptive distance learning procedure.
In preparing this paper, the LLM was used only for writing and editing, and it does not impact the core methodology.
Hongyi Zhou and Jin Zhu contributed equally to this paper and are listed in alphabetical order.↩︎
Corresponding author: e.xu2@lse.ac.uk, c.shi.7@lse.ac.uk↩︎
https://huggingface.co/openai-community/roberta-large-openai-detector↩︎
https://github.com/Jiaqi-Chen-00/ImBD/blob/main/data/expand_prompt.json↩︎
https://github.com/Jiaqi-Chen-00/ImBD/blob/main/data/polish_prompt.json↩︎