DeTeCtive: Detecting AI-generated Text via Multi-Level Contrastive Learning

Xun Guo, Yongxin He, Shan Zhang, Ting Zhang, Wanquan Feng, Haibin Huang, Chongyang Ma

Introduction

The rapid proliferation of Large Language Models (LLMs) such as GPT-4, LLaMA, and Claude has introduced significant challenges to information integrity. As these models become increasingly sophisticated, the risks of automated disinformation campaigns and academic dishonesty grow. Traditional detection methods typically treat the problem as a binary classification task—distinguishing between "Human" and "AI" text. However, this approach often fails to generalize to "out-of-distribution" (OOD) scenarios, where a detector trained on older models (like GPT-2) struggles to identify text from newer, more nuanced architectures.

To address these limitations, we present DeTeCtive, a novel framework that reframes AI-generated text detection as a writing style recognition problem. By leveraging multi-level contrastive learning and a retrieval-based inference pipeline, DeTeCtive identifies the unique stylistic fingerprints of different LLMs, allowing for robust detection and seamless adaptation to new models.

Methodology: Beyond Binary Classification

The core philosophy of DeTeCtive is that every LLM possesses a distinct "authorial" style. Rather than simply learning a boundary between human and machine text, the model learns the relationships between various text sources through three main components:

1. Multi-Level Contrastive Learning

DeTeCtive employs a hierarchical loss function designed to structure the feature space based on stylistic similarity. The model is trained to recognize three levels of kinship:

  • Instance Level: Text samples from the same specific LLM are pulled closest together.
  • Family Level: Text from models within the same family (e.g., different iterations of the GPT series) are clustered in proximity.
  • Source Level: All AI-generated text is grouped more closely together than it is to human-written text.

This hierarchical approach ensures that the model develops a sophisticated understanding of "machine-like" features, capturing the subtle stylistic DNA shared by related models.

2. Multi-Task Auxiliary Learning

To maintain high discriminative power for the primary detection task, the contrastive loss is combined with a standard cross-entropy loss via a classification head. This dual-objective training ensures the model retains the ability to perform standard classification while benefiting from the structured feature space of contrastive learning.

3. Dense Retrieval and TFIA

During inference, DeTeCtive moves away from static prediction. Instead, it uses Dense Retrieval Inference: the query text is encoded into a vector and compared against a database of known examples using K-Nearest Neighbors (KNN).

This architecture enables Training-Free Incremental Adaptation (TFIA). When a new LLM is released, there is no need to retrain the entire model. Instead, a small set of samples from the new model can be encoded and added to the feature database. The KNN search naturally identifies similarities between the query and these new samples, allowing the system to adapt to emerging threats instantly.

Experimental Evaluation

The researchers evaluated DeTeCtive across three comprehensive benchmarks: Deepfake (27 LLMs across 10 domains), M4 (multi-lingual and paraphrased text), and TuringBench (19 LLM families).

Key Results

  • Superior Generalization: DeTeCtive consistently outperformed state-of-the-art (SOTA) methods, including RoBERTa-based classifiers and DetectGPT. In zero-shot evaluations, it showed a 5.58% improvement on unseen models and a 14.20% improvement on unseen domains.
  • Effective Adaptation: The TFIA mechanism provided a 7.03% accuracy boost on unseen domains without requiring any gradient updates or retraining.
  • Robustness to Attacks: The framework demonstrated high resilience against "paraphrasing attacks" (using tools like DIPPER). While other detectors experienced significant performance degradation when faced with paraphrased machine text, DeTeCtive maintained its efficacy by focusing on underlying stylistic patterns.

Discussion and Future Work

DeTeCtive represents a paradigm shift in AI detection by treating LLMs as unique authors. By moving the "intelligence" of the system into a modular, searchable database, the framework becomes a dynamic and updatable library rather than a static classifier.

Despite its success, several avenues for future research remain. Currently, the model focuses on document-level detection; extending this to token-level interpretability would provide more granular insights into which specific parts of a text are machine-generated. Additionally, while the model is robust, improving the interpretability of the style embeddings remains a priority to help users understand the reasoning behind a "flagged" result. Finally, scaling the training to even more diverse and massive corpora could further refine the stylistic boundaries between human and machine writing.

Summary updated

BibTeX
@inproceedings{guo2024detective,
  author = {Xun Guo and Yongxin He and Shan Zhang and Ting Zhang and Wanquan Feng and Haibin Huang and Chongyang Ma},
  title = {{DeTeCtive: Detecting AI-generated Text via Multi-Level Contrastive Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=cdTTTJfJe3},
}
Figure