Mamba413/L2D

[ICLR 2026] Learn-to-Distance: Distance Learning for Detecting LLM-Generated Text

5

stars

63

commits

Python

primary language

Apr 3, 2026

updated

arxiv.org/abs/2601.21895
detection
distance-learning
large-language-models
llm-generated-text
metric-learning
Browse cluster: AI-Generated Text Detection

README

[ICLR 2026] Learn-to-Distance (L2D): Distance Learning for Detecting LLM-Generated Text ✨

ICLR 2026 Python

This repository contains the official implementation of Learn-to-Distance: Distance Learning for Detecting LLM-Generated Text (accepted at ICLR 2026).

L2D provides a geometric projection viewpoint on the effectiveness of rewrite-based detectors (Figure 1 🧠)
and strengthens this paradigm via distance learning (Figure 2 🧭). Under experimental settings, it achieves state-of-the-art performance across a wide range of LLMs and datasets (Figure 3 🏆).

Projection intuition behind rewrite-based detection

Figure 1. 🧠 Projection intuition behind rewrite-based detection. (Click to expand the full explanation 👇)

📝 Full explanation for Figure 1 The brown dot represents a human-authored text after embedding, while the two green dots represent its projection onto the LLM subspace and an LLM-generated text produced from an unobserved prompt, respectively. From left to right, the purple dots denote the reconstructions of the first green dot, the brown dot and the second green dot. As illustrated, d₁ > d₂, indicating that the reconstruction error for human text is larger than that for LLM-generated text, which aligns with Proposition 1 in the paper. Additionally, d₁ > d₃ suggests that rewrite-based methods remain robust to prompt-induced distribution shifts, as formalized in Proposition 2 in the paper.

L2D workflow

Figure 2. 🧭 Workflow of the proposal: our method adaptively learns a distance metric to measure the discrepancy between human and LLM-generated texts for detection.

L2D performance

Figure 3. 🏆 AUC scores across datasets, models, and tasks; best method highlighted in blue, second best in orange.

🧭 Table of Contents

🛠️ Installation

Requirements

  • Python 3.10.8
  • PyTorch 2.7.0
  • CUDA-compatible GPU (experiments conducted on H20-NVLink with 96GB memory)

Setup

./setup.sh

🚀 Usage

Run on a dataset with a pretrained checkpoint

Recommended for off-the-shelf usage.

python scripts/detect_l2d.py --from_pretrained mamba413/L2D   --eval_dataset example/demo --output_file example/demo --eval_only

Pretrained checkpoint details

If you want better / cheaper rewriting

  • Consider a smaller rewrite model such as Qwen/Qwen3-4B, or bring your own rewrite model / dataset.

Train / evaluate on your own data

Recommended when you want to:

  • 🔧 improve performance on your specific domain, or
  • ⚖️ fairly compare with other training-based methods.

1) Prepare your dataset

Provide a .json file named xxx.raw_data.json with the following structure:

{
  "original": ["human-text-1", "human-text-2", "..."],
  "sampled": ["machine-text-1", "machine-text-2", "..."]
}
  • original: human-written texts
  • sampled: machine-generated texts (from one or more LLMs)
  • The two lists should typically be aligned in length (one-vs-one), unless your pipeline explicitly supports otherwise.

2) Train (and optionally save) a checkpoint

python scripts/detect_l2d.py --train_dataset "./exp_prompt/data/squad_claude-3-5-haiku" --save_trained

By default, checkpoints are saved to ./scripts/AdaDist/ckpt/

3) Evaluate with your trained checkpoint

python scripts/detect_l2d.py --eval_only --eval_dataset your_data --output_file your_result --from_pretrained ./scripts/AdaDist/ckpt/

🎁 Additional Resources

The scripts/ directory contains implementations of various LLM detection methods from the literature. These implementations are modified from their official versions or from L2D to provide:

  • consistent input/output formats
  • simplified method comparison

Implemented baselines

MethodScript FilePaper/Website
AdaDetectGPTdetect_gpt_ada.pyarXiv:2510.01268
BARTScoredetect_bartscore.pyEMNLP-main.463
Binocularsdetect_binoculars.pyarXiv:2401.12070
Fast-DetectGPTdetect_gpt_fast.pyarXiv:2310.05130
GLTRdetect_gltr.pyarXiv:1906.04043
IDEdetect_ide.pyarXiv:2306.04723
ImBDdetect_ImBD.pyarXiv:2412.10432
Likelihooddetect_likelihood.pyarXiv:2306.05540
LRRdetect_lrr.pyarXiv:2306.05540
RADARdetect_radar.pyarXiv:2307.03838
RADIARdetect_radiar.pyarXiv:2401.12970
RoBERTa OpenAI Detectordetect_roberta.pyarXiv:1908.09203

Additional baselines can be found in a comprehensive github repo: AdaDetectGPT.

Reproducibility guide

  • exp_diverse.sh: generate Table 1 and Tables B1–B4
  • exp_prompt.sh: generate Table 2

After running the above code, use:

python script/report_results.py

You can call either report_black_prompt_results or report_diverse_results to render the tables/figures. To speedup the reproducibility, we include the rewritten texts for Table 2 in the directory exp_prompt.

  • exp_attack.sh: reproduce Figure 4 (use fig4.py to produce Figure 4 in the main text)

📖 Citation

If you find this work useful, please consider citing our paper:

@inproceedings{zhou2026learn,
  title={Learn-to-Distance: Distance Learning for Detecting LLM-Generated Text},
  author={Hongyi Zhou and Jin Zhu and Kai Ye and Ying Yang and Erhan Xu and Chengchun Shi},
  booktitle={The Fourteenth International Conference on Learning Representations},
  abbr={ICLR},
  year={2026},
}

If you have any questions, please feel free to open an issue.

Contributors

Mamba413

63 commits

Mamba413/L2D

[ICLR 2026] Learn-to-Distance: Distance Learning for Detecting LLM-Generated Text

5

stars

63

commits

Python

primary language

Apr 3, 2026

updated

arxiv.org/abs/2601.21895
detection
distance-learning
large-language-models
llm-generated-text
metric-learning
Browse cluster: AI-Generated Text Detection

README

[ICLR 2026] Learn-to-Distance (L2D): Distance Learning for Detecting LLM-Generated Text ✨

ICLR 2026 Python

This repository contains the official implementation of Learn-to-Distance: Distance Learning for Detecting LLM-Generated Text (accepted at ICLR 2026).

L2D provides a geometric projection viewpoint on the effectiveness of rewrite-based detectors (Figure 1 🧠)
and strengthens this paradigm via distance learning (Figure 2 🧭). Under experimental settings, it achieves state-of-the-art performance across a wide range of LLMs and datasets (Figure 3 🏆).

Projection intuition behind rewrite-based detection

Figure 1. 🧠 Projection intuition behind rewrite-based detection. (Click to expand the full explanation 👇)

📝 Full explanation for Figure 1 The brown dot represents a human-authored text after embedding, while the two green dots represent its projection onto the LLM subspace and an LLM-generated text produced from an unobserved prompt, respectively. From left to right, the purple dots denote the reconstructions of the first green dot, the brown dot and the second green dot. As illustrated, d₁ > d₂, indicating that the reconstruction error for human text is larger than that for LLM-generated text, which aligns with Proposition 1 in the paper. Additionally, d₁ > d₃ suggests that rewrite-based methods remain robust to prompt-induced distribution shifts, as formalized in Proposition 2 in the paper.

L2D workflow

Figure 2. 🧭 Workflow of the proposal: our method adaptively learns a distance metric to measure the discrepancy between human and LLM-generated texts for detection.

L2D performance

Figure 3. 🏆 AUC scores across datasets, models, and tasks; best method highlighted in blue, second best in orange.

🧭 Table of Contents

🛠️ Installation

Requirements

  • Python 3.10.8
  • PyTorch 2.7.0
  • CUDA-compatible GPU (experiments conducted on H20-NVLink with 96GB memory)

Setup

./setup.sh

🚀 Usage

Run on a dataset with a pretrained checkpoint

Recommended for off-the-shelf usage.

python scripts/detect_l2d.py --from_pretrained mamba413/L2D   --eval_dataset example/demo --output_file example/demo --eval_only

Pretrained checkpoint details

If you want better / cheaper rewriting

  • Consider a smaller rewrite model such as Qwen/Qwen3-4B, or bring your own rewrite model / dataset.

Train / evaluate on your own data

Recommended when you want to:

  • 🔧 improve performance on your specific domain, or
  • ⚖️ fairly compare with other training-based methods.

1) Prepare your dataset

Provide a .json file named xxx.raw_data.json with the following structure:

{
  "original": ["human-text-1", "human-text-2", "..."],
  "sampled": ["machine-text-1", "machine-text-2", "..."]
}
  • original: human-written texts
  • sampled: machine-generated texts (from one or more LLMs)
  • The two lists should typically be aligned in length (one-vs-one), unless your pipeline explicitly supports otherwise.

2) Train (and optionally save) a checkpoint

python scripts/detect_l2d.py --train_dataset "./exp_prompt/data/squad_claude-3-5-haiku" --save_trained

By default, checkpoints are saved to ./scripts/AdaDist/ckpt/

3) Evaluate with your trained checkpoint

python scripts/detect_l2d.py --eval_only --eval_dataset your_data --output_file your_result --from_pretrained ./scripts/AdaDist/ckpt/

🎁 Additional Resources

The scripts/ directory contains implementations of various LLM detection methods from the literature. These implementations are modified from their official versions or from L2D to provide:

  • consistent input/output formats
  • simplified method comparison

Implemented baselines

MethodScript FilePaper/Website
AdaDetectGPTdetect_gpt_ada.pyarXiv:2510.01268
BARTScoredetect_bartscore.pyEMNLP-main.463
Binocularsdetect_binoculars.pyarXiv:2401.12070
Fast-DetectGPTdetect_gpt_fast.pyarXiv:2310.05130
GLTRdetect_gltr.pyarXiv:1906.04043
IDEdetect_ide.pyarXiv:2306.04723
ImBDdetect_ImBD.pyarXiv:2412.10432
Likelihooddetect_likelihood.pyarXiv:2306.05540
LRRdetect_lrr.pyarXiv:2306.05540
RADARdetect_radar.pyarXiv:2307.03838
RADIARdetect_radiar.pyarXiv:2401.12970
RoBERTa OpenAI Detectordetect_roberta.pyarXiv:1908.09203

Additional baselines can be found in a comprehensive github repo: AdaDetectGPT.

Reproducibility guide

  • exp_diverse.sh: generate Table 1 and Tables B1–B4
  • exp_prompt.sh: generate Table 2

After running the above code, use:

python script/report_results.py

You can call either report_black_prompt_results or report_diverse_results to render the tables/figures. To speedup the reproducibility, we include the rewritten texts for Table 2 in the directory exp_prompt.

  • exp_attack.sh: reproduce Figure 4 (use fig4.py to produce Figure 4 in the main text)

📖 Citation

If you find this work useful, please consider citing our paper:

@inproceedings{zhou2026learn,
  title={Learn-to-Distance: Distance Learning for Detecting LLM-Generated Text},
  author={Hongyi Zhou and Jin Zhu and Kai Ye and Ying Yang and Erhan Xu and Chengchun Shi},
  booktitle={The Fourteenth International Conference on Learning Representations},
  abbr={ICLR},
  year={2026},
}

If you have any questions, please feel free to open an issue.

Contributors

Mamba413

63 commits

Languages

Python

91.6%

Shell

8.4%