Giter VIP home page Giter VIP logo

mmd-mp's Introduction

Detecting Machine-Generated Texts by Multi-Population Aware Optimization for Maximum Mean Discrepancy

Official PyTorch implementation of the ICLR 2024 paper:

Detecting Machine-Generated Texts by Multi-Population Aware Optimization for Maximum Mean Discrepancy

Shuhai Zhang, Yiliao Song, Jiahao Yang, Yuanqing Li, Bo Han, Mingkui Tan.

Abstract: Large language models (LLMs) such as ChatGPT have exhibited remarkable performance in generating human-like texts. However, machine-generated texts (MGTs) may carry critical risks, such as plagiarism issues, misleading informa- tion, or hallucination issues. Therefore, it is very urgent and important to detect MGTs in many situations. Unfortunately, it is challenging to distinguish MGTs and human-written texts because the distributional discrepancy between them is often very subtle due to the remarkable performance of LLMs. In this paper, we seek to exploit maximum mean discrepancy (MMD) to address this issue in the sense that MMD can well identify distributional discrepancies. However, directly training a detector with MMD using diverse MGTs will incur a significantly in- creased variance of MMD since MGTs may contain multiple text populations due to various LLMs. This will severely impair MMD’s ability to measure the differ-ence between two samples. To tackle this, we propose a novel multi-population aware optimization method for MMD called MMD-MP, which can avoid variance increases and thus improve the stability to measure the distributional discrep- ancy. Relying on MMD-MP, we develop two methods for paragraph-based and sentence-based detection, respectively. Extensive experiments on various LLMs, e.g., GPT2 and ChatGPT, show superior detection performance of our MMD-MP.

Requirements

  • An NVIDIA RTX graphics card with 12 GB of memory.
  • Python 3.7
  • Pytorch 1.13.1

Data and pre-trained models

For dataset, we use HC3, which can be downloaded by download link. For the pre-trained language models, you need to first download them from the following links:

After the download, please complete the model_path_dit in the run file.

Environment of MMD-MP

You have to create a virtual environment and set up libraries needed for training and evaluation.

conda env create -f detectGPT.yml

Run experiments on HC3

Training MMD-MP.

  • Select the best model through best_power:
CUDA_VISIBLE_DEVICES=0 
python run_meta_mmd_trans.py 
--id 10001 
--sigma0 55 
--lr 0.00005  
--no_meta_flag   
--n_samples 3900 
--target_senten_num 3000 
--val_num 50 
--sigma 30 
--max_length  100 
--trial_num 3 
--num_hidden_layers 1 
--target_datasets HC3 
--text_generated_model_name chatGPT 
--base_model_name roberta-base-openai-detector 
--skip_baselines 
--mask_flag 
--transformer_flag 
--meta_test_flag 
--epochs 100 
--two_sample_test
  • Select the best model through best_auroc:
CUDA_VISIBLE_DEVICES=1 
python run_meta_mmd_trans_auroc.py 
--id 10002 
--sigma0 40 
--lr 0.00005  
--no_meta_flag   
--n_samples 3900 
--target_senten_num 3000 
--val_num 50 
--sigma 30 
--max_length 100 
--trial_num 3 
--num_hidden_layers 1 
--target_datasets HC3 
--text_generated_model_name chatGPT 
--base_model_name roberta-base-openai-detector 
--skip_baselines 
--mask_flag 
--transformer_flag 
--meta_test_flag 
--epochs 100 
--two_sample_test

Testing MMD-MP.

  • Add a command-line argument --test_flag to enable the testing functionality, allowing for the evaluation of the checkpoint corresponding to the specified id:
CUDA_VISIBLE_DEVICES=0 
python run_meta_mmd_trans.py 
--test_flag
--id 10001 
--sigma0 55 
--lr 0.00005  
--no_meta_flag   
--n_samples 3900 
--target_senten_num 3000 
--val_num 50 
--sigma 30 
--max_length  100 
--trial_num 3 
--num_hidden_layers 1 
--target_datasets HC3 
--text_generated_model_name chatGPT 
--base_model_name roberta-base-openai-detector 
--skip_baselines 
--mask_flag 
--transformer_flag 
--meta_test_flag 
--epochs 100 
--two_sample_test

Citation

@inproceedings{zhangs2024MMDMP,
  title={Detecting Machine-Generated Texts by Multi-Population Aware Optimization for Maximum Mean Discrepancy},
  author={Zhang, Shuhai and Song, Yiliao and Yang, Jiahao and Li, Yuanqing and Han, Bo and Tan, Mingkui},
  booktitle = {International Conference on Learning Representations (ICLR)},
  year={2024}
}

mmd-mp's People

Contributors

zshsh98 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.