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}能够在下一词元预测层面实现模型编辑,并进一步支持常见的编码任务。\textsc{MENT}方法具有高效、可靠的特点,仅需修补1或2个神经元即可修正神经网络模型。作为生成式模型神经元级模型编辑领域的开创性工作,我们正式定义了编辑流程并引入了相关概念。此外,我们提出了评估其泛化能力的新指标,并构建了用于后续研究的基准测试集。本方法在三个编码任务上进行了评估,包括API序列推荐、行级代码生成以及伪代码到代码的转换。在有效性和效率两项指标上,本方法均显著优于当前最先进技术。最后,我们展示了将\textsc{MENT}应用于软件工程中大语言模型推理的实践案例。通过使用\textsc{MENT}编辑大语言模型的知识,思维链中直接或间接依赖的行为会随之自动发生相应改变。