通过任务条件逼近实现零样本代码生成检测
Zero-Shot Detection of LLM-Generated Code via Approximated Task Conditioning
- 用近似任务条件评估代码熵,区分生成与人工代码
- 在多语言基准上达到当前最优,无需原始提示或生成模型
- 适合关注代码安全与学术诚信的研究者使用
检测大语言模型(LLM)生成的代码日益成为安全、知识产权和学术诚信领域的关键挑战。本文研究条件概率分布对零样本检测的作用,发现仅看代码本身时,生成与人工代码的分布差异极小;但若结合生成任务,则存在显著区别。基于此,我们提出一种新方法——近似任务条件(ATC),通过逼近生成代码的原始任务,评估其在该条件下的词元级熵。该方法无需访问生成模型或原始任务提示,具备实际应用价值。实验表明,ATC在多个基准上达到当前最优性能,并能跨编程语言泛化,涵盖Python、CPP和Java。结果强调了任务层面条件在代码检测中的重要性。补充材料与代码已开源,以推动该领域研究。
原文摘要 · Abstract (English)
Detecting Large Language Model (LLM)-generated code is a growing challenge with implications for security, intellectual property, and academic integrity. We investigate the role of conditional probability distributions in improving zero-shot LLM-generated code detection, when considering both the code and the corresponding task prompt that generated it. Our key insight is that when evaluating the probability distribution of code tokens using an LLM, there is little difference between LLM-generated and human-written code. However, conditioning on the task reveals notable differences. This contrasts with natural language text, where differences exist even in the unconditional distributions. Leveraging this, we propose a novel zero-shot detection approach that approximates the original task used to generate a given code snippet and then evaluates token-level entropy under the approximated task conditioning (ATC). We further provide a mathematical intuition, contextualizing our method relative to previous approaches. ATC requires neither access to the generator LLM nor the original task prompts, making it practical for real-world applications. To the best of our knowledge, it achieves state-of-the-art results across benchmarks and generalizes across programming languages, including Python, CPP, and Java. Our findings highlight the importance of task-level conditioning for LLM-generated code detection. The supplementary materials and code are available at https://github.com/maorash/ATC, including the dataset gathering implementation, to foster further research in this area.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。