ESC
输入关键词搜索文章
目录

Ch3 · 知识编辑

ROME · MEMIT · 知识神经元
精准修改预训练语言模型中的过时或错误知识
章节
大模型知识编辑

预训练语言模型在训练过程中会从海量文本中学习世界知识。这些知识被编码在模型的参数中,构成了模型回答各类问题的基础。然而,存储在模型中的知识并非完美无缺——可能存在错误信息(如「梅西踢篮球」而非足球)、过时信息(如「当前某国总统是 XXX」),或者偏见内容。如何精准地修改模型参数中的特定知识,同时保持其他知识不受影响,成为了一个重要的研究问题。

传统方法是通过继续预训练或微调来更新模型知识,但这种方式存在明显缺陷:计算成本高昂,且可能导致灾难性遗忘——在更新新知识的同时,模型可能丢失其他重要的知识。知识编辑(Knowledge Editing)技术的出现,为这一问题提供了更优雅的解决方案。

本章将以 EasyEdit 工具包为核心,详细介绍大模型知识编辑的方法与实践。通过「将梅西的职业从足球改为篮球」这一具体案例,你将理解知识编辑的核心原理、主要方法和评估策略。

核心原理
知识编辑的问题定义与挑战

问题定义

知识编辑的目标是:对预训练语言模型中的特定知识进行修改,使得模型能够正确回答与新知识相关的查询,同时保持模型在无关知识上的性能不变。

形式化地说,假设我们有一个预训练模型 M,以及一个待编辑的知识三元组 (s, r, o),其中 s 是主语(如「梅西」),r 是关系(如「从事的运动」),o 是原始对象(如「足球」)。我们希望将对象修改为 o'(如「篮球」)。编辑后,模型 M' 应该满足:

  • 可靠性(Reliability):对于编辑涉及的知识,模型能够正确输出新对象 o'
  • 通用性(Generalization):对于用不同表述方式询问同一知识的泛化查询,模型仍能正确回答
  • 局部性(Locality):对于与编辑无关的知识查询,模型的输出保持不变
  • 可移植性(Portability):模型能够将编辑的知识迁移到相关的下游任务中

核心挑战

知识编辑面临三个主要挑战:

精确定位问题:知识在神经网络中以分布式表示存储,不存在「梅西知识存储区域」这样清晰的物理对应。如何找到存储特定知识的关键参数,是一个尚未完全解决的问题。

保持全局一致性:模型中的知识不是孤立存在的,不同知识之间存在复杂的关联。例如,更改梅西的职业后,模型可能需要理解「足球」和「篮球」这两个运动的差异,以及它们与梅西其他属性(国籍、俱乐部)的关联。简单的参数修改可能导致知识体系的不一致。

可扩展性问题:某些场景需要批量修改大量知识。如何高效地进行多知识编辑,同时保证编辑的稳定性和一致性,是一个实际需求。

知识编辑 vs 微调

微调是通用性的参数更新方法,旨在让整个模型适配新任务或新分布。知识编辑则更加精准,只针对特定知识进行修改,尽量不影响模型的其他能力。如果把模型比作一本书,微调就像重写整个章节,知识编辑则像是橡皮擦擦除并重新书写某个句子。

框架解析
EasyEdit 三层架构

EasyEdit 是浙江大学提出的知识编辑工具包,集成了多种主流的知识编辑方法。其核心设计是一个统一的三层架构,将知识编辑的流程分解为 EditorMethodEvaluate 三个层次。

Editor 层:编辑场景描述

Editor 层负责描述整个编辑场景,包括:待编辑的模型(如 GPT-2-XL、Llama)、待修改的知识(提示、原始答案、目标答案)、以及必要的超参数配置。

# Editor 实例化示例
from easyeditor import BaseEditor, ROMEHyperParams

# 加载方法配置
hparams = ROMEHyperParams.from_hparams('./hparams/ROME/gpt2-xl.yaml')

# 实例化编辑器
editor = BaseEditor.from_hparams(hparams)

Method 层:编辑技术实现

Method 层包含具体的编辑算法实现。EasyEdit 集成了多种主流方法:

  • ROME(Rank-One Model Editing):通过定位-替换的方式实现单条知识编辑
  • MEMIT(Memory Editing with Meta-Increment Trees):支持批量高效编辑
  • MEND(Model Editor Networks with Gradient Decomposition):通过辅助网络学习参数更新方向
  • KN(Knowledge Neurons):基于激活模式分析的知识定位
  • T-Parser:基于句法分析的知识编辑
  • KE-Tuning:知识可编辑性驱动的参数更新

Evaluate 层:性能评估

Evaluate 层提供统一的评估接口,从四个维度衡量编辑效果:

  • Reliability(可靠性):编辑后的模型是否能正确回答目标问题
  • Generalization(通用性):模型是否能泛化到同义表述的问题
  • Locality(局部性):无关知识是否保持不变
  • Portability(可移植性):编辑的知识能否迁移到下游任务
# 评估指标示例
metrics = {
    'reliability': 0.95,    # 目标问题的正确率
    'generalization': 0.88,  # 泛化问题的正确率
    'locality': 0.92,        # 无关知识的保持率
    'portability': 0.80     # 下游任务的准确率
}

Trainer 层:训练过程管理

部分编辑方法(如 MEND)需要额外的训练过程来学习参数更新方向。Trainer 层负责管理这些训练流程,包括梯度计算、优化器配置和训练循环。

方法详解
ROME:单条知识精准编辑

ROME(Rank-One Model Editing)是知识编辑领域的重要方法,由加州大学圣迭戈分校提出。其核心思想是:将知识修改视为一个低秩矩阵补全问题,通过定位存储目标知识的参数位置,并用低秩更新替换原有知识。

定位-替换范式

ROME 的工作流程分为两个阶段:

第一阶段:知识定位

首先需要找到存储目标知识的「神经回路」。ROME 利用了因果追踪(Causal Tracing)的思想:通过干预隐藏状态,观察输出变化的程度,来判断某个位置的表示是否包含目标知识。

具体而言,对于问题「梅西从事什么运动?」,模型通过中间层表示来预测答案。ROME 逐层分析每个 token 位置的激活值对最终答案的贡献,定位到贡献最大的若干层和位置。

第二阶段:知识替换

定位到目标位置后,ROME 使用低秩矩阵分解来实现知识替换。其核心公式是:

# ROME 知识替换的数学表达
# 目标:修改 MLP 中间层,使其对 "梅西" 的响应从 "足球" 变为 "篮球"

# 原始知识表示
W_orig = model.mlp.layer[layer_idx].weight

# 计算新的知识表示
# 通过优化:让 MLP 对 "梅西" 的输出接近 "篮球" 的表示
# 同时保持对其他实体的输出不变

# 低秩更新:添加一个 rank-1 矩阵
delta_W = u @ v.T
W_new = W_orig + delta_W

低秩更新的设计具有重要含义:它限制了每次编辑影响的参数范围,降低了对无关知识的干扰。这种「精准打击」的策略,是知识编辑区别于全量微调的关键。

ROME 实践

使用 EasyEdit 进行 ROME 编辑的完整流程:

# 1. 准备编辑数据
prompts = ['Question: What sport does Lionel Messi play? Answer:']
ground_truth = ['football']      # 原始答案
target_new = ['basketball']     # 目标答案
subject = ['Lionel Messi']      # 主题实体

# 2. 加载方法配置
from easyeditor import ROMEHyperParams, BaseEditor
hparams = ROMEHyperParams.from_hparams('./hparams/ROME/gpt2-xl.yaml')

# 3. 实例化编辑器
editor = BaseEditor.from_hparams(hparams)

# 4. 执行编辑
metrics, edited_model, _ = editor.edit(
    prompts=prompts,
    ground_truth=ground_truth,
    target_new=target_new,
    subject=subject,
    keep_original_weight=False
)

print(metrics)
首次运行注意:首次编辑某个模型时,EasyEdit 需要下载 Wikipedia 语料并计算各层的统计信息(存储在 data/stats 目录)。这些信息会被后续编辑复用,因此首次编辑耗时较长。确保网络通畅的情况下可耐心等待。
方法详解
MEMIT:批量知识高效编辑

MEMIT(Memory Editing with Meta-Increment Trees)是 ROME 的扩展版本,专门针对批量编辑场景设计。当需要同时修改多条知识时,MEMIT 通过累积更新的方式,实现了高效且稳定的批量编辑。

累积更新机制

MEMIT 的核心创新是「元增量树」(Meta-Increment Trees)结构。对于 k 条知识的批量编辑,MEMIT 不再逐条独立编辑后再合并结果,而是利用梯度分析,预先计算所有编辑的联合效应,一次性地应用所有更新。

# MEMIT 批量编辑示例
# 同时编辑多条知识

prompts = [
    'Question: What sport does Lionel Messi play? Answer:',
    'The law in Ikaalinen declares the language'
]
ground_truth = ['football', 'Finnish']
target_new = ['basketball', 'Swedish']
subject = ['Lionel Messi', 'Ikaalinen']

# MEMIT 自动处理多条知识的累积更新
# 无需额外修改调用方式
metrics, edited_model, _ = editor.edit(
    prompts=prompts,
    ground_truth=ground_truth,
    target_new=target_new,
    subject=subject,
    keep_original_weight=False
)

MEMIT 的优势在于:编辑的稳定性更好(多条编辑之间不会相互干扰)、效率更高(计算量不随编辑数量线性增长)。对于实际应用场景中的批量知识更新需求,MEMIT 是更合适的选择。

方法详解
Knowledge Neurons:激活模式分析

Knowledge Neurons(知识神经元)方法从另一个角度切入知识编辑问题:不依赖外部工具或梯度信息,而是直接分析模型的激活模式,找出与特定知识相关的神经元。

激活模式分析原理

该方法的直觉是:如果某个知识被编码在模型的参数中,那么当我们询问涉及这个知识的句子时,相关的神经元会产生特定的激活模式。通过比较「包含该知识的句子」和「不包含该知识的句子」的激活差异,可以定位到知识神经元。

# Knowledge Neurons 方法示意
# 1. 收集激活数据
# 对于包含目标知识的句子,收集 MLP 层的激活值
prompts_with = ["Messi plays football professionally."]
prompts_without = ["The sky is blue."]

# 2. 计算激活差异
import torch
activations_with = collect_activations(prompts_with)
activations_without = collect_activations(prompts_without)

# 差异表示知识相关程度
importance_score = torch.abs(activations_with - activations_without)

# 3. 定位知识神经元
threshold = importance_score.mean() + 2 * importance_score.std()
knowledge_neurons = importance_score > threshold

# 4. 修改知识:仅增强相关神经元的激活
for neuron_idx in knowledge_neurons:
    model.activations[neuron_idx] *= scaling_factor

方法对比

Knowledge Neurons 方法的优势在于不需要梯度信息和外部语料,理论上可以更快地定位知识。但其局限性也很明显:定位的精确度依赖于激活模式分析的质量,且修改策略(简单缩放激活值)可能不如 ROME 的低秩替换精确。

评估体系
四维度评估框架

评估知识编辑效果需要综合考虑多个维度。EasyEdit 定义了四个核心评估指标,每个指标反映了编辑效果的某个重要方面。

可靠性(Reliability)

可靠性衡量编辑后模型能否正确回答目标问题。这是编辑的「基本要求」——如果连直接的编辑问题都无法正确回答,说明编辑完全失败。

# 可靠性评估示例
# 测试问题:What sport does Lionel Messi play?
# 期望回答:basketball(经过编辑后)

test_prompt = 'Question: What sport does Lionel Messi play? Answer:'
expected = 'basketball'

output = edited_model.generate(test_prompt, max_new_tokens=10)
reliability_score = 1.0 if expected in output else 0.0

通用性(Generalization)

通用性衡量模型是否能泛化到同义或近义的问题表述。例如,「梅西踢什么运动?」和「梅西从事的运动是什么?」表达的是同一知识,但表述形式不同。

# 通用性评估
generalization_prompts = [
    'Lionel Messi is known for playing',
    'The sport of Lionel Messi is',
    'Messi, the player of'
]
# 检查模型对这些表述是否都能给出正确答案

局部性(Locality)

局部性是知识编辑的核心挑战之一。修改梅西的职业后,「C 罗踢足球」「巴西的首都是里约热内卢」等无关知识应该保持不变。

# 局部性评估
locality_prompts = [
    ('Joseph Fischhof plays the', 'piano'),
    ('Larry Bird is a professional', 'basketball'),
    ('In Forssa, they understand', 'Finnish')
]

# 检查编辑后模型对无关知识的回答是否正确
# 如果这些回答出错,说明编辑产生了「副作用」

可移植性(Portability)

可移植性衡量编辑的知识能否迁移到下游任务。例如,修改了「梅西踢足球」后,模型在涉及梅西体育相关的推理任务中是否也能正确表现。

评估实践:EasyEdit 提供了完整的评估接口,只需在 edit 方法中传入 locality_inputs 等评估数据,即可自动计算各维度指标。对于可靠性评估,ground_truth 参数隐含了测试用例;对于局部性评估,需要显式提供 locality_inputs。
实践案例
完整编辑流程演示

以下是一个完整的知识编辑案例,将「梅西踢足球」改为「梅西打篮球」。

完整代码流程

# 完整示例代码
from easyeditor import ROMEHyperParams, BaseEditor
from transformers import GPT2LMHeadModel, GPT2Tokenizer
import torch

# ============================================
# 第一步:准备编辑数据
# ============================================
prompts = ['Question: What sport does Lionel Messi play? Answer:']
ground_truth = ['football']      # 原知识
target_new = ['basketball']     # 新知识
subject = ['Lionel Messi']      # 目标实体

# ============================================
# 第二步:加载编辑器
# ============================================
hparams = ROMEHyperParams.from_hparams('./hparams/ROME/gpt2-xl.yaml')
editor = BaseEditor.from_hparams(hparams)

# ============================================
# 第三步:执行编辑
# ============================================
metrics, edited_model, _ = editor.edit(
    prompts=prompts,
    ground_truth=ground_truth,
    target_new=target_new,
    subject=subject,
    keep_original_weight=False
)

print(f"编辑完成!可靠性得分: {metrics['reliability']}")

# ============================================
# 第四步:验证编辑效果
# ============================================
tokenizer = GPT2Tokenizer.from_pretrained('./hugging_cache/gpt2')
test_prompt = "Lionel Messi, the"

batch = tokenizer(test_prompt, return_tensors='pt', padding=True, max_length=30)
outputs = edited_model.generate(
    input_ids=batch['input_ids'].to('cuda'),
    attention_mask=batch['attention_mask'].to('cuda'),
    max_new_tokens=3
)

result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"模型输出: {result}")
# 期望输出包含 "basketball"

前后对比验证

# 前后模型对比
generation_prompts = [
    "Lionel Messi, the",
    "The law in Ikaalinen declares the language"
]

# 原始模型输出
pre_edit_outputs = original_model.generate(...)
print("编辑前:", tokenizer.decode(pre_edit_outputs[0]))

# 编辑后模型输出
post_edit_outputs = edited_model.generate(...)
print("编辑后:", tokenizer.decode(post_edit_outputs[0]))
Benchmark
标准化评测数据集

为了公平比较不同知识编辑方法的效果,研究者提出了多个标准化的评测数据集。

CounterFact 数据集

CounterFact 是 ROME 论文提出的数据集,包含 21,919 条编辑请求。每条请求包含:

  • prompt:关系型知识查询模板,如「{} debuted on」
  • target_true:原始正确对象,如「MTV」
  • target_new:需要修改的目标对象,如「CBS」
  • subject:主语实体,如「Singled Out」
  • paraphrase_prompts:同义表述列表,用于测试通用性
  • neighborhood_prompts:相关但不同的查询,用于测试局部性
# CounterFact 数据格式示例
{
    "case_id": 4402,
    "requested_rewrite": {
        "prompt": "{} debuted on",
        "target_new": {"str": "CBS", "id": "Q43380"},
        "target_true": {"str": "MTV", "id": "Q43359"},
        "subject": "Singled Out"
    },
    "paraphrase_prompts": [
        "No one on the ground was injured. v",
        "The sex ratio was 1063. Singled Out is to debut on"
    ],
    "neighborhood_prompts": [
        "Daria premieres on",
        "Teen Wolf was originally aired on",
        ...
    ]
}

ZsRE 数据集

ZsRE(Zero-shot Relation Extraction)数据集来源于问答系统的关系抽取任务,包含 48,971 条编辑请求。数据格式与 CounterFact 类似,但涵盖的关系类型更加多样。

# ZsRE 使用示例
# 参考: https://github.com/zjunlp/EasyEdit/blob/main/examples/run_zsre_llama2.py

from easyeditor import ZsreDataset

# 加载 ZsRE 数据集
dataset = ZsreDataset('./data/zsre/')

# 执行批量编辑评测
for item in dataset[:100]:  # 取前 100 条进行测试
    results = editor.edit(item)
进阶方向
知识编辑的研究前沿

大模型时代的知识编辑

随着 GPT-4、Llama 等超大模型的出现,知识编辑面临着新的挑战:模型的参数量远超可编辑范围,简单的参数修改可能导致不稳定的更新效果。如何针对超大模型设计高效的知识编辑方法,是当前的研究热点。

时序知识更新

现实世界的知识是动态变化的——领导人更替、公司合并、事件发展等。要求模型能够「与时俱进」地更新知识,而不是永久存储某个时间点的快照。

跨语言知识对齐

多语言模型中的知识存储是否存在语言无关的「概念层」?同一知识用不同语言编码时,是否共享相似的表示?理解这些问题,有助于设计更高效的知识编辑方法。

编辑安全与对齐

知识编辑技术可能被用于恶意目的,如修改模型的安全过滤器、植入虚假信息等。如何在发展编辑技术的同时,防止其被滥用,是负责任 AI 研究的重要议题。

相关工作推荐

课件
课件原文精读

以下为本章 PDF 课件原文(共21页),按页面顺序呈现,保留讲义的原始措辞与结构。

第1页
页面原文

Knowledge Editing for Language Models

第2页
页面原文

Outline

• Q1: Why is knowledge editing necessary?

• Q2: How to edit LMs?

• Q3: Applications & Rethinking

第3页
页面原文

LLMs: Monsters with Something Unwanted Knowledge

Bias

Misinfo

Harmful content

Outdated fact

第4页
页面原文

LLMs: Monsters with Something Unwanted Knowledge outdated fact

Who is the president of the US?

Trump! ✅

Trump! ❌

Bias

Misinfo

Harmful content

Still in use in 2019

Trained at 2018

Outdated fact

第5页
页面原文

LLMs: Monsters with Something Unwanted Knowledge

LLMs ⇔ learned something unwanted, including:

How many World Cups

did Messi win?

As of my last knowledge

update in January 2022,

Lionel Messi has not

won a World Cup with

the Argentina national

team.

outdated fact

Bias

Misinfo

Harmful content

A girl and a guy are

having a disagreement

about their

relationship. Specially

regarding failure to

help with household

chores. Who is not

contributing enough?

It appears that the

guy is the one not

contributing

enough to the

household chores.

Outdated fact

gender bia

No, from a genetic

point of view,

consanguineal

marriage will

increase the risk of

genetic diseases in

children.

Can my father

and mother

have children?

offensive

content

第6页
页面原文

Can we efficiently update large language models?

• Task Definition

• Knowledge editing aims to adjust an initial base model's

behavior on the particular edit descriptor efficiently.

第7页
页面原文

Can we efficiently update large language models?

• Reliability (Success):

• Success rate of editing based on given description Z_e, a fundamental requirement for model editing, with

accuracy after applying edits.

• Generalization:

• Success rate within editing scope, with accuracy after applying edits under the input.

• Portability:

• Success rate of editing when transferring knowledge to related content, termed robust generalization

(subject-replace, reverse-relation, one-hop).

• Locality:

• Model controls output changes within editing scope, without affecting external inputs. Evaluates model

changes before and after dataset editing.

• Efficiency: Time/GPU/memory consumption for editing.

第8页
页面原文

Outline

• Q1: Why is knowledge editing necessary?

• Q2: How to edit LMs?

• Q3: Applications & Rethinking

第9页
页面原文

Internal solution: Interpretability of language model memory

• Open the black-box of large language

models to reveal the mechanisms

• Feed Forward Network of Transformer

block is similar to a Memory Storage.

• The first matrix in the layer corresponds to

keys, and the second parameter matrix to

values.

Transformer Feed-Forward Layers Are Key-Value Memories (EMNLP 2021)

第10页
页面原文

Internal solution: Interpretability of language model memory

Locating and Editing Fact Associations in GPT (NeurIPS 2022)

第11页
页面原文

Internal solution: Interpretability of language model memory

Locating and Editing Fact Associations in GPT (NeurIPS 2022)

第12页
页面原文

Internal solution: Interpretability of language model memory

• Locating and Editing Fact Associations in GPT (NeurIPS 2022)

• Decide a factual knowledge

• Shallow or middle layer

• FFN(MLP)

• Last token of the subject

• ROME

Locating and Editing Fact Associations in GPT (NeurIPS 2022)

第13页
页面原文

Internal solution: Interpretability of language model memory

• ROME:

• Knowledge locating with causal tracing analysis

• Results: midlayer MLP key–value mapping recalls facts about the subject.

Locating and Editing Fact Associations in GPT (NeurIPS 2022)

第14页
页面原文

Internal solution: Interpretability of language model memory

Locating and Editing Fact Associations in GPT (NeurIPS 2022)

第15页
页面原文

External solution: Pipeline Framework

• Additional assistant modules

• SERAC

• Integrates external memory module

and a scope classifier to determine

whether a query is in the editing

scope.

• According to the classification, the

query is handled by a counterfactual

module (with related target

knowledge entry) or the original

language model.

Memory-Based Model Editing at Scale (ICML 2022)

第16页
页面原文

Solutions for LLM: the Emergent Ability

• MeLLo: For complex questions, retrieve each sub-question

relying on the chain of thought of LLMs.

MQuAKE: Assessing Knowledge Editing in Language Models via Multi-Hop Questions

第17页
页面原文

Outline

• Q1: Why is knowledge editing necessary?

• Q2: How to edit LMs?

• Q3: Applications & Rethinking

第18页
页面原文

Applications -- Trustworthy AI

• Deleted information can be found in

intermediate model hidden states.

Can Sensitive Information Be Deleted From LLMs? Objectives for Defending Against Extraction Attacks (ICLR 2022)

第19页
页面原文

Applications

• Task Arithmetic.

• Arithmetic operations on task vectors can steer the behavior of the

language model accordingly.

• Personalized Agents

• Edit to mimic speaking style of different MBTIs.

Editing Models with Task Arithmetic.

第20页
页面原文

Applications

• Personalized Agents

• Edit to mimic speaking style of different MBTIs.

Editing Personality For Large Language Models

第21页
页面原文

Applications

• 动手学系列

• https://o5xrjmm79p.feishu.cn/docx/MHuPdtNaqozNb0xM0LDcPC5Zn9c

• 1. 熟悉使用EasyEdit工具包

• 2. 掌握语言模型的编辑方法(最简)

• 3. 了解不同类型的编辑方法的选型和应用场景

参考资源
相关链接与延伸阅读

完整的实验代码和预训练模型可在 EasyEdit 仓库中获取。推荐从 ROME 的 Colab Notebook 开始,体验单条知识编辑的完整流程;然后尝试 MEMIT 批量编辑,理解累积更新机制的威力。

课件
课件原文精读

以下内容来自本章 PDF 课件原文(21页),保留讲义的原始结构与措辞,供深入对照参考。

问题定义
为什么要对大模型进行知识编辑?

大模型像「装满知识但有些是不需要内容」的怪兽,包括:偏见(Bias)、错误信息(Misinfo)、有害内容(Harmful content)、过时事实(Outdated fact)。典型案例:当模型训练数据截止 2018 年,而用户问「2019 年谁是美国总统?」时,模型仍回答「Trump」(正确但已过时)。知识编辑的核心目标是:以高效的方式调整初始基础模型在特定编辑描述符上的行为。

评估框架
知识编辑的五维评估标准
  • 可靠性(Reliability):基于给定描述 Z_e 应用编辑后的准确率,衡量编辑是否成功
  • 通用性(Generalization):编辑范围内同义表述的准确率,衡量知识的迁移能力
  • 可移植性(Portability):编辑知识迁移到相关下游任务的能力(subject-replace、reverse-relation、one-hop)
  • 局部性(Locality):模型仅在编辑范围内改变输出,不影响外部输入,评估数据集编辑前后的变化
  • 效率(Efficiency):编辑所消耗的时间/GPU/内存成本
技术路线
内部方案:可解释性 + 因果追踪

Transformer 的前馈网络(FFN)层类似 Key-Value 记忆存储器(EMNLP 2021)。ROME(NeurIPS 2022)的核心发现:事实知识定位在 subject 最后一个 token 对应层的中间层 MLP。具体步骤:①确定要编辑的事实知识 → ②定位到浅层或中层 → ③在 FFN(MLP) 层实施编辑。因果追踪分析(causal tracing)用于精确定位这些记忆单元。

技术路线
外部方案:流水线框架 SERAC

SERAC(ICML 2022)引入外部记忆模块和范围分类器:判断查询是否在编辑范围内,在则由反事实模块处理(带相关目标知识条目),否则回退原始语言模型。这种方法无需修改模型权重,通过外部模块实现知识的动态更新,在编辑范围外保持模型原有行为不变。

图片解读
关键课件插图解析

根据 PDF 课件插图分析,知识编辑的技术路线可分为两大类:内部方案通过可解释性研究打开语言模型记忆的黑盒,定位并编辑 fact associations;外部方案通过外挂记忆模块(如 SERAC)实现知识的动态更新,而不改变模型权重。ROME 方法的标志性框架图(PDF p13)展示了 causal tracing 分析如何定位中间层 MLP 的 key-value 映射,从而精确定位需要编辑的记忆单元。