arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2310.05103cs.CLcs.AIcs.CRcs.LG
收藏

机器生成代码的零样本检测

Zero-Shot Detection of Machine-Generated Codes

University of California, Santa Barbara(加州大学圣巴巴拉分校);NEC Laboratories America, Princeton(普林斯顿NEC美国实验室)

Xianjun Yang, Kexun Zhang, Haifeng Chen, Linda Petzold, William Yang Wang, Wei Cheng

AI总结:

本研究提出一种无需训练的零样本代码检测方法,改进DetectGPT并利用代理白盒模型估计词元概率,在多个数据集和大模型上实现最优检测效果,具备攻击鲁棒性与跨语言泛化性。

摘要:

本研究提出了一种无需训练的方法,用于检测大语言模型(LLM)生成的代码,以降低这类代码被滥用带来的风险。据我们所知,本研究首次探索了应用于ChatGPT等先进黑盒大语言模型所生成代码的零样本检测技术。首先,我们发现现有的基于训练或零样本的文本检测器在检测代码时效果不佳,这可能是由代码结构特有的统计属性导致的。随后,我们对此前的零样本文本检测方法DetectGPT(Mitchell等人,2023)进行了改进,利用代理白盒模型估计最右侧词元的概率,从而识别由语言模型生成的代码片段。我们在CodeContest和APPS数据集的Python代码上开展了大量实验,结果表明该方法在检测text-davinci-003、GPT-3.5和GPT-4模型生成的代码时取得了当前最优的检测效果。此外,该方法对修改攻击具备鲁棒性,且能很好地泛化到Java代码上。我们还发现,像PolyCoder-160M这类更小的代码语言模型可作为通用代码检测器,性能优于十亿参数规模的同类模型。相关代码将发布于https://github.com/Xianjun-Yang/Code_detection.git。

英文摘要:

This work proposes a training-free approach for the detection of LLMs-generated codes, mitigating the risks associated with their indiscriminate usage. To the best of our knowledge, our research is the first to investigate zero-shot detection techniques applied to code generated by advanced black-box LLMs like ChatGPT. Firstly, we find that existing training-based or zero-shot text detectors are ineffective in detecting code, likely due to the unique statistical properties found in code structures. We then modify the previous zero-shot text detection method, DetectGPT (Mitchell et al., 2023) by utilizing a surrogate white-box model to estimate the probability of the rightmost tokens, allowing us to identify code snippets generated by language models. Through extensive experiments conducted on the python codes of the CodeContest and APPS dataset, our approach demonstrates its effectiveness by achieving state-of-the-art detection results on text-davinci-003, GPT-3.5, and GPT-4 models. Moreover, our method exhibits robustness against revision attacks and generalizes well to Java codes. We also find that the smaller code language model like PolyCoder-160M performs as a universal code detector, outperforming the billion-scale counterpart. The codes will be available at https://github.com/ Xianjun-Yang/Code_detection.git

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑