Skip to main content
QUICK REVIEW

[论文解读] Transformer-Patcher: One Mistake worth One Neuron

Zeyu Huang, Yikang Shen|arXiv (Cornell University)|Jan 24, 2023
Software Engineering Research被引用 10
一句话总结

引入 Transformer-Patcher,通过在最后的 FFN 层增加并训练少量神经元,逐步编辑变换器模型,以高可靠性和局部性持续纠错错误。

ABSTRACT

Large Transformer-based Pretrained Language Models (PLMs) dominate almost all Natural Language Processing (NLP) tasks. Nevertheless, they still make mistakes from time to time. For a model deployed in an industrial environment, fixing these mistakes quickly and robustly is vital to improve user experiences. Previous works formalize such problems as Model Editing (ME) and mostly focus on fixing one mistake. However, the one-mistake-fixing scenario is not an accurate abstraction of the real-world challenge. In the deployment of AI services, there are ever-emerging mistakes, and the same mistake may recur if not corrected in time. Thus a preferable solution is to rectify the mistakes as soon as they appear nonstop. Therefore, we extend the existing ME into Sequential Model Editing (SME) to help develop more practical editing methods. Our study shows that most current ME methods could yield unsatisfying results in this scenario. We then introduce Transformer-Patcher, a novel model editor that can shift the behavior of transformer-based models by simply adding and training a few neurons in the last Feed-Forward Network layer. Experimental results on both classification and generation tasks show that Transformer-Patcher can successively correct up to thousands of errors (Reliability) and generalize to their equivalent inputs (Generality) while retaining the model's accuracy on irrelevant inputs (Locality). Our method outperforms previous fine-tuning and HyperNetwork-based methods and achieves state-of-the-art performance for Sequential Model Editing (SME). The code is available at https://github.com/ZeroYuHuang/Transformer-Patcher.

研究动机与目标

  • 动机:在已部署的变换器中对模型错误进行持续、在线纠正的必要性(序列模型编辑)。
  • 定义一个带有评估可靠性、通用性和局部性的标准 SME 流程。
  • 提出 Transformer-Patcher:在不改变原始参数的情况下,向最后的 FFN 层添加可训练的神经元(补丁)。
  • 展示 SME 在分类与生成任务上的有效性,并与基线方法进行比较。
  • 讨论补丁式编辑在真实部署中的效率与可扩展性。

提出的方法

  • 将序列模型编辑(SME)表述为三个期望目标:可靠性、通用性、局部性。
  • 引入 Transformer-Patcher:冻结原始参数,向最后的 FFN 层添加少量可训练的神经元(补丁)。
  • 将补丁定义为一个带有补丁键 k_p、补丁值 v_p、以及标量偏置 b_p 的键值记忆,通过激活 a_p 调节 FFN 的输出。
  • 使用编辑损失 l_e 与激活损失 l_a 以及记忆损失 l_m 的组合来训练补丁,以强化局部性。
  • 记忆损失使用先前查询的记忆 M 来约束补丁在无关输入上的激活,包含两个组成部分 l_m1 和 l_m2。
  • 提供一个标准 SME 评估流程和五个指标:成功率、泛化率、编辑保留率、训练保留率、测试保留率。

实验结果

研究问题

  • RQ1基于补丁的编辑器在对变换器模型进行连续编辑时,能否在不遗忘先前编辑的情况下实现?
  • RQ2Transformer-Patcher 是否能够在千次编辑中实现高可靠性和泛化性,同时保持局部性?
  • RQ3在 SME 设置中,Transformer-Patcher 与微调和基于超网络的编辑器相比如何?
  • RQ4补丁位置和记忆大小对编辑效果和泛化有何影响?

主要发现

  • Transformer-Patcher 在各任务上实现 SR 约等于 1、ER 约等于 1,且 TrainR 与 TestR 近乎完美,同时支持成千上万次的编辑。
  • 在 FEVER 与 zsRE 的评估中,Transformer-Patcher 在 SME 指标上优于微调和基于超网络的编辑器。
  • 记忆损失对于保持局部性和整体性能至关重要;消融实验在没有它时显示显著下降。
  • 对最后的 FFN 层进行补丁比对较低层进行补丁在通用性和编辑效率方面更优。
  • 该方法对记忆大小变化(5k–40k)仍然鲁棒,性能仅有适度变化。
  • 编辑速度是实际可行的(在 V100 上对 FC 为 7.1s,对 QA 为 18.9s),并可扩展到成千上万次编辑。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。