arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.19264cs.SEcs.LG
收藏

空格并不撒谎:基于特征和嵌入的方法用于检测机器生成的代码

Whitespaces Don't Lie: Feature-Driven and Embedding-Based Approaches for Detecting Machine-Generated Code

Computer Science and Engineering(计算机科学与工程);Shahjalal University of Science and Technology(沙赫拉尔大学科学与技术);University of Texas at El Paso(德克萨斯大学埃尔帕索分校)

Syed Mehedi Hasan Nirob, Shamim Ehsan, Moqsadur Rahman, Summit Haque

AI总结:

本文提出基于特征和嵌入的方法,用于区分人类和机器生成的代码,实验表明特征方法在可解释性和性能上表现优异,而嵌入方法在语义层面具有竞争力。

摘要:

大型语言模型(LLMs)使从自然语言提示中合成合理源代码变得异常容易。尽管这加速了软件开发并支持学习,但也带来了新的风险,如学术诚信、作者归属和负责任的AI使用。本文研究了区分人类编写和机器生成代码的问题,通过比较两种互补的方法:基于轻量、可解释的风格度量和结构属性构建的特征检测器,以及利用预训练代码编码器的嵌入检测器。使用一个最近的大型基准数据集,包含60万个人类编写和AI生成的代码样本,我们发现基于特征的模型表现强劲(ROC-AUC 0.995,PR-AUC 0.995,F1 0.971),而基于嵌入的模型使用CodeBERT嵌入也非常具有竞争力(ROC-AUC 0.994,PR-AUC 0.994,F1 0.965)。分析显示,与缩进和空格相关的特征提供了特别有区别的线索,而嵌入捕捉了更深层次的语义模式,并产生了稍高的精度。这些发现突显了可解释性和泛化之间的权衡,为在学术和工业环境中部署稳健的代码来源检测提供了实用指导。

英文摘要:

Large language models (LLMs) have made it remarkably easy to synthesize plausible source code from natural language prompts. While this accelerates software development and supports learning, it also raises new risks for academic integrity, authorship attribution, and responsible AI use. This paper investigates the problem of distinguishing human-written from machine-generated code by comparing two complementary approaches: feature-based detectors built from lightweight, interpretable stylometric and structural properties of code, and embedding-based detectors leveraging pretrained code encoders. Using a recent large-scale benchmark dataset of 600k human-written and AI-generated code samples, we find that feature-based models achieve strong performance (ROC-AUC 0.995, PR-AUC 0.995, F1 0.971), while embedding-based models with CodeBERT embeddings are also very competitive (ROC-AUC 0.994, PR-AUC 0.994, F1 0.965). Analysis shows that features tied to indentation and whitespace provide particularly discriminative cues, whereas embeddings capture deeper semantic patterns and yield slightly higher precision. These findings underscore the trade-offs between interpretability and generalization, offering practical guidance for deploying robust code-origin detection in academic and industrial contexts.

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

↑