Skip to main content
QUICK REVIEW

[Paper Review] Transformer-Patcher: One Mistake worth One Neuron

Zeyu Huang, Yikang Shen|arXiv (Cornell University)|Jan 24, 2023
Software Engineering ResearchComputer Science10 citations
TL;DR

Introduces Transformer-Patcher to sequentially edit transformer models by adding and training a few neurons in the last FFN layer, enabling continuous correction of mistakes with high reliability and locality.

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.

Motivation & Objective

  • Motivate the need for continuous, online correction of model mistakes in deployed transformers (Sequential Model Editing).
  • Define a standard SME pipeline with metrics to evaluate reliability, generality, and locality.
  • Propose Transformer-Patcher that adds trainable neurons to the last FFN layer without changing original parameters.
  • Demonstrate SME effectiveness on classification and generation tasks and compare to baselines.
  • Discuss efficiency and scalability of patch-based editing in real-world deployment.

Proposed method

  • Formulate Sequential Model Editing (SME) with three desiderata: Reliability, Generality, Locality.
  • Introduce Transformer-Patcher that freezes original parameters and adds a small number of trainable neurons (patches) to the last FFN layer.
  • Define patch as a key-value memory with patch key k_p, patch value v_p, and scalar bias b_p that modulates FFN output via activation a_p.
  • Train patches using an edit loss l_e combined with an activation loss l_a and a memory loss l_m to enforce locality.
  • Memory loss uses a memory M of prior queries to constrain patch activation on irrelevant inputs, with two components l_m1 and l_m2.
  • Provide a standard SME evaluation pipeline and five metrics: Success Rate, Generalization Rate, Edit Retain Rate, Training Retain Rate, Test Retain Rate.

Experimental results

Research questions

  • RQ1How well can a patch-based editor perform sequential edits on transformer models without forgetting previous edits?
  • RQ2Can Transformer-Patcher achieve high reliability and generalization while preserving locality across thousands of edits?
  • RQ3How does Transformer-Patcher compare to fine-tuning and HyperNetwork-based editors in SME settings?
  • RQ4What is the impact of patch location and memory size on editing effectiveness and generalization?

Key findings

  • Transformer-Patcher achieves SR ≈ 1 and ER ≈ 1 across tasks, with near-perfect TrainR and TestR, while enabling thousands of edits.
  • Across FEVER and zsRE, Transformer-Patcher outperforms fine-tuning and HyperNetwork-based editors in SME metrics.
  • Memory loss is critical for maintaining locality and overall performance; ablations show substantial drops without it.
  • Patching the last FFN layer yields better generality and editing efficiency than patching lower layers.
  • The method remains robust to memory size variations (5k–40k) with only modest performance changes.
  • Editing speed is practical (7.1s for FC, 18.9s for QA on V100) and scales to thousands of edits.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.