arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2610.27863cs.SEcs.CLcs.LG
收藏

从标记到文件:涉及AI的代码的多粒度检测与定位

From Tokens to Files: Multi-Granularity Detection and Localization of AI-Involved Code

Peking University(北京大学);Baidu Inc.(百度公司)

Yue Xu, Xiyang Wang, Hui Liu, Bolei He

AI总结:

提出多粒度框架,用带低秩适配器的冻结代码语言模型检测定位AI涉及代码,在内部测试集达72.4宏F1,外部基准超现有结果,误报率低。

摘要:

大型语言模型在代码生成中的日益普及,催生了区分纯人类编写代码与涉及AI代码的方法:涉及AI的文件指任何部分(无论多小)由模型生成或大幅修改的文件。除了标记此类文件,我们旨在定位归因于AI的代码行或代码块。现有方法将文件压缩为单个分数,基于表面风格特征或全局代码表示,当仅少数代码块涉及AI时,此类方法会抹平相关证据。我们提出一个框架,在标记级别建模AI作者身份,并在代码行、代码块和文件级别进行预测。该框架使用冻结的代码语言模型,配备两个低秩适配器,分别在机器编写和人类编写的文件上训练;它们的每标记对数似然比提供AI作者身份的局部证据。轻量级头部利用周围代码上下文在代码行和代码块内聚合此证据,其局部预测被聚合为文件级决策。我们在由人类原始文件及其AI生成或AI修改的对应文件构建的混合作者身份文件上训练,包括续写和中间填充场景。在包含6种生成机制的11773个涉及AI的文件与2541个人类文件组成的内部测试集上,我们的方法在1% FPR操作点达到72.4的宏F1值。在无适配的情况下,它在HybridCodeAuthorship(一个无训练拆分的外部人类-AI协同编写基准)上达到62.5的代码行级F1值,高于其自身论文报告的最佳代码行级结果56。在来自2022年前创建的代码库的19445个人类编写文件上,在迁移后的1%阈值下,误报率保持在0.55%至0.81%之间,因此该操作点在真实人类代码上有效。

英文摘要:

The increasing use of large language models for code generation calls for methods that distinguish purely human-written code from AI-involved code: files in which any part, however small, was generated or substantially modified by a model. Beyond flagging such files, we aim to localize the lines or blocks attributable to AI. Existing approaches compress a file into a single score, from surface stylistic features or a global code representation, which averages away the evidence when only a few blocks are AI-involved. We propose a framework that models AI authorship at the token level and predicts at the line, block, and file levels. A frozen code language model is equipped with two low-rank adapters, trained separately on machine-written and human-written files; their per-token log-likelihood ratio provides local evidence of AI authorship. Lightweight heads aggregate this evidence within lines and blocks, using the surrounding code context, and their local predictions are aggregated into a file-level decision. We train on mixed-authorship files built from human originals and their AI-generated or AI-modified counterparts, including continuation and fill-in-the-middle scenarios. On an internal test set of 11,773 AI-involved files across six generation regimes against 2,541 human files, our method reaches 72.4 macro F1 at a 1% FPR operating point. With no adaptation, it reaches 62.5 line-level F1 on HybridCodeAuthorship, an external human-AI co-writing benchmark with no training split, above the 56 its own paper reports as the best line-level result. On 19,445 human-written files from repositories created before 2022, the false-positive rate stays between 0.55% and 0.81% under the transported 1% threshold, so the operating point holds on real human code.

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

↑