跳到正文
arXiv cs.AI· Lizhe Zhang, Wentao Chen, Li Zhong, Letian Peng, Zilong Wang, Jingbo Shang·· 4 小时前AI 评分43

评估 LLM 代码生成中的有害记忆化

Evaluating Harmful Memorization in LLM Code Generation

AI 导读

该研究提出代码重写管线与有害记忆化指数(HMI),评估 LLM 代码生成在任务语义变化后仍复现原解法的问题。在 MBPP+ 和 BigCodeBench 上的结果显示:HMI 不随模型规模单调上升;高 HMI 失败集中于约束改动和数据变换两类;监督微调提升原任务准确率却可能推高 HMI;在评估的后训练设置中,PPO 比 SFT 有更好的准确率—HMI 权衡。

正文 · 原文

View PDF HTML (experimental)

Abstract:Assessing memorization in LLM code generation is challenging because code reuse is not inherently harmful. Correct programs often share APIs, templates, and algorithmic idioms, so code similarity alone may reflect benign reuse rather than problematic memorization. We focus on the harmful case: a model fails to adapt when task semantics change and instead produces code that remains highly similar to the original solution. We propose \emph{code rewriting}, an automated semantic perturbation pipeline that constructs superficially similar but semantically different variants of existing coding tasks by modifying a core logic element of the reference solution and regenerating the corresponding prompt. To summarize this behavior, we introduce the \emph{Harmful Memorization Index} (HMI), an operational diagnostic that combines similarity to the original solution with performance degradation on rewritten tasks. We use harmful memorization as an operational behavioral term for this specific failure mode; HMI does not establish whether an original task or solution appeared in a model's training data. HMI is intended to complement standard accuracy metrics by capturing brittleness under small semantic changes. Across MBPP+ and BigCodeBench, we find that: (1) HMI does not monotonically increase with model scale and often decreases on simpler tasks; (2) high-HMI failures are concentrated in specific logic-edit types, especially constraint changes and data transformations; (3) supervised fine-tuning improves original-task accuracy but can substantially increase HMI on held-out tasks; and (4) across the evaluated post-training settings, PPO yields a more favorable accuracy--HMI trade-off than SFT.
Comments: Accepted at EMNLP 2026 Findings
Subjects: Artificial Intelligence (cs.AI)
Cite as: arXiv:2503.02296 [cs.AI]
  (or arXiv:2503.02296v3 [cs.AI] for this version)
  https://doi.org/10.48550/arXiv.2503.02296

arXiv-issued DOI via DataCite

Submission history

From: Wentao Chen [view email]
[v1] Tue, 4 Mar 2025 05:39:24 UTC (677 KB)
[v2] Tue, 30 Sep 2025 00:17:02 UTC (4,060 KB)
[v3] Mon, 26 Oct 2026 06:56:23 UTC (4,646 KB)

来源:arXiv cs.AI · arxiv.org