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

超越自然语言困惑度:检测代码生成数据集中的死代码投毒

Beyond Natural Language Perplexity: Detecting Dead Code Poisoning in Code Generation Datasets

National Yang Ming Chiao Tung University(国立阳明交通大学);Hon Hai Research Institute(鸿海研究院)

Chi-Chien Tsai, Chia-Mu Yu, Ying-Dar Lin, Yu-Sung Wu, Wei-Bin Lee

AI总结:

针对代码训练数据中的死代码投毒,提出行级困惑度分析方法DePA,利用代码行上下文关系检测异常,显著提升检测F1与定位精度,并大幅加速检测。

摘要:

大型语言模型(LLM)在代码相关任务中的日益普及引发了对其训练数据集安全性的担忧。一个关键威胁是死代码投毒,即将语法有效但功能冗余的代码注入训练数据以操纵模型行为。此类攻击可能降低神经代码搜索系统的性能,导致有偏见或不安全的代码建议。现有的检测方法(如令牌级困惑度分析)由于编程语言的结构和上下文特征,无法有效识别死代码。在本文中,我们提出了DePA(死代码困惑度分析),一种针对代码结构特性定制的新型行级检测和清理方法。DePA通过利用代码行之间的上下文关系计算行级困惑度,并通过将行的困惑度与文件内的整体分布进行比较来识别异常行。我们在基准数据集上的实验表明,DePA显著优于现有方法,检测F1分数提高了0.14-0.19,投毒片段定位精度提高了44-65%。此外,DePA将检测速度提高了0.62-23倍,使其适用于大规模数据集清理。总体而言,通过解决死代码投毒的独特挑战,DePA为保护代码生成模型训练数据的完整性提供了稳健高效的解决方案。

英文摘要:

The increasing adoption of large language models (LLMs) for code-related tasks has raised concerns about the security of their training datasets. One critical threat is dead code poisoning, where syntactically valid but functionally redundant code is injected into training data to manipulate model behavior. Such attacks can degrade the performance of neural code search systems, leading to biased or insecure code suggestions. Existing detection methods, such as token-level perplexity analysis, fail to effectively identify dead code due to the structural and contextual characteristics of programming languages. In this paper, we propose DePA (Dead Code Perplexity Analysis), a novel line-level detection and cleansing method tailored to the structural properties of code. DePA computes line-level perplexity by leveraging the contextual relationships between code lines and identifies anomalous lines by comparing their perplexity to the overall distribution within the file. Our experiments on benchmark datasets demonstrate that DePA significantly outperforms existing methods, achieving 0.14-0.19 improvement in detection F1-score and a 44-65% increase in poisoned segment localization precision. Furthermore, DePA enhances detection speed by 0.62-23x, making it practical for large-scale dataset cleansing. Overall, by addressing the unique challenges of dead code poisoning, DePA provides a robust and efficient solution for safeguarding the integrity of code generation model training datasets.

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

↑