DNA-GPT: Divergent N-Gram Analysis for Training-Free Detection of GPT-Generated Text

Xianjun Yang, Wei Cheng, Yue Wu, Linda Petzold, William Yang Wang, Haifeng Chen

TL;DR

DNA-GPT is a novel, training-free method for detecting AI-generated text by comparing a candidate passage to its own "regenerated" continuations. By exploiting the fact that LLMs are more deterministic than humans when completing a given prefix, the researchers achieved state-of-the-art detection accuracy across multiple models and languages while providing explainable evidence for their results.

What Problem Does This Paper Address?

As large language models (LLMs) like GPT-4 become increasingly fluent, distinguishing between human and machine-written text has become a high-stakes game of cat and mouse. Existing detection tools generally fall into two camps:

  1. Supervised Classifiers: These are trained on millions of examples but struggle to generalize to new domains or updated models. They are "black boxes" that offer a simple "Yes/No" without explanation.
  2. Zero-Shot Detectors: Methods like DetectGPT rely on token-level probabilities. However, many top-tier models (like ChatGPT) are closed-source and do not provide these probabilities, rendering such detectors useless in real-world "black-box" scenarios.

The authors of DNA-GPT sought a method that is training-free (zero-shot), works without internal model access, provides explainable evidence, and remains robust against text revisions.

Methods

The core intuition behind DNA-GPT is the Likelihood-Gap Hypothesis: conditioned on the same preceding text, an LLM is far more likely to produce a specific, high-probability continuation than a human is.

The process follows a simple "truncate-and-regenerate" pipeline:

  1. Truncation: A candidate text $S$ is split into two parts: a prefix $X$ and the original suffix $Y_0$.
  2. Regeneration: The prefix $X$ is fed back into the LLM to generate $K$ new suffixes $\{Y_1, ..., Y_K\}$.
  3. Scoring:
    • Black-box (BScore): The system calculates the N-gram overlap between the original suffix ($Y_0$) and the new machine-generated suffixes. High overlap suggests the original was machine-generated.
  4. White-box (WScore): If token probabilities are available, the system measures the probability divergence between the original and regenerated text.
Overview of the DNA-GPT framework

Crucially, the overlapping N-grams found during BScore calculation serve as "DNA evidence," allowing the system to highlight exactly which phrases look suspiciously machine-like.

Datasets

The researchers evaluated DNA-GPT on a diverse set of benchmarks to ensure robustness:

  • Reddit-ELI5: Long-form Q&A filtered for recent data (2022-2023) to avoid models simply "memorizing" the answers.
  • Scientific Abstracts: Recently published abstracts from Nature to test detection on high-quality technical writing.
  • PubMedQA & Xsum: Standard benchmarks for biomedical Q&A and extreme summarization.
  • WMT16: Used to test performance on both English and German text.
  • WikiText-103: Used specifically to investigate how model memorization of training data affects detection.

Key Insights and Ideas

  • The Determinism Trap: LLMs tend to follow a likelihood maximization criterion. Even with sampling, they occupy a much narrower distribution of possible continuations than the "noisy" and creative thought process of human writing. This is clearly visible in the probability density differences between human and machine text.
  • Explainability as a Feature: By identifying specific N-gram overlaps, DNA-GPT moves beyond a binary classification. This is vital for educators who need to show why a student's essay was flagged for plagiarism.
  • Model Sourcing: Because different models have different "DNA" (generation patterns), this method can actually identify which specific model (e.g., GPT-4 vs. LLaMA) likely generated the text by checking which model's regenerations have the highest overlap.
  • Robustness to Temperature: While training-based classifiers fail when the "creativity" (decoding temperature) of the LLM changes, DNA-GPT remains relatively stable.
Figure 5: The impact of decoding temperature on detection performance, conducted using gpt-3.5-turbo.

Key Results

  • Superior Accuracy: DNA-GPT consistently outperformed OpenAI’s own classifier and GPTZero. In white-box settings, it outperformed DetectGPT by a massive margin (e.g., AUROC of ~99% vs. ~55% on certain datasets).
  • Efficiency: The researchers found that only 5 to 10 regenerations ($K$) are needed to reach peak performance, making the method cost-effective for API-based models.
  • Cross-Lingual Success: Unlike many tools that only work for English, DNA-GPT showed strong results on German text, where baselines like GPTZero performed no better than random guessing.
  • Revision Robustness: The method remained effective even when the text was partially revised by humans or other AI models, maintaining high AUROC scores even when 50% of the text was altered.
Figure 4: A comparative analysis of AUROC scores and TPR (at a 1% FPR) across four datasets, each characterized by different numbers of regeneration. The analysis is performed under both black- box and white-box settings, utilizing the gpt-3.5-turbo and text-davinci-003 models, respectively.

Limitations and Future Work

  • Architecture Specificity: The current evaluation focused on GPT-style decoder-only models. Its effectiveness on encoder-decoder models (like T5) is not yet fully explored.
  • Length Constraints: The method works best on passages of moderate length (1000–2000 characters). Very short snippets remain a challenge for all detection methods.
  • The Memorization Problem: If an LLM has memorized a piece of human-written text from its training data (like a Wikipedia entry), it will regenerate it perfectly. This can lead to false positives, as the "machine" is simply echoing a human.
  • Future Directions: The authors suggest a "sliding window" approach to detect mixed-authorship documents where a human continues a machine-generated prefix or vice versa.

Summary updated

Abstract

Large language models (LLMs) have notably enhanced the fluency and diversity of machine-generated text. However, this progress also presents a significant challenge in detecting the origin of a given text, and current research on detection methods lags behind the rapid evolution of LLMs. Conventional training-based methods have limitations in flexibility, particularly when adapting to new domains, and they often lack explanatory power. To address this gap, we propose a novel training-free detection strategy called Divergent N-Gram Analysis (DNA-GPT). Given a text, we first truncate it in the middle and then use only the preceding portion as input to the LLMs to regenerate the new remaining parts. By analyzing the differences between the original and new remaining parts through N-gram analysis in black-box or probability divergence in white-box, we unveil significant discrepancies between the distribution of machine-generated text and the distribution of human-written text. We conducted extensive experiments on the most advanced LLMs from OpenAI, including text-davinci-003, GPT-3.5-turbo, and GPT-4, as well as open-source models such as GPT-NeoX-20B and LLaMa-13B. Results show that our zero-shot approach exhibits state-of-the-art performance in distinguishing between human and GPT-generated text on four English and one German dataset, outperforming OpenAI's own classifier, which is trained on millions of text. Additionally, our methods provide reasonable explanations and evidence to support our claim, which is a unique feature of explainable detection. Our method is also robust under the revised text attack and can additionally solve model sourcing. Codes are available at https://github.com/Xianjun-Yang/DNA-GPT.
BibTeX
@inproceedings{yang2024dna,
  author = {Xianjun Yang and Wei Cheng and Yue Wu and Linda Petzold and William Yang Wang and Haifeng Chen},
  title = {{DNA-GPT: Divergent N-Gram Analysis for Training-Free Detection of GPT-Generated Text}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=Xlayxj2fWp},
}
Figure