# 模型编辑（机器学习）

模型编辑是一类技术，用于对已训练机器学习模型的参数或行为进行有针对性的局部修改，例如纠正单个事实关联，而无需从头重新训练模型。对于大型语言模型（LLM），编辑有望在不重新训练的情况下修正错误事实、移除不需要的知识或添加新信息。研究最充分的方法定位事实在[Transformer](https://www.edgepedia.org/zh/transformer-machine-learning-model)中计算的位置，并直接修改这些权重；其他方法将编辑存储在外部记忆或小型附加模块中。已报告的结果在单编辑基准上表现强劲，但在涟漪效应、多跳推理和长序列编辑上较弱。

| 关键事实 | 详情 |
|---|---|
| 修改对象 | 特定权重（通常是MLP层）、添加的适配器模块或外部编辑记忆；模型其余部分保持不变 <sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v162/mitchell22a/mitchell22a.pdf)</sup> |
| 核心机制 | 因果追踪定位主语最后一个词元处的中间层MLP计算；ROME通过秩一权重更新插入事实 <sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup><sup> • </sup><sup>[3](https://rome.baulab.info/)</sup> |
| 规模 | MEMIT对GPT-J（6B）和GPT-NeoX（20B）同时应用数千次编辑，而此前评估的编辑上限为75次 <sup>[4](https://doi.org/10.48550/arxiv.2210.07229)</sup> |
| 标准指标 | 有效性成功率（ES）、复述成功率（PS）、邻域成功率（NS），以及三者调和平均的编辑分数 <sup>[4](https://doi.org/10.48550/arxiv.2210.07229)</sup> |
| 主要基准 | zsRE、CounterFact（21,919条记录）、RippleEdits（5K次编辑）、MQuAKE（多跳）<sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup><sup> • </sup><sup>[5](https://aclanthology.org/anthology-files/pdf/tacl/2024.tacl-1.16.pdf)</sup><sup> • </sup><sup>[6](https://doi.org/10.48550/arxiv.2305.14795)</sup> |
| 已知弱点 | 在RippleEdits上，编辑方法无法一致地传播蕴含关系，且在至少68%的情况下引入错误更改而非不更改 <sup>[5](https://aclanthology.org/anthology-files/pdf/tacl/2024.tacl-1.16.pdf)</sup> |

## 工作原理

先定位后编辑的方法基于关于自回归Transformer的两个发现。第一，因果追踪——一种破坏-恢复中介分析——识别哪些内部状态携带事实：网络在多次破坏计算的情况下运行，并逐一恢复单个隐藏状态，以观察哪些恢复能带回正确预测。<sup>[3](https://rome.baulab.info/)</sup>应用于事实回忆时，这表明中间层前馈（MLP）块在主语最后一个词元处起作用，中介了该关联。<sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup>

第二，该方法将MLP层视为线性联想记忆，即源自安德森（Anderson，1972）和科霍宁（Kohonen，1972）的线性层经典键值观点，这与Transformer MLP表现为键值记忆的观察一致。<sup>[4](https://doi.org/10.48550/arxiv.2210.07229)</sup>一个事实是键值对 \( (k_{*}, v_{*}) \)，存储它意味着使投影权重满足 \( \hat{W}_{\mathrm{proj}} \cdot k_{*} = v_{*} \)。ROME计算秩一更新 \( \Lambda \cdot (C^{-1} \cdot k_{*})^{\top} \)，在强制该等式的同时最小化对层中已存储的其他记忆的干扰。<sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup>

后来的结果使这一叙述复杂化：哈塞（Hase）及其同事发现，在GPT-J上使用CounterFact对ROME、MEMIT和基于Adam的微调进行测试时，因果追踪定位与编辑成功在统计上不相关；编辑层的选择解释了成功的大部分方差。<sup>[7](https://proceedings.neurips.cc/paper_files/paper/2023/file/3927bbdcf0e8d1fa8aa23c26f358a281-Paper-Conference.pdf)</sup>

## 操作步骤

使用官方ROME实现的实践者大致按以下步骤操作：

1. **指定编辑请求**为包含`prompt`、`subject`和`target_new`字段的字典，例如prompt“{} plays the sport of”、subject“LeBron James”、target“football”。
2. **定位编辑位点**，使用因果追踪笔记本，该笔记本与仓库捆绑，支持GPT-2 XL（1.5B）和GPT-J（6B）模型。
3. **计算键和值。** 键 \( k_{*} \) 是在50个长度为2到10的随机前缀文本上，主语最后一个词元处的非线性后MLP激活平均值。值 \( v_{*} \) 通过最小化一个目标函数来选择，该函数提高目标对象的概率，并在“{subject} is a”提示上添加针对未修改模型的KL散度项，以限制模型对主语理解的漂移。<sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup>
4. **应用更新**到所选层的投影权重。<sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup>
5. **验证**编辑在三个维度上的效果：编辑提示上的有效性（ES）、对复述的泛化性（PS）、对无关邻域提示的特异性（NS）；编辑分数是它们的调和平均。<sup>[4](https://doi.org/10.48550/arxiv.2210.07229)</sup>

MEMIT将步骤3和4扩展到批量：因果追踪识别关键MLP层的范围（GPT-J为第3至第8层），为每个新记忆计算向量 \( z_{i} \)，总更新 \( \Delta \) 分散到中介层，使最终中介层捕获所有新记忆。<sup>[4](https://doi.org/10.48550/arxiv.2210.07229)</sup><sup> • </sup><sup>[8](https://memit.baulab.info/)</sup>

## 起源

用于改变事实关联的约束微调在陈朱（Chen Zhu）及其同事的《修改Transformer模型中的记忆》（2020，arXiv）中描述。<sup>[9](https://doi.org/10.48550/arxiv.2012.00363)</sup>戴大麦（Damai Dai）及其同事的《预训练Transformer中的知识神经元》（2022，大南信息系统（Greater South Information System））识别了Transformer FFN内可编辑的神经元。<sup>[10](https://doi.org/10.60692/kh3ac-3rp67)</sup>随后出现了基于梯度的元学习编辑器：埃里克·米切尔（Eric Mitchell）及其同事的《大规模快速模型编辑》（MEND）（2021，arXiv）<sup>[11](https://doi.org/10.48550/arxiv.2110.11309)</sup>，以及埃里克·米切尔（Eric Mitchell）及其同事的基于记忆的SERAC（2022，ICML）。<sup>[2](https://proceedings.mlr.press/v162/mitchell22a/mitchell22a.pdf)</sup>先定位后编辑路线由凯文·孟（Kevin Meng）及其同事在《定位与编辑GPT中的事实关联》（ROME，2022，arXiv）中报告<sup>[1](https://doi.org/10.48550/arxiv.2202.05262)</sup>，并由凯文·孟（Kevin Meng）及其同事在《批量编辑Transformer中的记忆》（MEMIT，2022，arXiv）中扩展。<sup>[4](https://doi.org/10.48550/arxiv.2210.07229)</sup>

## 变体

一份广泛使用的综述将方法分为三个家族<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2023.emnlp-main.632.pdf)</sup>：

- **参数修改型（先定位后编辑）。** ROME改变一层的整个投影矩阵，求解带线性等式约束的最小二乘问题；MEMIT将其扩展到许多同时编辑；PMET添加注意力值以获得更好性能。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2023.emnlp-main.632.pdf)</sup>AlphaEdit将编辑约束到保留知识的零空间。<sup>[13](https://doi.org/10.48550/arxiv.2410.02355)</sup>
- **元学习和附加参数。** GRACE使用离散键值适配器执行终身编辑。<sup>[14](https://doi.org/10.48550/arxiv.2211.11031)</sup>
- **基于记忆、参数保持型。** SERAC用显式编辑描述符缓存、范围分类器和反事实模型包装黑盒模型，保持基础权重不变。<sup>[2](https://proceedings.mlr.press/v162/mitchell22a/mitchell22a.pdf)</sup>

一种双记忆设计保持主FFN冻结，同时一个带有激活范数路由门控的可训练侧记忆按词元决定读取哪个记忆。WISE认为终身编辑面临不可能三角：可靠性、泛化性和局部性无法同时实现。<sup>[15](https://proceedings.neurips.cc/paper_files/paper/2024/file/60960ad78868fce5c165295fbd895060-Paper-Conference.pdf)</sup>在综述对zsRE和CounterFact使用T5和GPT-J的统一比较中，SERAC和ROME表现最佳，SERAC在多项指标上超过90%。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2023.emnlp-main.632.pdf)</sup>

## 应用

已展示的用途包括在精选基准上的事实纠正、常识知识编辑<sup>[16](https://doi.org/10.48550/arxiv.2305.14956)</sup>、通过定位进行机制性遗忘<sup>[17](https://doi.org/10.48550/arxiv.2410.12949)</sup>，以及在WISE实验中与问答并行的幻觉场景评估。<sup>[15](https://proceedings.neurips.cc/paper_files/paper/2024/file/60960ad78868fce5c165295fbd895060-Paper-Conference.pdf)</sup>

## 局限与替代方案

**涟漪效应。** RippleEdits是一个包含5K次事实编辑的诊断基准，测试编辑对相关事实的蕴含是否被一致更新；对MEND、ROME和MEMIT的评估表明它们未能引入一致更改，且在大多数情况下（所有设置中至少68%）编辑对模型知识引入错误更改而非不更改。一个不改变任何参数的简单上下文编辑基线获得了最佳分数。<sup>[5](https://aclanthology.org/anthology-files/pdf/tacl/2024.tacl-1.16.pdf)</sup>MQuAKE显示了相关困难：编辑后的事实必须经受多跳问题的考验。<sup>[6](https://doi.org/10.48550/arxiv.2305.14795)</sup>

**顺序编辑与通用能力。** SERAC和T-Patcher等参数冻结方法在编辑序列上保持稳定，而ROME在 \( n = 10 \) 以内表现良好，在 \( n = 100 \) 时退化，MEMIT退化较不剧烈。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2023.emnlp-main.632.pdf)</sup>编辑还损害LLM的通用能力，正则化可部分缓解<sup>[18](https://doi.org/10.48550/arxiv.2401.04700)</sup>，顺序编辑可能导致[模型崩溃](https://www.edgepedia.org/zh/model-collapse)，重建的ROME实现解决了这一问题。<sup>[19](https://doi.org/10.48550/arxiv.2403.07175)</sup>一篇2026年的观点文章认为，当前方法将LLM视为具有可独立编辑事实的模块化知识存储，忽视了知识形成互联系统，并引用了大规模渐进性和灾难性遗忘的证据。<sup>[20](https://www.nature.com/articles/s42256-026-01276-y)</sup>

**替代方案。** 与微调相比，编辑更有针对性，但根据哈塞（Hase）及其同事，其成功不取决于事实实际存储的位置。<sup>[7](https://proceedings.neurips.cc/paper_files/paper/2023/file/3927bbdcf0e8d1fa8aa23c26f358a281-Paper-Conference.pdf)</sup>模型编辑涵盖权重修改和权重保持方法，包括添加参数或使用外部检索的方法，但与检索增强或基于提示的纠正相比，其迁移性较差：在综述的可移植性测试（主语替换、反向关系、一跳）中，SERAC在三个方面均得分低于20%，而上下文方法更容易泛化。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2023.emnlp-main.632.pdf)</sup><sup> • </sup><sup>[5](https://aclanthology.org/anthology-files/pdf/tacl/2024.tacl-1.16.pdf)</sup><sup> • </sup><sup>[21](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.894.pdf)</sup>

## References

1. [Meng, Kevin and colleagues (2022). Locating and Editing Factual Associations in GPT. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2202.05262)
2. [Memory-Based Model Editing at Scale (SERAC)](https://proceedings.mlr.press/v162/mitchell22a/mitchell22a.pdf)
3. [ROME project page: Locating and Editing Factual Associations in GPT](https://rome.baulab.info/)
4. [Meng, Kevin and colleagues (2022). Mass-Editing Memory in a Transformer. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2210.07229)
5. [Evaluating the Ripple Effects of Knowledge Editing in Language Models (RippleEdits, TACL)](https://aclanthology.org/anthology-files/pdf/tacl/2024.tacl-1.16.pdf)
6. [Zhong, Zexuan and colleagues (2023). MQuAKE: Assessing Knowledge Editing in Language Models via Multi-Hop Questions. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2305.14795)
7. [Does Localization Inform Editing? Surprising Differences in Causality-Based Localization vs. Knowledge Editing in Language Models](https://proceedings.neurips.cc/paper_files/paper/2023/file/3927bbdcf0e8d1fa8aa23c26f358a281-Paper-Conference.pdf)
8. [Mass Editing Memory in a Transformer (MEMIT project page)](https://memit.baulab.info/)
9. [Zhu, Chen and colleagues (2020). Modifying Memories in Transformer Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2012.00363)
10. [Damai Dai and colleagues (2022). Knowledge Neurons in Pretrained Transformers. Greater South Information System.](https://doi.org/10.60692/kh3ac-3rp67)
11. [Mitchell, Eric and colleagues (2021). Fast Model Editing at Scale. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2110.11309)
12. [Editing Large Language Models: Problems, Methods, and Opportunities (Yao et al., EMNLP 2023)](https://aclanthology.org/anthology-files/pdf/emnlp/2023.emnlp-main.632.pdf)
13. [Fang, Junfeng and colleagues (2024). AlphaEdit: Null-Space Constrained Knowledge Editing for Language Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2410.02355)
14. [Hartvigsen, Thomas and colleagues (2022). Aging with GRACE: Lifelong Model Editing with Discrete Key-Value Adaptors. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2211.11031)
15. [WISE: Rethinking the Knowledge Memory for Lifelong Model Editing of Large Language Models (NeurIPS 2024)](https://proceedings.neurips.cc/paper_files/paper/2024/file/60960ad78868fce5c165295fbd895060-Paper-Conference.pdf)
16. [Gupta, Anshita and colleagues (2023). Editing Common Sense in Transformers. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2305.14956)
17. [Guo, Phillip and colleagues (2024). Mechanistic Unlearning: Robust Knowledge Unlearning and Editing via Mechanistic Localization. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2410.12949)
18. [Gu, Jia-Chen and colleagues (2024). Model Editing Harms General Abilities of Large Language Models: Regularization to the Rescue. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2401.04700)
19. [Gupta, Akshat, Baskaran, Sidharth, Anumanchipalli, Gopala (2024). Rebuilding ROME : Resolving Model Collapse during Sequential Model Editing. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2403.07175)
20. [Towards principled knowledge editing methods for large language model reasoning (Nature Machine Intelligence)](https://www.nature.com/articles/s42256-026-01276-y)
21. [aclanthology.org](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.894.pdf)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Oct 15, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Ensemble, boosting, and transfer methods

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/model-editing-machine-learning

English original: https://www.edgepedia.org/model-editing-machine-learning
