TrustMedia-zju/Lastde_Detector

Training-free LLM-generated Text Detection by Mining Token Probability Sequences (ICLR 2025)

37

stars

17

commits

Python

primary language

Apr 25, 2025

updated

Browse cluster: AI-Generated Text Detection

README

Training-free LLM-generated Text Detection by Mining Token Probability Sequences

This project provides the core code for the two main methods, Lastde and Lastde++ , as presented in our paper.

We follow the standard testing procedures outlined in Fast-DetectGPT to evaluate each detection method.

>

Environment

  • Python3.8
  • Pytorch2.0.0
  • Other dependencies:
    pip install -r requirements.txt
    
    (Note: Our experiments were conducted on two RTX 3090 GPUs with 24GB of memory each.)

Source Models and Proxy Models

The pretrain_models directory is used to store open-source models, including those used as proxies or for generating text produced by LLMs. Here, we take gpt-j-6b and Llama-3-8B as examples, and the model weights can be downloaded from the following addresses:

Datasets

The main dataset is divided into two parts:

  • The human_original_data directory contains raw text in json format, with the Xsum dataset (i.e., xsum.json) as an example.
  • The human_llm_data_for_experiment directory stores the complete data used for experiments, with xsum_llama3_8b.raw_data.json as an example. This dataset needs to be obtained by running
    python py_scripts/data_generations/data_generation_opensource.py
    
    (Note : We have already provided the data here, so there is no need to run) Each complete data entry contains two parts: 'original' (human-written text) and 'sampled' (LLM-generated text), with the content of the two types of text corresponding to each other. The 'sampled' text is generated by using the first 30 tokens of the corresponding 'original' text as prompt input to the source model (in this case, Llama-3-8B) for continuation, and all entries are truncated to the same length.
  • The perturbation_data_detectgpt_npr and regeneration_data_dnagpt directories store the complete data of the DetectGPT/DetectNPR and DNA-GPT detection experiments respectively.
  • The remaining directories correspond to the robustness section in our paper.

Detection

Running detection_white_box.sh or detection_black_box.sh in shell_scripts will trigger white-box and black-box detection, respectively.

cd shell_scripts

# white-box setting
./detection_white_box.sh 

# black-box setting
./detection_black_box.sh

The detection methods include:

  • Likelihood, LogRank, Entropy, DetectLRR, Lastde(ours). Results will be saved in experiment_results/statistic_detection_results.
  • DetectGPT. Results will be saved in experiment_results/detectgpt_detection_results.
  • DetectNPR. Results will be saved in experiment_results/npr_detection_results.
  • DNA-GPT. Results will be saved in experiment_results/dna_gpt_detection_results.
  • Fast-DetectGPT. Results will be saved in experiment_results/fast_detectgpt_detection_results.
  • Lastde++(ours). Results will be saved in experiment_results/lastde_doubleplus_detection_results.

The code for the above detection methods is encapsulated in py_scripts/baselines.

Other experimental scripts are located in the shell_scripts directory.

Baselines

We provide the following baseline implementations.

  • sample-based methods: Likelihood, LogRank, Entropy, DetectLRR, Lastde(ours), Binoculars
  • Distribution-based methods: DetectGPT, DetectNPR, DNA-GPT, Fast-DetectGPT, Lastde++(ours)
  • Plug and Play versions: Likelihood_tocsin, LogRank_tocsin, DetectLRR_tocsin, Lastde_tocsin, Fast-DetectGPT_tocsin, Lastde++_tocsin
  • supervised-based methods: RoBERTa_Base, RoBERTa_Large, ReMoDetect

We thank the authors of open source projects and models such as Fast-DetectGPT, TOCSIN, ReMoDetect and Binoculars.

Main results (AUROC)

White-box

  • Datasets : XSum, SQuAD, WritingPrompts
  • Sampling || Scoring model : specific source model || specific source model
  • Hyperparameters of Lastde/Lastde++ :
    • Lastde: $s$ = 3, $\varepsilon=10\times n$, $\tau^{\prime}=5$, $Agg=Std$.
    • Lastde++: $s$ = 4, $\varepsilon=8\times n$, $\tau^{\prime}=10$, $Agg=Std$.
MethodGPT-2Neo-2.7OPT-2.7GPT-JLlama-13Llama2-13Llama3-8OPT-13BLOOM-7.1Falcon-7Gemma-7Phi2-2.7Avg.
Likelihood91.6589.4088.0884.9563.6565.3698.3584.4588.0076.7870.1489.6782.54
LogRank94.3192.8790.9988.6868.8770.2799.0487.7492.4281.3274.8192.1386.12
Entropy52.1551.7250.4654.3164.1861.0523.3054.3062.6759.3366.4744.0953.67
DetectLRR96.6796.0793.1392.2481.4080.8998.9491.0396.3587.4581.3694.1090.80
Lastde98.4198.6498.1597.2488.9888.4099.7196.4799.3595.4991.8596.9995.89
DetectGPT93.4390.4090.3683.8263.7865.3970.1385.0589.2877.9868.9689.5580.68
DetectNPR95.7794.7793.2488.8668.6069.8395.5589.7894.9583.0674.7493.0686.85
DNA-GPT89.9286.8086.7982.2166.2864.4698.0782.5186.7474.0463.6388.0080.45
Fast-DetectGPT99.5799.4998.7898.9593.4593.3499.9198.0799.5397.7496.9098.1097.82
Lastde++99.7699.8799.4699.5296.5896.6799.8298.7799.8498.7698.4098.7698.85

Black-box

  • Datasets : XSum, WritingPrompts, Reddit
  • Sampling || Scoring model :
  • Hyperparameters of Lastde/Lastde++ :
    • Lastde: $s$ = 3, $\varepsilon=10\times n$, $\tau^{\prime}=5$, $Agg=Std$.
    • Lastde++: $s$ = 4, $\varepsilon=8\times n$, $\tau^{\prime}=10$, $Agg=Std$.
MethodGPT-2Neo-2.7OPT-2.7Llama-13Llama2-13Llama3-8OPT-13BLOOM-7.1Falcon-7Gemma-7Phi2-2.7GPT-4-TurboAvg.
Likelihood65.8867.0967.4065.7568.6199.6068.8061.8067.4269.9073.9379.6971.32
LogRank70.3871.1772.3570.2872.6799.6973.0167.5171.6672.1777.9979.2474.84
Entropy61.4858.6554.5549.1445.1814.4353.0960.8450.5548.0146.5835.0948.13
DetectLRR79.3079.1981.2578.5178.9497.3580.2779.5779.8773.4783.7973.8580.45
Lastde89.1790.2489.7080.7179.9099.6790.0188.9484.3679.6188.3281.3386.38
DetectGPT67.5669.2872.0366.1267.9682.9073.8961.8368.6966.5572.7681.7370.94
DetectNPR68.0768.4173.0667.8370.6096.7575.1363.0070.4265.7274.0879.9472.75
DNA-GPT64.1562.6363.6460.7766.7199.4765.7562.0165.0862.5972.0270.7567.97
Fast-DetectGPT89.8288.7586.5277.5877.6299.4386.1684.5581.4281.4986.6788.1885.68
Lastde++94.9395.2894.1385.0085.8099.0393.3792.2289.4987.5892.6788.2191.47

GPT-4-Turbo || GPT-4o || Claude-3-Haiku (Black-box)

  • Sampling || Scoring model :
  • Hyperparameters of Lastde/Lastde++ :
    • Lastde: $s$ = 3, $\varepsilon=1\times n$, $\tau^{\prime}=15$.
    • Lastde++: $s$ = 4, $\varepsilon=8\times n$, $\tau^{\prime}=10$.
Source Models ($\rightarrow$)GPT-4-TurboGPT-4oClaude-3-haiku
XSumWritingPromptsRedditAvg.XSumWritingPromptsRedditAvg.XSumWritingPromptsRedditAvg.
Likelihood60.4481.4897.1579.6975.4284.9097.7486.0296.8498.3899.9298.38
LogRank61.5279.0397.1679.2473.8582.3297.7484.6497.0998.7199.9698.59
Entropy61.2435.5608.4835.0947.5031.6009.7429.6138.9017.6906.5621.05
DetectLRR61.7166.7593.1073.8562.8769.0693.7575.2395.7897.9699.5697.77
Lastde(Std)64.1683.0996.7481.3373.8786.2097.7485.9497.4499.4099.9298.92
Fast-DetectGPT80.7989.8893.8788.1886.8793.7797.9392.8699.9399.9999.9699.96
Lastde++(2-Norm)76.9187.3993.6185.9785.7492.9697.5292.0799.9599.9999.9699.97
Lastde++(Range)82.6786.3791.7286.9285.9691.3496.5791.2999.8499.9999.9699.93
Lastde++(Std)83.1288.5093.0088.2186.4793.4196.9892.2999.9299.9699.8999.92
Lastde++(ExpRange)82.4089.0293.7088.3787.4293.6097.7792.9399.9610099.9799.98
Lastde++(ExpStd)81.5589.8193.9988.4587.2494.2497.9493.1499.9799.9999.9599.97

Notes

  • Currently, we recommend that you set the aggregate function (Agg) to ExpStd.

Citation

If you find this work useful, you can cite it with the following BibTex entry:

@articles{
  xu2025trainingfree,
  title={Training-free {LLM}-generated Text Detection by Mining Token Probability Sequences},
  author={Yihuai Xu and Yongwei Wang and Yifei Bi and Huangsen Cao and Zhouhan Lin and Yu Zhao and Fei Wu},
  booktitle={The Thirteenth International Conference on Learning Representations},
  year={2025},
}

Contributors

TrustMedia-zju

15 commits

Yihuai-Xu

2 commits

TrustMedia-zju/Lastde_Detector

Training-free LLM-generated Text Detection by Mining Token Probability Sequences (ICLR 2025)

37

stars

17

commits

Python

primary language

Apr 25, 2025

updated

Browse cluster: AI-Generated Text Detection

README

Training-free LLM-generated Text Detection by Mining Token Probability Sequences

This project provides the core code for the two main methods, Lastde and Lastde++ , as presented in our paper.

We follow the standard testing procedures outlined in Fast-DetectGPT to evaluate each detection method.

>

Environment

  • Python3.8
  • Pytorch2.0.0
  • Other dependencies:
    pip install -r requirements.txt
    
    (Note: Our experiments were conducted on two RTX 3090 GPUs with 24GB of memory each.)

Source Models and Proxy Models

The pretrain_models directory is used to store open-source models, including those used as proxies or for generating text produced by LLMs. Here, we take gpt-j-6b and Llama-3-8B as examples, and the model weights can be downloaded from the following addresses:

Datasets

The main dataset is divided into two parts:

  • The human_original_data directory contains raw text in json format, with the Xsum dataset (i.e., xsum.json) as an example.
  • The human_llm_data_for_experiment directory stores the complete data used for experiments, with xsum_llama3_8b.raw_data.json as an example. This dataset needs to be obtained by running
    python py_scripts/data_generations/data_generation_opensource.py
    
    (Note : We have already provided the data here, so there is no need to run) Each complete data entry contains two parts: 'original' (human-written text) and 'sampled' (LLM-generated text), with the content of the two types of text corresponding to each other. The 'sampled' text is generated by using the first 30 tokens of the corresponding 'original' text as prompt input to the source model (in this case, Llama-3-8B) for continuation, and all entries are truncated to the same length.
  • The perturbation_data_detectgpt_npr and regeneration_data_dnagpt directories store the complete data of the DetectGPT/DetectNPR and DNA-GPT detection experiments respectively.
  • The remaining directories correspond to the robustness section in our paper.

Detection

Running detection_white_box.sh or detection_black_box.sh in shell_scripts will trigger white-box and black-box detection, respectively.

cd shell_scripts

# white-box setting
./detection_white_box.sh 

# black-box setting
./detection_black_box.sh

The detection methods include:

  • Likelihood, LogRank, Entropy, DetectLRR, Lastde(ours). Results will be saved in experiment_results/statistic_detection_results.
  • DetectGPT. Results will be saved in experiment_results/detectgpt_detection_results.
  • DetectNPR. Results will be saved in experiment_results/npr_detection_results.
  • DNA-GPT. Results will be saved in experiment_results/dna_gpt_detection_results.
  • Fast-DetectGPT. Results will be saved in experiment_results/fast_detectgpt_detection_results.
  • Lastde++(ours). Results will be saved in experiment_results/lastde_doubleplus_detection_results.

The code for the above detection methods is encapsulated in py_scripts/baselines.

Other experimental scripts are located in the shell_scripts directory.

Baselines

We provide the following baseline implementations.

  • sample-based methods: Likelihood, LogRank, Entropy, DetectLRR, Lastde(ours), Binoculars
  • Distribution-based methods: DetectGPT, DetectNPR, DNA-GPT, Fast-DetectGPT, Lastde++(ours)
  • Plug and Play versions: Likelihood_tocsin, LogRank_tocsin, DetectLRR_tocsin, Lastde_tocsin, Fast-DetectGPT_tocsin, Lastde++_tocsin
  • supervised-based methods: RoBERTa_Base, RoBERTa_Large, ReMoDetect

We thank the authors of open source projects and models such as Fast-DetectGPT, TOCSIN, ReMoDetect and Binoculars.

Main results (AUROC)

White-box

  • Datasets : XSum, SQuAD, WritingPrompts
  • Sampling || Scoring model : specific source model || specific source model
  • Hyperparameters of Lastde/Lastde++ :
    • Lastde: $s$ = 3, $\varepsilon=10\times n$, $\tau^{\prime}=5$, $Agg=Std$.
    • Lastde++: $s$ = 4, $\varepsilon=8\times n$, $\tau^{\prime}=10$, $Agg=Std$.
MethodGPT-2Neo-2.7OPT-2.7GPT-JLlama-13Llama2-13Llama3-8OPT-13BLOOM-7.1Falcon-7Gemma-7Phi2-2.7Avg.
Likelihood91.6589.4088.0884.9563.6565.3698.3584.4588.0076.7870.1489.6782.54
LogRank94.3192.8790.9988.6868.8770.2799.0487.7492.4281.3274.8192.1386.12
Entropy52.1551.7250.4654.3164.1861.0523.3054.3062.6759.3366.4744.0953.67
DetectLRR96.6796.0793.1392.2481.4080.8998.9491.0396.3587.4581.3694.1090.80
Lastde98.4198.6498.1597.2488.9888.4099.7196.4799.3595.4991.8596.9995.89
DetectGPT93.4390.4090.3683.8263.7865.3970.1385.0589.2877.9868.9689.5580.68
DetectNPR95.7794.7793.2488.8668.6069.8395.5589.7894.9583.0674.7493.0686.85
DNA-GPT89.9286.8086.7982.2166.2864.4698.0782.5186.7474.0463.6388.0080.45
Fast-DetectGPT99.5799.4998.7898.9593.4593.3499.9198.0799.5397.7496.9098.1097.82
Lastde++99.7699.8799.4699.5296.5896.6799.8298.7799.8498.7698.4098.7698.85

Black-box

  • Datasets : XSum, WritingPrompts, Reddit
  • Sampling || Scoring model :
  • Hyperparameters of Lastde/Lastde++ :
    • Lastde: $s$ = 3, $\varepsilon=10\times n$, $\tau^{\prime}=5$, $Agg=Std$.
    • Lastde++: $s$ = 4, $\varepsilon=8\times n$, $\tau^{\prime}=10$, $Agg=Std$.
MethodGPT-2Neo-2.7OPT-2.7Llama-13Llama2-13Llama3-8OPT-13BLOOM-7.1Falcon-7Gemma-7Phi2-2.7GPT-4-TurboAvg.
Likelihood65.8867.0967.4065.7568.6199.6068.8061.8067.4269.9073.9379.6971.32
LogRank70.3871.1772.3570.2872.6799.6973.0167.5171.6672.1777.9979.2474.84
Entropy61.4858.6554.5549.1445.1814.4353.0960.8450.5548.0146.5835.0948.13
DetectLRR79.3079.1981.2578.5178.9497.3580.2779.5779.8773.4783.7973.8580.45
Lastde89.1790.2489.7080.7179.9099.6790.0188.9484.3679.6188.3281.3386.38
DetectGPT67.5669.2872.0366.1267.9682.9073.8961.8368.6966.5572.7681.7370.94
DetectNPR68.0768.4173.0667.8370.6096.7575.1363.0070.4265.7274.0879.9472.75
DNA-GPT64.1562.6363.6460.7766.7199.4765.7562.0165.0862.5972.0270.7567.97
Fast-DetectGPT89.8288.7586.5277.5877.6299.4386.1684.5581.4281.4986.6788.1885.68
Lastde++94.9395.2894.1385.0085.8099.0393.3792.2289.4987.5892.6788.2191.47

GPT-4-Turbo || GPT-4o || Claude-3-Haiku (Black-box)

  • Sampling || Scoring model :
  • Hyperparameters of Lastde/Lastde++ :
    • Lastde: $s$ = 3, $\varepsilon=1\times n$, $\tau^{\prime}=15$.
    • Lastde++: $s$ = 4, $\varepsilon=8\times n$, $\tau^{\prime}=10$.
Source Models ($\rightarrow$)GPT-4-TurboGPT-4oClaude-3-haiku
XSumWritingPromptsRedditAvg.XSumWritingPromptsRedditAvg.XSumWritingPromptsRedditAvg.
Likelihood60.4481.4897.1579.6975.4284.9097.7486.0296.8498.3899.9298.38
LogRank61.5279.0397.1679.2473.8582.3297.7484.6497.0998.7199.9698.59
Entropy61.2435.5608.4835.0947.5031.6009.7429.6138.9017.6906.5621.05
DetectLRR61.7166.7593.1073.8562.8769.0693.7575.2395.7897.9699.5697.77
Lastde(Std)64.1683.0996.7481.3373.8786.2097.7485.9497.4499.4099.9298.92
Fast-DetectGPT80.7989.8893.8788.1886.8793.7797.9392.8699.9399.9999.9699.96
Lastde++(2-Norm)76.9187.3993.6185.9785.7492.9697.5292.0799.9599.9999.9699.97
Lastde++(Range)82.6786.3791.7286.9285.9691.3496.5791.2999.8499.9999.9699.93
Lastde++(Std)83.1288.5093.0088.2186.4793.4196.9892.2999.9299.9699.8999.92
Lastde++(ExpRange)82.4089.0293.7088.3787.4293.6097.7792.9399.9610099.9799.98
Lastde++(ExpStd)81.5589.8193.9988.4587.2494.2497.9493.1499.9799.9999.9599.97

Notes

  • Currently, we recommend that you set the aggregate function (Agg) to ExpStd.

Citation

If you find this work useful, you can cite it with the following BibTex entry:

@articles{
  xu2025trainingfree,
  title={Training-free {LLM}-generated Text Detection by Mining Token Probability Sequences},
  author={Yihuai Xu and Yongwei Wang and Yifei Bi and Huangsen Cao and Zhouhan Lin and Yu Zhao and Fei Wu},
  booktitle={The Thirteenth International Conference on Learning Representations},
  year={2025},
}

Contributors

TrustMedia-zju

15 commits

Yihuai-Xu

2 commits

Languages

Python

77.5%

Shell

22.5%