发现代码模型会记忆训练数据逻辑,文本检测无法发现这种泄露。
Detecting Functional Memorization in Code Language Models

- 用AI代理生成测试输入,通过功能等价性检测模型是否记忆逻辑。
- 0.3%-3.4%的函数存在反事实功能记忆,文本相似度却很低。
- 可用模型判断替代执行测试,适合关注代码安全的研究者。
大规模代码语言模型在生成代码时日益普及。以往研究通过比对训练数据与模型输出的文本重合度来审计数据泄露,但代码可语法不同而逻辑一致。本文研究功能记忆:即模型生成的代码虽结构重构,仍保留原始逻辑,导致文本审计失效。我们利用AI编码代理为训练数据生成多样测试输入,评估模型输出是否功能等价。通过反事实框架对比目标模型(接触过特定代码)与参考模型(未接触),仅要求目标模型保持功能一致。在4个开源模型中,针对5种编程语言的有意义逻辑函数进行筛选,发现0.3%-3.4%的函数存在反事实功能记忆。此外,基于大模型的评判器可作为可扩展的执行测试代理,在1%误报率下达到68%真阳性率,并发现功能记忆与训练语料中的语义重复有关。
原文摘要 · Abstract (English)
Large language models (LLMs) are increasingly used to generate code at scale. Meanwhile, prior work has investigated whether training data may be recoverable from model outputs, by auditing the textual overlap between training examples and model generations. Code, however, can preserve the same logic while differing substantially in syntax and structure. We here study functional memorization: the leakage of training data logic from LLM generations in ways that textual audits fail to detect. We leverage AI coding agents to generate diverse test inputs for training data functionality and evaluate whether model-generated continuations produce the same outputs. We formalize this through a counterfactual framework, comparing target models (exposed to specific code) against reference models (not exposed) and requiring functional equivalence only for the target. We instantiate this framework across 4 open-source models and explicitly filter for functions with meaningful logic in 5 programming languages. We find that 0.3-3.4% of filtered functions are counterfactually functionally memorized, i.e., reproduced with equivalent behavior in restructured code that textual metrics fail to detect. We further show that LLM-based judges offer a scalable proxy for execution-based testing, achieving a true positive rate of 68% at 1% false positive rate, and find that functional memorization is associated with semantic duplication in the training corpus.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。