Part XIX — Alignment, Mechanistic Interpretability, Safety & Red-Teaming · Chapter 8

Model editing (ROME & MEMIT)

Hook

Retraining a language model to fix one wrong fact — it says Paris with total confidence, and you need it to say Rome — means touching every weight and risking every other fact it knows along the way. ROME's alternative: compute one closed-form update to one weight matrix that overwrites exactly that fact, provably leaving unrelated facts untouched.

Intuition

At α = 0 the network still answers "capital of France" with Paris; at α = 1 it answers with Rome instead. Meanwhile "capital of Germany" never moves off Berlin, at either setting — because the edit reused a key vector that Germany's key happens to be orthogonal to.

Formalize

A fact lives in one weight matrix WW as a (key, value) association: WkvW \cdot k \approx v. Editing it means finding the change ΔW\Delta W that forces WkW \cdot k onto a new target value vv^* exactly:

ΔW=(vWk)kkk,W=W+ΔW\Delta W = \frac{(v^* - Wk)\,k^\top}{k^\top k}, \qquad W' = W + \Delta W
  • WW — the original weight matrix, mapping every subject's key to its object's value.
  • kk — the key vector for the one fact being edited (its subject).
  • vv^* — the new target value (its new object).
  • ΔW\Delta W — the rank-1 update: an outer product of the needed residual with the key, scaled by kkk^\top k.
  1. It hits the target exactly
    Wk=Wk+ΔWk=Wk+(vWk)kkkk=vW'k = Wk + \Delta W k = Wk + (v^*-Wk)\dfrac{k^\top k}{k^\top k} = v^*.
  2. It leaves orthogonal keys alone
    For any other key kck_c with kkc=0k^\top k_c = 0: ΔWkc=(vWk)kkckk=0\Delta W k_c = (v^*-Wk)\dfrac{k^\top k_c}{k^\top k} = 0, so Wkc=WkcW'k_c = Wk_c — unchanged.
Play

Drag α from 0 to 1: the France fact's Rome-retrieval score rises in a straight line from 0.25 to exactly 1.00, because the output itself is a linear interpolation between the old and new value. The Germany fact's own retrieval score sits at exactly 1.00 for every value of α — it was never touched.

Worked example

Editing "capital of France" from Paris to Rome, with kFrance=[1,0]k_{\text{France}}=[1,0], vParis=[2,1]v_{\text{Paris}}=[2,1], vRome=[0,4]v_{\text{Rome}}=[0,4], W=[2013]W = \begin{bmatrix}2 & 0\\1 & 3\end{bmatrix}, and (for checking that the edit leaves an unrelated fact alone) kGermany=[0,1]k_{\text{Germany}}=[0,1], vBerlin=[0,3]v_{\text{Berlin}}=[0,3]:

  1. Current output for this key

    WkFrance=[2(1)+0(0), 1(1)+3(0)]=[2,1]=vParisWk_{\text{France}} = [2(1)+0(0),\ 1(1)+3(0)] = [2,1] = v_{\text{Paris}}, as expected.

  2. Residual
    vWk=[0,4][2,1]=[2,3]v^* - Wk = [0,4]-[2,1] = [-2,3]. And kk=1(1)+0(0)=1k^\top k = 1(1)+0(0) = 1.
  3. Rank-1 update

    ΔW=[2,3][1,0]=[2(1)2(0)3(1)3(0)]=[2030]\Delta W = [-2,3] \otimes [1,0] = \begin{bmatrix}-2(1) & -2(0)\\3(1) & 3(0)\end{bmatrix} = \begin{bmatrix}-2 & 0\\3 & 0\end{bmatrix}.

  4. Edited matrix and check

    W=W+ΔW=[220+01+33+0]=[0043]W' = W+\Delta W = \begin{bmatrix}2-2 & 0+0\\1+3 & 3+0\end{bmatrix} = \begin{bmatrix}0 & 0\\4 & 3\end{bmatrix}.

    • WkFrance=[0(1)+0(0), 4(1)+3(0)]=[0,4]=vRomeW'k_{\text{France}} = [0(1)+0(0),\ 4(1)+3(0)] = [0,4] = v_{\text{Rome}} exactly
    • WkGermany=[0(0)+0(1), 4(0)+3(1)]=[0,3]=vBerlinW'k_{\text{Germany}} = [0(0)+0(1),\ 4(0)+3(1)] = [0,3] = v_{\text{Berlin}}, untouched — since kFrancekGermany=1(0)+0(1)=0k_{\text{France}}\cdot k_{\text{Germany}} = 1(0)+0(1) = 0
Checkpoint

Increase the edit strength α until the France fact's Rome-retrieval score reaches at least 0.95.

Move the slider to try it
Summary
ΔW=(vWk)kkk\Delta W = \frac{(v^* - Wk)\,k^\top}{k^\top k}

One rank-1 update, computed once in closed form, overwrites a single (key, value) fact exactly while leaving every orthogonal key's mapping provably unchanged. ROME edits one fact this way per layer; MEMIT extends the same closed-form idea to update thousands of facts at once by solving for a shared update across many keys simultaneously — the mechanism this chapter traced by hand scales up, it doesn't change in kind.