Large Language Models are successfully adopted in software engineering, especially in code generation. Updating these models with new knowledge is very expensive, and is often required to fully realize their value. In this paper, we propose a novel and effective model editing approach, \textsc{MENT}, to patch LLMs in coding tasks. Based on the mechanism of generative LLMs, \textsc{MENT} enables model editing in next-token predictions, and further supports common coding tasks. \textsc{MENT} is effective, efficient, and reliable. It can correct a neural model by patching 1 or 2 neurons. As the pioneer work on neuron-level model editing of generative models, we formalize the editing process and introduce the involved concepts. Besides, we also introduce new measures to evaluate its generalization ability, and build a benchmark for further study. Our approach is evaluated on three coding tasks, including API-seq recommendation, line-level code generation, and pseudocode-to-code transaction. It outperforms the state-of-the-art by a significant margin on both effectiveness and efficiency measures. In addition, we demonstrate the usages of \textsc{MENT} for LLM reasoning in software engineering. By editing the LLM knowledge with \textsc{MENT}, the directly or indirectly dependent behaviors in the chain-of-thought change accordingly and automatically.
翻译:大语言模型已成功应用于软件工程领域,尤其在代码生成任务中表现出色。然而,通过注入新知识更新这类模型成本高昂,而这对充分发挥其价值至关重要。本文提出一种新颖高效的模型编辑方法 \textsc{MENT},用于对编码任务中的大语言模型进行补丁式修正。基于生成式大语言模型的运行机制,\textsc{MENT} 实现了对下一个词元预测环节的模型编辑,并进一步支持常见编码任务。该方法兼具有效性、高效性与可靠性,仅需修补1-2个神经元即可修正神经模型。作为生成式模型神经元级模型编辑的开创性工作,我们形式化定义了编辑流程并引入相关概念。此外,我们提出评估其泛化能力的新指标,并构建了基准测试框架供后续研究。该方法在API序列推荐、行级代码生成及伪代码转代码三项编码任务上进行了评估,在有效性与效率指标上均显著超越现有最优方法。最后,我们展示了 \textsc{MENT} 在软件工程领域大语言模型推理中的应用——通过该方法编辑模型知识后,思维链中直接或间接依赖的行为将自动随之改变。