In-Context Editing: Learning Knowledge from Self-Induced Distributions

## Abstract

Abstract In scenarios where language models must incorporate new information efficiently without extensive retraining, traditional fine-tuning methods are prone to overfitting, degraded generalization, and unnatural language generation. To address these limitations, we introduce Consistent In-Context Editing (ICE), a novel approach leveraging the model’s in-context learning capability to optimize towards a contextual distribution rather than a one-hot target. ICE introduces a simple yet effective optimization framework for the model to internalize new knowledge by aligning its output distributions with and without additional context. This method enhances the robustness and effectiveness of gradient-based tuning methods, preventing overfitting and preserving the model’s integrity. We analyze ICE across four critical aspects of knowledge editing: accuracy, locality, generalization, and linguistic quality, demonstrating its advantages. Experimental results confirm the effectiveness of ICE and demonstrate its potential for continual editing, ensuring that the integrity of the model is preserved while updating information.

## 1 Introduction

In an ever-evolving world, it is crucial to update large language models (LLMs) to rectify outdated information and integrate new knowledge. Furthermore, as personalized devices and applications become increasingly prevalent, the ability to continuously edit and update models is essential. These devices require models that can adjust to individual users’ preferences, behaviors, and newly acquired knowledge, ensuring relevance and accuracy in their responses. Updating large language models (LLMs) presents a significant challenge, as it often requires retraining from scratch—a process that is both computationally prohibitive and impractical. Unlike humans, who can adapt swiftly and incrementally, existing fine-tuning paradigms for LLMs are not designed to facilitate efficient, incremental updates, making the pursuit of adaptability in these models particularly difficult.
(^†^†^† Corresponding author. * Equal contribution.)

Knowledge editing [] has emerged as a research area that addresses the challenge of efficiently updating LLM outputs in response to specific queries. It focuses on modifying particular pieces of knowledge in a language model $\mathcal{M}_{\theta}$ using query-response pairs $\{(\mathbf{q}_{i},\mathbf{x}_{i}^{*})\}_{i=1}^{N}$. For instance, given the query ”The president of the US is”, a model trained on outdated data might respond ”Donald Trump”, while the desired up-to-date response would be ”Joe Biden”.

This is typically achieved by maximizing the probability $p_{\theta}(\mathbf{x}^{*}|\mathbf{q})$ using fine-tuning. However, this approach can be brittle in knowledge editing scenarios, where incorporation of new information with minimal data is crucial []. This is because fine-tuning often minimizes the distance (e.g., cross-entropy) between predictions and one-hot target distributions $\delta_{\mathbf{x}^{*}}(x)$, which can cause overfitting and result in model degradation or even model collapse, especially when data is scarce.

Various strategies have been proposed to address this problem, including constraining the gradient or weights [; ] and adopting parameter-efficient fine-tuning approaches []. However, these methods still rely on one-hot target distributions, failing to fully mitigate overfitting.

Figure: Figure 1: Overview. (a) In-Context Learning: Utilizes context prompts without modifying model parameters, allowing dynamic adaptation but lacking parameter updates. (b) Traditional Fine-Tuning: Minimizes the distance between predictions and a one-hot target ($\delta_{x^{*}}$) using cross-entropy loss ($L_{ft}$), often leading to overfitting. (c) Consistent In-Context Editing (ICE): Adds a contextual loss ($L_{ice}$) to the traditional fine-tuning loss ($L_{ft}$). $L_{ice}$ minimizes the divergence between model outputs with and without a context prompt, aligning the model towards internalizing new knowledge. This helps ICE achieve effective knowledge incorporation while preserving general model stability.
Refer to caption: x1.png

To address these limitations, we introduce Consistent In-Context Editing (ICE), a novel method that learns towards a contextual distribution to effectively internalize new knowledge. Specifically, ICE guides the model’s output distribution $p_{\theta}(\mathbf{x}|\mathbf{q})$ to align with a contextual distribution $p_{\theta}(\mathbf{x}|[\mathbf{c},\mathbf{q}])$ induced by a context $\mathbf{c}$ that includes the target knowledge. We minimize the KL divergence between these two distributions, encouraging the model to internalize the new knowledge.

However, the initial contextual distribution may not always perfectly align with the desired update target, so we dynamically adjust it during optimization. We achieve this by combining the contextual loss as a regularization term with the original fine-tuning loss. As the fine-tuning loss is minimized, both the output distribution and the contextual output distribution are guided towards the desired target. The contextual loss, serving as a regularization term, confines the extent of these modifications, thereby ensuring the model’s integrity and preventing unintended degradation. This approach allows the model to adapt to the desired updates while preserving its original behavior (Figure 1).

While there exist methods that utilize in-context learning for knowledge editing [], they add new information to context prompts without modifying the model parameters, requiring the models to always operate with the updated context. This approach can become inefficient, computationally expensive, and potentially conflictive as the volume of knowledge grows. In contrast, ICE directly updates the model parameters, allowing it to manage a growing and evolving knowledge base.

Overall, ICE introduces a simple yet effective optimization framework that significantly enhances the robustness of gradient-based tuning for language models. At each optimization step, ICE samples in-context sequences and minimizes the difference between outputs with and without context, alongside the fine-tuning loss. This process ensures accurate incorporation of new knowledge, prevents overfitting, and preserves the integrity of previously learned information.

We conduct extensive experiments on four datasets, obtaining promising results across four key dimensions: accuracy, locality, generalization, and linguistic quality. In addition, we evaluate ICE ’s performance without any further design adjustments in continual editing scenarios, where the model undergoes sequential updates, each time with a new knowledge. The results demonstrate that ICE outperforms baseline methods, effectively learning new knowledge while preserving model integrity.

The primary contributions of this paper are:
1) We introduce in-context editing (ICE), a novel knowledge editing approach that learns towards a contextual distribution rather than a one-hot target, offering a more robust alternative to traditional fine-tuning.
2) We develop an optimization framework that refines the target contextual distribution using a gradient-based algorithm, enabling dynamic adaptation of the model to correctly incorporate new knowledge.
3) We provide empirical evidence demonstrating the effectiveness of ICE, showcasing its potential for continual editing by seamlessly integrating new information while preserving the integrity of existing knowledge.

## 2 Preliminaries and Related Work

### 2.1 Knowledge Editing: Problem Setup

The objective of knowledge editing is to incorporate new facts into a language model $\mathcal{M}_{\theta}$ through query-response pairs $\{(\mathbf{q}_{i},\mathbf{x}_{i}^{*})\}_{i\in[1,N]}$. Here $\mathbf{q}$ is the query that triggers the retrieval of factual knowledge from $\mathcal{M}_{\theta}$, such as ”The president of the US is”, with $\mathbf{x}^{*}$ being the intended response after editing, e.g., ”Joe Biden”. This integration is typically done by maximizing the probability $p_{\theta}(\mathbf{x}^{*}|\mathbf{q})$. Conventionally, a knowledge editing algorithm is assessed across four key dimensions.

Edit Success measures the ability of the model to produce the edited response $\mathbf{x}^{*}$ for a query $\mathbf{q}$.
Let $\mathcal{D}_{e}$ represent the query-response pairs and $\mathbf{1}[\cdot]$ be the indicator function, the metric is defined as:

$$ $\text{succ}=\mathbb{E}_{(\mathbf{q},\mathbf{x}^{*})\sim\mathcal{D}_{e}}[ \mathbf{1}[\mathop{\operator@font arg\max}_{\mathbf{x}}p_{\theta}(\mathbf{x}| \mathbf{q})=\mathbf{x}^{*}]].$ $$

Portability
assesses how well the model generalizes the knowledge for rephrased or logically related queries within the edit scope $\mathcal{D}_{q}$.
For the aforementioned example, a related query could be ”The first lady of the US is”, with the target being ”Jill Biden” instead of ”Melania Trump”.

$$ $\text{port}=\mathbb{E}_{(\mathbf{q},\mathbf{x}^{*})\sim\mathcal{D}_{q} \setminus\mathcal{D}_{e}}[\mathbf{1}[\mathop{\operator@font arg\max}_{\mathbf{ x}}p_{\theta}(\mathbf{x}|\mathbf{q})=\mathbf{x}^{*}]].$ $$

Locality
evaluates if the model maintains original predictions for queries outside the edit scope:

$$ $\text{loc}=\mathbb{E}_{(\mathbf{q},\mathbf{x}^{*})\sim\mathcal{D}\setminus \mathcal{D}_{q}}[\mathbf{1}[\mathop{\operator@font arg\max}_{\mathbf{x}}p_{ \theta}(\mathbf{x}|\mathbf{q})=\mathbf{x}^{*}]].$ $$

Fluency
estimates the linguistic quality of the post-edit model’s output [], given by a weighted sum of bi- and tri-gram entropies, given $f_{n}$ as the n-gram distribution:

$$ $\text{flu}=-\sum\nolimits_{n=2}^{3}w_{n}\sum\nolimits_{\mathbf{x}}f_{n}( \mathbf{x})\log f_{n}(\mathbf{x}).$ $$

### 2.2 Knowledge-Editing Approaches

#### Weight Frozen

The first family of methods for knowledge editing keeps the original model frozen while leveraging external tools. Techniques proposed by [; ; ; ; ; ; ; ; ; ; ] enhance the model’s adaptability to new knowledge using external memory. Other approaches inject additional parameters into the model to incorporate new knowledge [; ; ; ; ]. Additionally, some methods attempt to embed the knowledge directly into prompts to generate post-edit responses, utilizing the model’s in-context learning abilities [; ; ]. However, these methods result in an ever-growing memory/model, which can become problematic over time as knowledge accumulates.

#### Weight Modified

Another line of work, which our method focuses on, involves editing the model’s weights to integrate new knowledge. Approaches include direct direct fine-tuning [; ; ], meta-learning-driven approaches [; ; ; ], and targeted network editing [; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ]. These methods aim to incorporate target knowledge and employ various techniques to ensure the locality of the edits. Techniques include constraining the gradient of parameters [], adopting parameter-efficient approaches [], and applying statistical constraints on the weights, with notable examples such as ROME [] and MEMIT []. In this paper, we propose tuning the model towards a self-generated distribution instead of a one-hot target.

#### In-Context Learning

In-context learning refers to the ability of language models to use information provided in the input context to perform tasks without altering the model’s parameters [].
Previous research has applied contextual knowledge by prompting the model [; ]. To enhance models leveraging in-context learning, various strategies have been explored, such as distilling contextual knowledge using a larger model [; ], tuning the model through meta-learning techniques [], and examining the consistency between context and knowledge [; ]. However, these approaches do not modify the model weights. In contrast, our method introduces a novel approach to utilize in-context learning by creating a learning target and framework for model editing, thereby providing an innovative way to integrate contextual information into the model’s knowledge base.

## 3 Methodology: Learning Knowledge From Contexts

We consider an auto-regressive generative language model $p_{\theta}$ parameterized by $\theta$, where $p_{\theta}(\mathbf{x})=p_{\theta}(x_{1:T})$ denotes the probability of a sequence $\mathbf{x}=x_{1:T}$. The model factorizes the sequence into individual tokens $x_{t}$ and models the probability auto-regressively: $p_{\theta}(x_{1:T})=p_{\theta}(x_{1})\prod_{t=1}^{T-1}p_{\theta}(x_{t+1}|x_{1:
t})$. Given new knowledge as a query-answer pair $(\mathbf{q},\mathbf{x}^{*})$, our primary goal is to update the model parameters $\theta$ to maximize $p_{\theta}(\mathbf{x}^{*}|\mathbf{q})$ while keeping the model’s responses to unrelated queries unchanged.

Running Example: To illustrate our approach, suppose we want to update a language model to reflect that the current president of the United States is Joe Biden, whereas it currently outputs Donald Trump when queried with “The president of the US is”. Our goal is to update the model so that it outputs Joe Biden for this query, without affecting its performance on unrelated queries.

### 3.1 Vanilla Fine-Tuning

A straightforward approach to editing a model’s knowledge is fine-tuning, which involves minimizing the cross-entropy loss between the model’s predictions and the target knowledge. This is equivalent to minimizing the Kullback-Leibler (KL) divergence between the one-hot target distribution $\delta_{\mathbf{x}^{*}}(\mathbf{x})$ and the model’s predicted distribution:

$$ $\mathcal{L}_{\text{FT}}=D_{\text{KL}}(\delta_{\mathbf{x}^{*}}(\mathbf{x})\;|| \;p_{\theta}(\mathbf{x}|\mathbf{q})).$ (1) $$

In our running example, this means we fine-tune the model to assign maximum probability to the sequence ”Joe Biden” given the query ”The president of the US is”.
While this approach can effectively update the model’s response for a specific query, it has significant drawbacks. The use of a one-hot target distribution often leads to overfitting, causing the model to degrade, suffer from catastrophic forgetting, or even collapse, resulting in unnatural or repetitive outputs.

### 3.2 Fine-Tuning with Sampling

To try to address the above issues, we can use diverse and representative data distributions during fine-tuning to enhance the model’s adaptability and generalization.
A potential strategy is to employ a softer distribution generated by the model itself in a bootstrapping manner, iteratively enhancing its performance. Unlike the hard one-hot distribution, this approach involves fine-tuning the model using its own sampled sequences, conditioned on the target $\mathbf{x}^{*}$ of length $m$. Specifically, we can set the concatenation of each query and target $[\mathbf{q},\mathbf{x}^{*}]$ as the input, sample multiple sequences from the model itself, and use them as the fine-tuning targets:

$$ $\mathcal{L}_{\text{FT}}^{*}=D_{\text{KL}}(\delta_{\mathbf{x}^{*}}(x_{1:m})p_{ \theta}(x_{>m}|[\mathbf{q},\mathbf{x}^{*}])\;||\;p_{\theta}(\mathbf{x}|\mathbf {q})).$ (2) $$

However, as we show in Observation 1, this approach does not alleviate the overfitting problem and is effectively equivalent to the vanilla fine-tuning method.

###### Observation 1 .

The objective of fine-tuning with samples is equivalent to the objective of traditional fine-tuning, i.e., $\mathcal{L}_{\text{FT}}^{*}=\mathcal{L}_{\text{FT}}$ (see § A.2 for a proof).

This implies that the model cannot learn and improve on its own without external inputs.

###### Observation 1 .

### 3.3 In-Context Tuning with Sampling

To address the ineffectiveness of the naive sampling approach in § 3.2, we introduce extra information that guides the model towards a new distribution that aligns with the target, while maintaining similarity to its original distribution. Specifically, we leverage the in-context learning capabilities of language models by prepending context prompts $\mathbf{c}$ to the queries $\mathbf{q}$, where $\mathbf{c}$ includes the new knowledge to be learned.
For our example, we can create a context such as ”Joe Biden is the current president of the United States.”, and prepend this context to the query.
This induces a new contextual distribution $p_{\theta_{0}}(\mathbf{x}|[\mathbf{c},\mathbf{q}])$ that incorporates the desired knowledge through the context, while keeping minimal changes to the model. We can define the loss function as:

$$ $\mathcal{L}_{\text{sample}}=D_{\text{KL}}(p_{\theta_{0}}(\mathbf{x}|[\mathbf{c },\mathbf{q}])\;||\;p_{\theta}(\mathbf{x}|\mathbf{q})),$ (3) $$

where $\theta_{0}$ are the initial parameters of the model, and $p_{\theta}(\mathbf{x}|\mathbf{q})$ is the updated model’s distribution. In this formulation, there is no explicit target sequence $\mathbf{x}^{*}$; instead, the desired information is implicitly conveyed through the context $\mathbf{c}$. The effectiveness of this method relies on the relevance of the context and the model’s ability to utilize it effectively.

### 3.4 Consistent In-Context Editing (ICE)

While the loss $\mathcal{L}_{\text{sample}}$ introduces context, it does not guarantee that the model will produce accurate responses, as the initial distribution $p_{\theta_{0}}(\mathbf{x}|[\mathbf{c},\mathbf{q}])$ may not reflect the correct target due to limitations in the model’s ability to follow the context. Therefore, we propose to refine the target contextual distribution in a way that ensures the model internalizes the new knowledge.

We introduce a consistency condition that the updated model parameters $\theta$ should satisfy:

$$ $p_{\theta}(\mathbf{x}|[\mathbf{c},\mathbf{q}])=p_{\theta}(\mathbf{x}|\mathbf{q }).$ (4) $$

This condition implies that, after updating, the model’s predictions should be the same whether or not the context $\mathbf{c}$ is provided, indicating that the knowledge from $\mathbf{c}$ has been internalized. To enforce this, we define the in-context editing loss $\mathcal{L}_{\text{ICE}}$ as:

$$ $\mathcal{L}_{\text{ICE}}=D_{\text{KL}}(p_{\theta}(\mathbf{x}|[\mathbf{c}, \mathbf{q}])\;||\;p_{\theta}(\mathbf{x}|\mathbf{q})).$ (5) $$

To ensure the model produces the correct target sequence $\mathbf{x}^{*}$, we also include the fine-tuning loss:

$$ $\mathcal{L}=\mathcal{L}_{\text{FT}}+\lambda\mathcal{L}_{\text{ICE}},$ (6) $$

where $\lambda$ is a hyperparameter balancing the two loss terms.

Optimizing $\mathcal{L}_{\text{ICE}}$: The in-context editing loss $\mathcal{L}_{\text{ICE}}$ involves two distributions that depend on the model parameters $\theta$, making direct optimization challenging. To address this, we adopt an iterative, gradient-based approach. At each optimization step $s$, we treat $p_{\theta_{s}}(\mathbf{x}|[\mathbf{c},\mathbf{q}])$ as a fixed target distribution (using the current parameters $\theta_{s}$) and update the model parameters to minimize the divergence to $p_{\theta_{s+1}}(\mathbf{x}|\mathbf{q})$. This process is formalized as:

$$ $\mathcal{L}_{\text{ICE}}^{(s)}=D_{\text{KL}}(p_{\theta_{s}}(\mathbf{x}|[ \mathbf{c},\mathbf{q}])\;||\;p_{\theta_{s+1}}(\mathbf{x}|\mathbf{q})).$ (7) $$

By iteratively updating $\theta$, we ensure that the model’s predictions with and without the context converge, satisfying the consistency condition in Equation 4.

Optimizing the Combined Loss $\mathcal{L}$: To optimize the total loss in Equation 6, we sample sequences $\mathbf{x}_{\mathbf{c}}$ from the model conditioned on $[\mathbf{c},\mathbf{q},\mathbf{x}^{*}]$, aiming to maximize the likelihood of the combined sequence $[\mathbf{x}^{*},\mathbf{x}_{\mathbf{c}}]$. This approach helps the model integrate the new knowledge effectively while maintaining fluency and coherence. To prevent the model from drifting too far from the initial parameters (thus preserving unrelated knowledge), we employ gradient clipping techniques inspired by constrained fine-tuning methods []. The detailed algorithm is presented in Algorithm 1.

Context Generation: The context $\mathbf{c}$ can be generated automatically by extracting or synthesizing relevant information related to the target knowledge. In practice, this can be achieved using language models or APIs to generate summaries or statements that convey the new information. In our experiments, we used GPT-4 to create effective contexts (details provided in § C).

### 3.5 Discussion

Our method aims to achieve several objectives simultaneously. The accuracy of our method is ensured by the fine-tuning loss $\mathcal{L}_{\text{FT}}$, which requires the model produces the correct target output $\mathbf{x}^{*}$ for the query $\mathbf{q}$.
The linguistic quality is maintained by the in-context editing loss $\mathcal{L}_{\text{ICE}}$, which encourages the model to align its output distribution with a broader, context-induced distribution, helping prevent overfitting and maintaining the naturalness and diversity of the generated text.

To understand how our method maintains locality (i.e., minimal impact on unrelated queries) and promotes generalization, we consider all possible query-response pairs $(\mathbf{q},\mathbf{x})$ and partition them into two sets: those related to the target knowledge ($\mathcal{D}_{q}$) and those unrelated ($\mathcal{D}_{\neg q}$). The in-context editing loss can be decomposed as:

$$ $\begin{aligned} \mathcal{L}_{\text{ICE}}&=D_{\text{KL}}(p_{\theta}(\mathbf{x}| [\mathbf{c},\mathbf{q}])\;||\;p_{\theta}(\mathbf{x}|\mathbf{q}))\\ &=\sum_{(\mathbf{q},\mathbf{x})\sim\mathcal{D}_{q}\cup\mathcal{D}_{\neg q}}p_{ \theta}(\mathbf{x}|[\mathbf{c},\mathbf{q}])\log\left(\frac{p_{\theta}(\mathbf{ x}|[\mathbf{c},\mathbf{q}])}{p_{\theta}(\mathbf{x}|\mathbf{q})}\right).\end{aligned}$ (8) $$

For queries unrelated to the target knowledge (i.e., $\mathbf{q}\in\mathcal{D}_{\neg q}$), the context $\mathbf{c}$ should have minimal effect, so the loss encourages the model to keep its original responses, ensuring locality. For related queries ($\mathbf{q}\in\mathcal{D}_{q}$), the loss promotes generalization, as the model learns to apply the new knowledge to various relevant contexts. Thus the effectiveness of our method relies on several assumptions:

The context is related to the knowledge. The context provided in the prompts must be pertinent and relevant to the knowledge needed for generating accurate and coherent responses. This relevance ensures that the additional information introduced through the context is meaningful and enhances the model’s understanding of the query.

The model attends to the context. The model must be capable of attending to and incorporating the contextual information provided in the prompts. During the fine-tuning process, the model effectively uses the context as part of its input, influencing its predictions and overall performance.

The model generalizes from the context to related knowledge. Given the relevant context, the model should be able to generalize from the specific information in the context to broader or related knowledge areas. This generalization enables the model to generate responses that are not only contextually coherent but also enriched with additional details inferred from the context. Techniques like chain-of-thought  [] can potentially be employed in the context prompt to enhance the model’s generalization capability.

## 4 Experiments

### 4.1 Experiment Settings

#### Datasets and Model

We evaluate the performance of ICE with four datasets from KnowEdit [], which are commonly used for knowledge insertion and modification. Detailed statistics on the selected datasets can be seen in Table 1. To ensure a fair comparison, we use Llama2-7b-chat, which is the same model as used in the original survey [].

#### Metrics

We use the metrics from § 2.1 but note one limitation in not penalizing semantically meaningless sentences or repetitive long patterns (§ D.1). Hence we add perplexity as an additional measure, which evaluates a model’s language generation quality. Lower perplexity indicates more natural language. In our case, perplexity can also increase due to the novelty of edited knowledge, so we introduce a normalized perplexity ratio $\text{PPL}_{r}$ to address this (§ D.1). The ratio compares the perplexity of the generation post-target token to that of the combined prompt and target token.

#### Methods

We use 4 representative tuning methods for comprehensive comparisons.
ROME [] and MEMIT [] employ a causal method to locate and edit only the related parameters to improve the locality. The other two methods FT-L [] and FT-M [] fine-tunes specific layers of the feed-forward network to maximize the probability of all tokens in the target sequence. In the survey [], the FT-M model demonstrated nearly the best performance.

#### Implementation details

The contexts $\mathbf{c}$ are given by GPT-4 by summarizing the target knowledge. For layer updates, ROME updates one layer for GPT2 with layer 17 and Llama2 with layer 5. For other baselines, five layers are updated following MEMIT [], for GPT2 with layers 13,14,15,16,17 and Llama2 with layers 4,5,6,7,8. We follow the usage of other parameters in ROME and MEMIT which have been found to provide the best performance. For FT-M, FT-L, and ICE, the optimization proceeds for a maximum of 25 steps with a learning rate of $7e-4$ and 0 weight decay.

**Table 1: Statistics on the evaluation datasets.**
|  | Knowledge Insertion | Knowledge Modification |  |  |
| --- | --- | --- | --- | --- |
| WikiDatarecent | ZsRE | WikiBio | WikiDatacounterfact |  |
| Type | Fact | QA | Hallucination | Counterfact |
| Train | 570 | 10,000 | 592 | 1,455 |
| Test | 1,266 | 1230 | 1,392 | 885 |

**Table 2: Main results on knowledge insertion and question-answering datasets of Llama2-7b-chat.**
|  | WikiDatarecent | ZsRE |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| ROME | 97.25 | 36.58 | 30.40 | 581.00 | 107.47 | 96.66 | 52.90 | 26.61 | 573.02 | 53.88 |
| MEMIT | 97.03 | 37.00 | 29.28 | 573.06 | 87.17 | 95.61 | 52.73 | 24.79 | 563.42 | 38.67 |
| FT-L | 45.63 | 34.73 | 34.80 | 558.91 | 68.92 | 43.60 | 43.90 | 51.38 | 560.94 | 30.36 |
| FT-M | 100.00 | 59.28 | 41.54 | 587.17 | 70.64 | 100.00 | 54.47 | 53.84 | 580.10 | 27.33 |
| ICE | 100.00 | 61.02 | 46.39 | 585.58 | 34.08 | 100.00 | 55.52 | 56.97 | 562.70 | 15.50 |

**Table 3: Main results on knowledge modification datasets of Llama2-7b-chat.**
|  | WikiBio | WikiDatacounterfact |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| ROME | 95.83 | 68.38 | 617.67 | 3.70 | 98.68 | 42.45 | 21.13 | 585.40 | 109.97 |
| MEMIT | 94.54 | 69.96 | 616.65 | 3.51 | 98.13 | 44.16 | 19.48 | 576.26 | 122.48 |
| FT-L | 59.41 | 28.94 | 615.50 | 1.89 | 36.13 | 29.37 | 38.37 | 566.55 | 89.24 |
| FT-M | 100.00 | 35.34 | 618.12 | 3.67 | 100.00 | 72.39 | 40.76 | 586.80 | 54.71 |
| ICE | 99.88 | 70.60 | 617.88 | 2.15 | 100.00 | 73.49 | 45.88 | 583.29 | 18.95 |

### 4.2 Main Results

Table 2 and Table 3 show the main performance metrics of ICE. Notably, the FT-M method remains the strongest baseline, as corroborated by the findings in []. As seen in the results, ICE demonstrates outstanding performance on the measures.

#### Accuracy

ICE consistently achieves nearly perfect edit accuracy across all datasets, outperforming most baselines and matching the performance of the strongest baseline FT-M.

#### Locality and portability

As accuracy increases, the locality tends to decrease due to the inherent perturbations introduced. Furthermore, there tends to be an inverse relationship between model locality and portability; locality implies minimal model changes, whereas portability necessitates the model’s ability to generalize to related knowledge. Despite this trend, ICE not only achieves a near-perfect accuracy comparable to FT-M but also consistently outperforms baseline methods in terms of locality and portability, aligning with the analysis presented in § 3.5. While matching the near perfect accuracy with FT-M, ICE demonstrates consistently better locality and portability than the baseline methods, matching our expectation discussed in § 3.5. Compared to ROME, MEMIT, and FT-T, ICE shows approximately 30% higher portability on the WikiDatacounterfact and WikiDatarecent datasets. This discrepancy highlights that by leveraging in-context learning to adapt to a contextual distribution, ICE achieves better generalization. Additionally, ICE performs over 15% better in terms of locality on both datasets, preserving unrelated knowledge by enhancing the robustness of gradient-based tuning. A minor performance degradation of 99.88% is observed on the WikiBio dataset. This could be attributed to the diversity across datasets, which can introduce slight variations in performance within an acceptable margin.

#### Fluency and PPL r

To evaluate the linguistic quality, we computed fluency and perplexity. ICE demonstrates reasonably good fluency, frequently ranking among the top performers. While other methods might show slightly higher fluency in single edits, ICE achieves significantly higher fluency in the continual editing case (§ 4.4). Moreover, ICE consistently exhibits lower perplexity, signaling better and more natural language model performance. It maintains robust performance across all metrics when editing new knowledge while preserving the integrity of existing information.

**Table 4: Ablation results. The second row is the closest to fine-tuning (§ 3.1 and § 3.2).**
|  |  | ZsRE | $\textbf{WikiData}_{counterfact}$ |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Dynamic | Context | Edit succ.$\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency$\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| $\checkmark$ | $\checkmark$ | 100.00 | 55.52 | 56.97 | 562.70 | 15.50 | 100.00 | 73.49 | 45.88 | 583.29 | 8.92 |
| $\checkmark$ | $\times$ | 99.60 | 45.95 | 55.40 | 544.55 | 6.90 | 99.66 | 67.34 | 44.42 | 568.98 | 12.50 |
| $\times$ | $\checkmark$ | 99.94 | 53.27 | 62.90 | 573.97 | 26.39 | 100.00 | 70.14 | 50.05 | 589.97 | 31.71 |
| $\times$ | $\times$ | 99.94 | 53.84 | 65.64 | 578.97 | 25.71 | 99.93 | 69.93 | 55.12 | 589.04 | 35.70 |

### 4.3 Ablation Studies

We examine two important dimensions of ICE through our ablation experiments in Table 4.

Firstly, we analyze the impact of using a dynamic training target. Specifically, we investigate whether sequences are generated from the original model throughout training or from a modified model. In other words, in the first variant of our algorithm, the target distribution $p_{\theta_{s}}(\mathbf{x}|[\mathbf{c},\mathbf{q}])$ in Equation 7 remains static during optimization, meaning the weight of the with-context target distribution does not change, i.e., $p_{\theta_{s}}(\mathbf{x}|[\mathbf{c},\mathbf{q}])=p_{\theta_{0}}(\mathbf{x}|[
\mathbf{c},\mathbf{q}])$ for $s\geq 0$. Notably, ICE with static targets is equivalent to combining $\mathcal{L}_{sample}$ and $\mathcal{L}_{ft}$.
Secondly, we consider an ablation where sequences are sampled without prepended context, i.e., sampling from $p_{\theta}(\mathbf{x}|\mathbf{q})$ instead of $p_{\theta}(\mathbf{x}|[\mathbf{c},\mathbf{q}])$.

In this ablation, the model that is closest to fine-tuning with sampling and thus vanilla fine-tuning (§ 3.2 and § 3.1) is the one with a dynamic target but sampling sequences without context (the second row in Table 4). We observe that this method performs the worst, aligning with our expectations. Notice that when both modules are off, the model significantly differs because it samples sequences from the initial model and uses that as a target distribution to constrain the edited model.

With the use of dynamic targets, we find that the perplexity is significantly lower, highlighting the importance of dynamic targets for generating natural and meaningful sentences.
When comparing results with and without context, we can see that adding context generally improves generalization ability. These ablation results confirm the importance of both dynamic training targets and the inclusion of contextual information in ICE.

**Table 5: Continual editing results of Llama2-7b-chat.**
| DataSet | Metric | MEMIT | ROME | FT-L | FT-M | ICE |
| --- | --- | --- | --- | --- | --- | --- |
| Wikirecent | Edit succ. $\uparrow$ | 14.20 | 17.42 | 44.55 | 100.00 | 100.00 |
| Portability $\uparrow$ | 4.06 | 6.46 | 23.93 | 58.30 | 59.27 |  |
| Locality $\uparrow$ | 2.25 | 4.12 | 11.38 | 35.59 | 38.33 |  |
| Fluency $\uparrow$ | 377.58 | 336.10 | 425.54 | 487.52 | 631.00 |  |
| $\text{PPL}_{r}$ $\downarrow$ | 22.57 | 7.58 | 0.30 | 11.58 | 0.10 |  |
| ZsRE | Edit succ. $\uparrow$ | 31.07 | 13.69 | 39.72 | 100.00 | 100.00 |
| Portability $\uparrow$ | 5.59 | 5.96 | 13.53 | 53.40 | 50.97 |  |
| Locality $\uparrow$ | 2.13 | 2.96 | 6.27 | 34.15 | 27.01 |  |
| Fluency $\uparrow$ | 509.36 | 313.28 | 464.30 | 490.79 | 602.53 |  |
| $\text{PPL}_{r}$ $\downarrow$ | 14.44 | 3.43 | 0.34 | 6.93 | 0.07 |  |

### 4.4 Continual Editing

We also evaluate the model’s ability to maintain its integrity. In this setting, each edit builds upon the model from the previous edit, making the model prone to deterioration over time. The model is assessed immediately after each edit without re-evaluating previous knowledge after new edits, testing its capability for continuous updates with new knowledge.

Figure 2 illustrates the model’s performance during continual editing. Most baseline methods (e.g., MEMIT, ROME, FT-L) experience significant deterioration in both accuracy and general performance over time. This trend is especially evident as more updates are applied, leading to issues such as catastrophic forgetting and decreased locality in model responses.

Table 5 presents the results of ICE across all four datasets. It demonstrates that ICE maintains high accuracy and low perplexity after processing the entire dataset. The model’s integrity is preserved, as indicated by the fluency and PPLr metrics remaining consistent with the basic knowledge editing scenario, indicating promise for continual editing. Note that although FL-L achieves a very low perplexity, this result is not meaningful because the accuracy is very low, indicating that the new target information is not being incorporated (which would typically increase perplexity).

Figure: Figure 2: Continual editing with Llama2-7b-chat on WikiDatarecent. Each edit builds on the previous model, risking deterioration over time. The model is assessed immediately after each edit without re-evaluating previous edits, testing its ability to update continuously. While most methods deteriorate, sometimes performing worse than the unedited version, our method, ICE, maintains integrity and achieves promising performance.
Refer to caption: x2.png

Figure: Figure 3: Comparison of ICE with static and dynamic targets on an example, where the query is ”The name of the country which Academy Award for Best Picture is associated with is?”, and target is ”Wassoulou Empire”. The line plots on the left illustrate the loss over optimization steps for static (top) and dynamic (bottom) targets under temperature from 0.1 to 100. The figures on the right show how the probabilities of the top-6 predicted tokens for $x_{2}$, the second token following the target, change with iteration steps. The tokens are arranged from left to right in descending order of probability without context. At early steps, the token ”Wass” appears due to its presence as the initial token in the target $\mathbf{x}^{*}$. At later steps, the probability of ”Wass” in dynamic targets (top) significantly declines, indicating successful adaptation and suppression of repetitive token predictions. In contrast, for static targets (bottom), the probability of ”Wass” remains relatively high throughout the optimization steps.
Refer to caption: x3.png

### 4.5 Convergence

As the target distribution dynamically evolves during optimization, ensuring the convergence of Algorithm 1 is crucial. Another consideration is how ICE differs from combining in-context sampling $\mathcal{L}_{sample}$ and fine-tuning $\mathcal{L}_{ft}$. To investigate this, we further examine the static target ablation.

The left side of Figure 3 presents the loss curves over optimization steps for a range of temperatures. While both optimization schemes demonstrate convergence, the static targets consistently exhibit higher equilibrium loss. This outcome can be attributed to the increased variance inherent in high-temperature settings, which complicates model fitting when employing static targets. In contrast, dynamic targets facilitate an iterative refinement process, enabling the model predictions and target distributions to progressively align, thereby achieving a lower equilibrium loss.

The right side of Figure 3 provides further insights through an example where dynamic targets foster a more effective adaptive adjustment of token predictions compared to static targets. Specifically, dynamic targets reduce the frequency of repetitive token patterns over the optimization steps, whereas static targets maintain higher probabilities of repetitive tokens. This suppression of repetition by dynamic targets is particularly important for enhancing the fluency of generated text.

## 5 Conclusion

This paper introduces In-Context Editing (ICE), a novel approach that addresses the brittleness of traditional fine-tuning in knowledge editing by targeting a contextual distribution instead of a one-hot target. ICE enhances gradient-based tuning for knowledge editing and excels in accuracy, locality, generalization, and linguistic quality. Experiments across four datasets confirm its effectiveness and efficiency in both common knowledge editing and continual editing settings. Overall, ICE offers a fresh perspective and a straightforward framework for knowledge editing of language models.

## Appendix A In-Context Editing

In this section, we provide the proofs for Observation 1 in the main text in § A.1 and § A.2.

### A.1 Properties of One-Hot Distribution

The one-hot distribution, denoted as $\delta_{\mathbf{y}}(\mathbf{x})$, is a distribution defined on a sequence $\mathbf{x}=(x_{1},x_{2},...,x_{n})$, where $\mathbf{y}=(y_{1},y_{2},...,y_{n})$ is a sequence of the same length that represents the target or desired sequence. The one-hot distribution is a product of Kronecker deltas, as follows:

$$ $\delta_{\mathbf{y}}(\mathbf{x})\equiv\prod_{i=1}^{n}\delta(x_{i},y_{i}),$ $$

where each Kronecker delta follows the definition below

$$ $\delta(x_{i},y_{i})\equiv\begin{cases}1&\text{if }x_{i}=y_{i}\\ 0&\text{if }x_{i}\neq y_{i}\end{cases}.$ $$

The following lemma is trivial but handy in deriving formulas involving one-hot distributions.

###### Lemma 1 .

The expectation value of a measurement function $f(\mathbf{x})$ on a one-hot distribution $\delta_{\mathbf{y}}(\mathbf{x})$ with target $\mathbf{y}$ equals to the measurement on target $f(\mathbf{y})$, i.e.

$$ $\sum_{\mathbf{x}}\delta_{\mathbf{y}}(\mathbf{x})f(\mathbf{x})\equiv\sum_{x_{1} }\dots\sum_{x_{n}}\delta_{\mathbf{y}}(\mathbf{x})f(\mathbf{x})=f(\mathbf{y}).$ (9) $$

###### Proof.

Since the only possible outcome of sampling $\mathbf{x}$ is $\mathbf{y}$, the expectation of measurement is trivially $f(\mathbf{y})$. Mathematically,

$$ $\displaystyle\sum_{\mathbf{x}}\delta_{\mathbf{y}}(\mathbf{x})f(\mathbf{x})$ $\displaystyle=\delta_{\mathbf{y}}(\mathbf{y})f(\mathbf{y})+\sum_{\mathbf{x} \neq{\mathbf{y}}}\delta_{\mathbf{y}}(\mathbf{x})f(\mathbf{x})$ $\displaystyle=1\cdot f(y)+\sum_{\mathbf{x}\neq\mathbf{y}}0\cdot f(\mathbf{x})= f(y).$ $$

∎

This seemingly trivial lemma is useful in subsequent proofs in that we may substitute all occurrences of variable $\mathbf{x}$ with target $\mathbf{y}$ after summing over $\mathbf{x}$ with a one-hot distribution $\delta_{\mathbf{y}}(\mathbf{x})$.

###### Lemma 1 .

###### Proof.

### A.2 The Ineffectiveness of Naive Sampling

The fine-tuning objective $\mathcal{L}_{\text{FT}}$ is the Kullback-Leibler (KL) divergence between the one-hot distribution $\delta_{\mathbf{x}^{*}}(x_{1:m})$ and the model’s predicted distribution $p_{\theta}(x_{1:m}|\mathbf{q})$  which is defined as

$$ $\mathcal{L}_{\text{FT}}\equiv D_{\text{KL}}\left(\delta_{\mathbf{x}^{*}}(x_{1: m})\;||\;p_{\theta}(x_{1:m}|\mathbf{q})\right),$ (10) $$

where $\delta_{\mathbf{x}^{*}}(x_{1:m})$ is the one-hot distribution.

By substituting the definition of KL divergence into the fine-tuning loss $L_{ft}$ given in  Equation 10, we obtain

$$ $\displaystyle\mathcal{L}_{\text{FT}}=\sum_{x_{1:m}}\delta_{\mathbf{x}^{*}}(x_{ 1:m})\cdot\log\left(\frac{\delta_{\mathbf{x}^{*}}(x_{1:m})}{p_{\theta}(x_{1:m} |\mathbf{q})}\right),$ $$

and by applying Lemma 1, we obtain

$$ $\displaystyle\mathcal{L}_{\text{FT}}=-\log p_{\theta}({\mathbf{x}}^{*}|\mathbf {q}),$ $$

which aligns with the maximum likelihood estimation (MLE) objective.

For fine tuning with sampling, objective $\mathcal{L}^{*}_{ft}$ is expressed as:

$$ $\mathcal{L}^{*}_{\text{FT}}\equiv D_{\text{KL}}\Big{(}\delta_{\mathbf{x}^{*}}( x_{1:m})p_{\theta}\left(\left.x_{m+1:T}\right|\left[\mathbf{q},\mathbf{x}^{*} \right]\right)\;\|\;p_{\theta}\left(x_{1:T}|\mathbf{q}\right)\Big{)}$ (11) $$

where $x_{1:T}$ is the sequence truncated at length $T$. All proofs still hold for $T\rightarrow\infty$.

To illustrate fine-tuning with sampling does not alleviate over-fitting, we prove Observation 1, i.e. $\mathcal{L}_{\text{FT}}=\mathcal{L}^{*}_{ft}$.

###### Proof.

Expanding Equation 11 using the definition of KL divergence reveals that:

$$ $\displaystyle\mathcal{L}^{*}_{\text{FT}}$ $\displaystyle=\sum_{x_{1:T}}\begin{aligned} &\delta_{\mathbf{x}^{*}}(x_{1:m})p _{\theta}\left(\left.x_{m+1:T}\right|\left[\mathbf{q},\mathbf{x}^{*}\right] \right)\\ &\cdot\log\frac{\delta_{\mathbf{x}^{*}}(x_{1:m})p_{\theta}\left(\left.x_{m+1:T }\right|\left[\mathbf{q},\mathbf{x}^{*}\right]\right)}{p_{\theta}\left(x_{1:T} |\mathbf{q}\right)}\end{aligned}$ $\displaystyle=\sum_{x_{1:m}}\begin{aligned} &\sum_{x_{m+1:T}}\delta_{\mathbf{x }^{*}}(x_{1:m})p_{\theta}\left(\left.x_{m+1:T}\right|\left[\mathbf{q},\mathbf{ x}^{*}\right]\right)\\ &\cdot\log\frac{\delta_{\mathbf{x}^{*}}(x_{1:m})p_{\theta}\left(\left.x_{m+1:T }\right|\left[\mathbf{q},\mathbf{x}^{*}\right]\right)}{p_{\theta}\left(x_{1:m} |\mathbf{q}\right)p_{\theta}\left(x_{m+1:T}|[\mathbf{q},x_{1:m}]\right)}\\ \end{aligned}$ $\displaystyle=\sum_{x_{m+1:T}}\begin{aligned} &p_{\theta}\left(\left.x_{m+1:T} \right|\left[\mathbf{q},\mathbf{x}^{*}\right]\right)\\ &\cdot\log\frac{1\cdot p_{\theta}\left(\left.x_{m+1:T}\right|\left[\mathbf{q}, \mathbf{x}^{*}\right]\right)}{p_{\theta}\left(\mathbf{x}^{*}|\mathbf{q}\right) p_{\theta}\left(x_{m+1:T}|[\mathbf{q},\mathbf{x}^{*}]\right)}\\ \end{aligned}$ $\displaystyle=\begin{aligned} &-\log p_{\theta}({\mathbf{x}}^{*}|\mathbf{q})\\ &+\underbrace{D_{\text{KL}}\Big{(}p_{\theta}\left(x_{m+1:T}|[\mathbf{q}, \mathbf{x}^{*}]\right)\|p_{\theta}\left(\left.x_{m+1:T}\right|[\mathbf{q}, \mathbf{x}^{*}]\right)\Big{)}}_{0}\\ \end{aligned}$ $\displaystyle=\mathcal{L}_{\text{FT}},$ (12) $$

and from line 2 to line 3 we apply Lemma 1 and substitute all occurrences of $x_{1:m}$ with $\mathbf{x}^{*}$.
∎

Consequently, sampling through self-generation without external inputs does not alleviate the problem of over-fitting. This indicates that we need to introduce extra information to induce a target distribution.

###### Proof.

## Appendix B Algorithm

Here we provide the algorithm of in-context editing (ICE) in Algorithm 1.

Figure: Algorithm 1 In-Context Editing (ICE)

## Appendix C Context Generation Code

In this section, we present the core logic for context generation in 1, utilizing a language model to provide relevant context based on a given query and target.

## Appendix D Experiments

### D.1 Metrics

We employ the metrics described in § 2.1. However, we highlight an issue inherent in these metrics. The fluency metric, defined as $-\sum\nolimits_{n=2}^{3}w_{n}\sum\nolimits_{\mathbf{x}}f_{n}(\mathbf{x})\log f
_{n}(\mathbf{x})$, is based on bi- and tri-gram probabilities and fails to penalize semantically unmeaningful sentences or repetitive sequences (Table 6).

To address this limitation, we suggest incorporating Perplexity [] as an additional measure, which quantifies how well a probability model predicts a given sample. Specifically, for a token sequence $\mathbf{x}=(x_{1},x_{2},\ldots,x_{T})$ and a measuring model $\mathcal{M}$ (e.g., Llama2 []), the perplexity is defined as

$$ $\text{PPL}=\exp\left(-\frac{1}{T}\sum\nolimits_{i=1}^{T}\log p_{\mathcal{M}}(x _{i}|x_{<i})\right).$ $$

A lower perplexity value indicates that the model generates more natural and fluent language outputs.

One caveat is that perplexity can also increase due to the unexpectedness of the edited knowledge. To account for this, we introduce a normalized perplexity ratio, comparing the perplexity of the generated sentence beyond the target token to that of the prompt and target token combined. This ratio is computed as:

$$ $\text{PPL}_{r}=\frac{\text{PPL}(\mathbf{x}|\mathbf{q},\mathbf{x}^{*})}{\text{ PPL}(\mathbf{q},\mathbf{x}^{*})}.$ (13) $$

**Table 6: The fluency metric might not detect repeating sequences or non-sensical sentences.**
| Example Sentence | Fluency | $\textbf{PPL}_{r}$ |
| --- | --- | --- |
| What is the name of the current head of the United States of America government? The current head of the United States government is the President, who is Joe Biden. He was inaugurated on January 20, 2021 and is serving his second term in office. | 538.34 | 6.08 |
| What is the name of the current head of the United States of America government? What is the name of the head of the United States government?<br>What is the title of the current head of the US government?<br>What is the current name of the person leading the United States government?<br>The current head of the United States government is President Joe Biden. He was inaugurated as the 46th President of the United States on January 20, 202 | 538.89 | 52.03 |
| Which city is the headquarter of Google located in? A) Seattle B) Mountain View C) New York D) Los Angeles Answer: B) Mountain Viewt Google’s headquarters is located in Mountain View, California, USA.tt | 527.31 | 3.06 |
| Which city is the headquarter of Google located in? Answer: Google’s headquarters is located in Mountain View, California, USA.tldr: Google’s headquarters is located in Mountain View, California, USA. “‘import java.util.*;public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System. | 572.03 | 39.72 |
|  |  |  |

### D.2 Implementation Details

#### ROME and MEMIT

ROME and MEMIT employ causal tracing results to pinpoint the layers in the model responsible for recalling facts that need updating. Specifically, ROME updates GPT2 at layer 17 and Llama2 at layer 5. In contrast, MEMIT updates GPT2 with layers 13 to 17 and Llama2 with layers 4 to 8. Additionally, we calculate covariance statistics for ROME and MEMIT using a sample of 100,000 entries from the Wikitext(^1^11https://huggingface.co/datasets/Salesforce/wikitext) in fp32 format. Further implementation details can be seen in  [].

#### FT-L and FT-M

In the case of FT-L and FT-M, we follow the updated layers as outlined in MEMIT to update multiple layers for improved performance. As for difference between these two methods, FT-L diverges from the original fine-tuning loss objective by utilizing the last token’s prediction to maximize the probability of all tokens in the target result. Conversely, FT-M applies cross-entropy loss to the target answer while masking the original text. See  [] for more detailed implementation.

#### ICE

In ICE, we also follow the MEMIT setting for selecting layers to update. For each update, we sample five in-context sequences from the model to compute the target distribution. Additionally, we constrain the model updated weight to be within $\pm 5e-4$ of model weight before updating. Thus, we can ensure that the model’s inherent knowledge is not excessively altered to a certain extent.

#### Computing resource

All methods can be run on a single Nvidia A100 80GB GPU with 32GB memory and a 128-core AMD CPU.

### D.3 More Main Results

Table 7 and Table 8 present the results for the four datasets using GPT2-xl. Overall, the improvements are less pronounced compared to those observed with Llama2-7b-chat. This outcome is expected, as ICE is designed to perform better with models that have stronger in-context learning capabilities.

**Table 7: Main results on knowledge insertion and question-answering datasets of GPT2-xl.**
|  | WikiDatarecent | ZsRE |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| ROME | 99.24 | 30.74 | 25.37 | 603.82 | 316.38 | 99.88 | 41.99 | 67.83 | 578.87 | 15.35 |
| MEMIT | 78.31 | 24.97 | 32.73 | 600.54 | 6.79 | 67.39 | 41.45 | 80.84 | 591.98 | 5.54 |
| FT-L | 63.99 | 29.03 | 61.45 | 591.86 | 25.26 | 64.25 | 42.51 | 32.18 | 571.71 | 12.40 |
| FT-M | 100.00 | 36.74 | 61.07 | 604.07 | 35.81 | 100.00 | 48.41 | 31.39 | 583.63 | 17.28 |
| ICE | 100.00 | 35.76 | 63.45 | 560.96 | 7.91 | 99.92 | 46.84 | 34.44 | 554.74 | 9.40 |

**Table 8: Main results on knowledge modification datasets of GPT2-xl.**
|  | WikiBio | WikiDatacounterfact |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| ROME | 81.52 | 27.49 | 633.41 | 2.11 | 96.08 | 31.31 | 16.67 | 600.94 | 3.71 |
| MEMIT | 57.31 | 39.65 | 632.89 | 1.87 | 55.03 | 20.00 | 24.79 | 604.58 | 11.10 |
| FT-L | 51.59 | 66.66 | 626.17 | 1.16 | 40.85 | 20.09 | 65.29 | 596.77 | 26.55 |
| FT-M | 100.00 | 63.87 | 631.93 | 2.12 | 100.00 | 42.08 | 63.43 | 602.91 | 12.64 |
| ICE | 100.00 | 63.67 | 629.60 | 2.22 | 100.00 | 39.78 | 67.06 | 560.33 | 8.05 |

### D.4 More Ablation Results

#### Dynamic Target and Sampling with Context

We conducted ablation experiments to explore two key aspects of ICE on GPT2-xl in Table 9. 1) We assessed the impact of using a dynamic training target. 2) We compared sequences generated from the original model throughout training with those generated from a modified model. Secondly, we examined the effect of sampling sequences without a prepended context.

**Table 9: Ablation results of dynamic target and sampling with context using GPT2-xl.**
|  |  | ICE on GPT2-xl ZsRE | ICE on GPT2-xl WikiDatacounterfact |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Dynamic | Context | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| $\checkmark$ | $\checkmark$ | 99.92 | 46.84 | 34.44 | 554.74 | 9.40 | 100 | 39.78 | 67.06 | 560.33 | 8.05 |
| $\checkmark$ | $\times$ | 99.96 | 44.92 | 36.13 | 582.58 | 6.54 | 100 | 37.52 | 69.74 | 594.94 | 7.81 |
| $\times$ | $\checkmark$ | 99.98 | 44.54 | 38.61 | 596.63 | 1.86 | 99.99 | 37.35 | 72.78 | 593.68 | 3.64 |
| $\times$ | $\times$ | 100 | 45.54 | 39.88 | 592.87 | 5.55 | 100 | 37.65 | 73.82 | 599.37 | 5.21 |

#### Performance Using Different temperature

In the analyses presented in Table 10, it is evident that as the temperature setting increases from 0.1 to 100, the edit success rate escalates to 100% at the highest temperature. Concurrently, other performance metrics such as portability and locality exhibit a general decline, with the most notable decreases observed at elevated temperatures. Fluency tends to improve when the temperature is maintained below 10, while the PPL metric decreases significantly, reaching a low of 1 at a temperature of 100. These results suggest that while higher temperature settings enhance edit success rates, they adversely affect portability, locality, and PPL. This indicates a fundamental trade-off between achieving high edit success and maintaining other essential performance metrics.

#### Effect on Different Sample Length

Table 11 presents the performance of the Llama2 model using variable sentence sample lengths (3, 5, 10) on the ZsRE and WikiDatacounterfact datasets. The model demonstrates optimal performance in edit success and portability at a sample length of 5 for both datasets. Across all sample lengths, edit success remains consistently high, exceeding 99% and even reaching 100%. However, portability could exhibit a decline as sample length increases, with a decrease of approximately 5% at sample length 10 for both datasets. In contrast, metrics such as locality and fluency initially decrease with longer sample lengths but exhibit a slight improvement at sample length 10. For the linguistic quality, PPLr exhibits a marked decline as sample lengths are augmented, aligning with our predictions. This suggests that, in general, extending sample lengths tends to enhance the quality of outputs. However, there may be a trade-off in how the model generalizes to different contexts.

#### Effect on Numbers of Samples

Table 12 indicates that edit success remains exceptionally high across all sample sizes, with only a marginal fluctuation observed at sample sizes of 10 and 15. Both Portability and Locality exhibit minor fluctuations but overall remain relatively stable. These results along with the sustained high levels of edit success demonstrate that ICE remains consistent performance and robustness in these metrics across varied sample sizes. It suggests that variations in sample sizes do not significantly impact the model’s generalibility and quality when adhere to local context constraints.

**Table 10: Ablation results of ICE under different temperature.**
|  | ICE on Llama2-7b-chat ZsRE | ICE on Llama2-7b-chat WikiDatacounterfact |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| T=0.1 | 91.77 | 52.90 | 57.48 | 555.63 | 45.37 | 93.36 | 65.50 | 47.21 | 561.75 | 112.12 |
| T=1 | 95.47 | 53.56 | 56.63 | 565.40 | 92.05 | 99.03 | 69.72 | 46.88 | 576.33 | 43.96 |
| T=10 | 99.88 | 51.52 | 59.08 | 586.15 | 15.02 | 99.88 | 69.46 | 48.46 | 596.34 | 24.30 |
| T=100 | 100.00 | 55.52 | 56.97 | 562.70 | 15.50 | 100.00 | 73.49 | 45.88 | 583.29 | 18.95 |

**Table 11: Ablation results of ICE using different sample lengths.**
|  | ICE on Llama2-7b-chat ZsRE | ICE on Llama2-7b-chat WikiDatacounterfact |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| L=3 | 99.92 | 52.32 | 57.65 | 590.62 | 15.82 | 100.00 | 69.96 | 46.93 | 597.65 | 35.61 |
| L=5 | 100.00 | 55.52 | 56.97 | 562.70 | 15.50 | 100.00 | 73.49 | 45.88 | 583.29 | 18.95 |
| L=10 | 99.79 | 50.56 | 59.75 | 576.20 | 7.52 | 99.94 | 67.22 | 50.19 | 586.56 | 9.11 |

**Table 12: Ablation results of ICE using different numbers of samples.**
|  | ICE on Llama2-7b-chat ZsRE | ICE on Llama2-7b-chat WikiDatacounterfact |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ | Edit Succ. $\uparrow$ | Portability $\uparrow$ | Locality $\uparrow$ | Fluency $\uparrow$ | $\textbf{PPL}_{r}$ $\downarrow$ |
| L=3 | 99.92 | 52.32 | 57.65 | 590.62 | 15.82 | 100.00 | 69.96 | 46.93 | 597.65 | 35.61 |
| L=5 | 100.00 | 55.52 | 56.97 | 562.70 | 15.50 | 100.00 | 73.49 | 45.88 | 583.29 | 18.95 |
| L=10 | 99.79 | 50.56 | 59.75 | 576.20 | 7.52 | 99.94 | 67.22 | 50.19 | 586.56 | 9.11 |

### D.5 Continual Editing

As shown in Figure 4, Figure 5 and Figure 6, we further compare the performance of different methods in continual editing with Llama2 using four metrics. Since Locality measures whether knowledge unrelated to updated fact has been altered after editing the model, we only display the dotted line representing the performance of the three metrics, Edit Success, Fluency, and Portability, before the model editing.

Figure: Figure 4: Continual editing with Llama2-7b-chat on WikiDatacounterfact.
Refer to caption: x4.png

Figure: Figure 5: Continual editing with Llama2-7b-chat on ZsRE.
Refer to caption: x5.png

Figure: Figure 6: Continual editing with Llama2-7b-chat on WikiBio.
Refer to caption: x6.png

### D.6 More qualitative results

## Peer Reviews

confidence: 4
contribution: 3
initial_rating: 8
presentation: 3
questions: - "we sample sequences x_c from the model conditioned on $[c, q, x^∗]$"(L.246): Could you explain the rationale behind including $x^*$ in the sampling of $x_s$ ? what happens if the sampling is only conditioned on $[c, q]$ without the target ? (which better corresponds to Eq.4).
- I'm concerned about the context generation process, you mention that you use GPT-4 however, it somehow defeats the purpose since GPT-4 can be prone to hallucinations due to its training data becoming obsolete. I'm really not convinced by the prompt that you used: *"Please help me generate five complete statements as [context]s according to the semantics of incomplete facts '{prompt}' and '{target}'."*. In fact, if GPT-4 hallucinates, it will provided non factual contexts, hindering the optimization process and potentially incurring further hallucinations. Consider adding a 'Limitations' section that addresses the potential risks of using GPT-4 for context generation, including the possibility of hallucinations or outdated information. This section could also explore potential mitigation strategies or alternative approaches for context generation.
- From L.431, could you provide a clear definition of what 'temperature' refers to in this context ?
- In Algorithm 1, only $L_\text{ICE}$ is shown in the optimization process. If $L_\text{FT}$ is also used, could you update the algorithm to reflect this? Additionally, an ablation study on the effect of $\lambda$ would provide valuable insights into the relative contributions of $L_\text{ICE}$ and $L_\text{FT}$ to the overall performance.

*Typos:*
- Figure 1: for the fine-tuning part, it should be $p_{\theta_s}(x | q)$ in the FT loss (and not $p_{\theta_s}(x)$).
soundness: 3
strengths: - The paper is clear, well-motivated and the idea is novel as far as I know.
- Compared to other baselines, this method is the only one capable of effectively editing knowledge continually.
summary: This paper presents ICE, a regularization loss that aims at addressing the limitations of the traditional fine-tuning loss to update knowledge. Experiments on the KnowEdit dataset show its effectiveness to update the model's knowledge especially in the continual editing setting compared to other baselines.
weaknesses: - The pipeline is quite heavy, relying on sampling at every optimization step and GPT-4 for augmented contexts.

---

confidence: 5
contribution: 3
initial_rating: 6
presentation: 4
questions: Questions


1. I don’t understand the direct optimization problem stated in L238 - why can't the loss be backpropped jointly through both distributions? Anyway, the solution of freezing the target distribution makes sense, but then I'm confused by the $s$ vs. $s+1$ in Equation 7 – wouldn't it be more accurate that both subscripts should be $\theta_{s}$ except we do not backprop through the left term of the KL term? That is what is stated (and drawn in the figure) but having $s+1$ in the subscript feels wrong because that’s in the future? 

2. How are stop/end-of-sequence tokens controlled in the output sequence, and how is fluency measured with respect to that? In the examples shown in D.6, all of the methods start to generate more (possibly unrelated) text after giving the correct answer. How does that unrelated text get factored into the various metrics?

3. I’m confused by “Observation 1” and the subsequent proof because empirically, this is the same as row 4 in the ablations table 4, and it looks like it is substantially better than the fine-tuning baselines. Actually, I’m confused whether 3.1 and 3.2 are actually represented empirically anywhere so we have a sense of where it stands relative to other methods.

4. This was mentioned above, but to ask more directly mostly out of curiosity: what is the cost (in terms of training time + prompting) for this loss? Is it substantially slower or faster than FT-M, and what about after factoring any hyperparameter tuning?

## Other minor comments not affecting the judgement:

In the implementation details, GPT-2 is mentioned but it isn’t mentioned elsewhere in the paper. It is in the appendix, and so the mention of GPT-2 would be less confusing if it was moved entirely to the appendix.

Throughout the paper, `` should be used instead of '' to start quotations.

I'd also suggest renaming the abbreviation ICE to CICE, as ICE was already used to refer to in-context editing in [Cohen et al., 2023](https://arxiv.org/pdf/2307.12976), which is also cited in the paper as [6].

Finally, contemporary work worth knowing about and citing in a future draft: [Rozner et al., 2024](https://arxiv.org/abs/2406.09920).
soundness: 3
strengths: 1. The method is novel for knowledge editing by identifying an issue with prior approaches for targeted knowledge editing. While there has been prior work on fine-tuning and naive work on in-context (prompt-based) knowledge editing, the combination of distilling the in-context editing directly into the parameters has not been done.

2. The empirical results, while not perfect on all metrics and datasets, show promise across the baseline methods presented and on the standard metrics and perplexity.

3. Ablation studies emphasize the importance of both dynamically updating the target distribution during training and on the importance of the context. In particular, an in-depth analysis of the static target distribution shows that dynamic targets actually lead to better convergence.

4. More analysis shows that as the model is edited (updated) more, the degradation of the model is less prominent than the other baseline methods.
summary: This work presents an auxiliary loss for finetuning an LLM which steers it towards new knowledge and applied in the knowledge editing domain. This is through “in-context editing” (ICE), which minimizes the distances of the output *distribution* of the original model without the new knowledge to that of a model which is conditioned on the new knowledge in the prompt. Besides accuracy and fluency, other facets of generation are evaluated, like whether unrelated knowledge is affected and whether the learned new knowledge generalizes to related knowledge. Compared to prior methods (ROME, MEMIT, FT-L, FT-M), ICE performs relatively well on most metrics.
weaknesses: 1. The method is similar to knowledge/context distillation or gisting, and so a connection should be drawn there. Still, applying this method appears novel for knowledge editing. However the lack of references to KD/gisting makes it hard to place how related (or not) this idea is to that line of work.

[Snell et al., 2022](https://arxiv.org/abs/2209.15189) - Context Distillation

[Mu et al., 2023](https://arxiv.org/abs/2304.08467) - Gisting

2. The paper advocates for conditioning on “context” to generate target token distributions. It isn’t clear based on the data that this “context” is what makes the ICE method good, as opposed to the training objective. 

  The method requires GPT-4 outputs to generate the context, while the other baselines being compared against are not allowed any access to this (external model) context. If the method is instead interpreted as knowledge distillation, it is less clear how whether this is possible without this context from a stronger LLM.

  Concretely, the effect of context should be isolated from the distillation-like training objective. The latter targets the one-hot problem motivated by the introduction of the paper, but the former is discussed heavily by this paper.

  If I understand the ablations table correctly, the rows with x in “Context” gives us a view of what the distillation-like objective could do for model editing. It looks competitive (or even better) than the baselines presented in Table 3, and so I wonder what the context actually adds? 

3. In addition, one way to explore this would be to measure an “upper bound” of how good the model could be if it were perfect with context, i.e. evaluate the model corresponding to $p_\theta(x, | c, q)$ both before and after training. 

4. The baselines included do not seem comprehensive and are a little misleading. In particular, MEND and SERAC are other method mentioned by Zhang et al., 2024 [survey] that achieve strong results only slightly worse than FT-M. The omission of those results make it seem like ICE is tied with FT-M, both much better than other methods. In reality, ROME/MEMIT are relatively weak baselines compared to the other methods.
5. Another limitation of the method that should be acknowledged or perhaps even addressed directly is the number of modified parameters and cost to make the edits. MEMIT/ROME are local, while FT-M, FT-L, and ICE are full-model. But my understanding is that the latter 3 are actually similar in terms of training cost and modified parameters

[Mitchell et al., 2021](https://arxiv.org/abs/2110.11309) - MEND 

[Mitchell et al., 2022](https://proceedings.mlr.press/v162/mitchell22a/mitchell22a.pdf) - SERAC.

---

confidence: 3
contribution: 3
initial_rating: 8
presentation: 3
questions: I am curious to hear the thoughts of the authors about how much the base in-context ability of the models impact the success of the method.
The discussion section could be expanded with such consideration. It would be interesting especially since the paper does not experiment with different base models
soundness: 3
strengths: The paper proposes an interesting methods that is likely to be useful for future applications. 
The paper does a good job at demonstrating the usefulness of the method.
summary: This paper proposed a method for knowledge editing that is based on leveraging the in-context ability of the model. To learn a new fact by finetuning, the methods proposes to train the model with supervision coming from itself when it can answer the query correctly based on contextual information. 

What is interesting is that since the method relies and benefits from the in-context adapting ability of the model to have better update, better models would benefit even more from finetuning with this method [1, 2].

Overall, this is a good contribution with interesting potential for future work. I think the author could include a discussion about how much the base in-context ability of the models impact the success of the method.

[1] Yu et al 2023 Characterizing mechanisms for factual recall in language models.
[2] Monea et al. 2024. A Glitch in the Matrix? Locating and Detecting Language Model Grounding with Fakepedia
weaknesses: The paper only studies one base model, it is not clear how this generalizes to other model. In particular, I suspect that the size of the model and their base in-context capabilities might play an important role in the success of the method.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: What is the value of lambda used? Was a different value used for different datasets? How was this value found?

Why is the WikiBio dataset the only one missing the Portability score?

Perplexity is reported as an evaluation metric but is that the perplexity of the trained model itself or the perplexity of some other reference model on the generated text? 

It is said that one of the baselines "demonstrated nearly the best performance" in a survey. Why was the best model not reported as a baseline?

The information about which layers are updated by the proposed method should be in the main paper, not hidden deep in the appendix. The main paper currently only mentions this information for "other baselines" and the proposed model does not qualify as a baseline.

Given the very imminent US elections, the example used throughout the paper should probably be updated.
soundness: 3
strengths: The idea is interesting and makes sense, as the probability distribution provides more detailed information compared to just a one-hot target.
Evaluation is performed on several different datasets and with a number of different metrics.
summary: The paper proposes a method of updating an LLM to incorporate some specific piece of new information.
The LLM prompt is prefixed with this new information and the output distribution is used as the target for training the same LLM without that additional context.
This loss is used as a regulariser, along with the main fine-tuning loss.
Results show good performance compared to the chosen baselines.
weaknesses: A crucial baseline is currently missing. There needs to be an evaluation of the exact same proposed model but with lambda set to 0. Using only the fine-tuning (FT) training loss.
This is important to understand what effect the proposed regularising objective has on the model. As far as I can see, this has not been reported in the paper at the moment.
FT-M and FT-L are reported but these differ from the vanilla FT objective and update only 1 specific layer in the model. 
It is mentioned in the appendix that the proposed ICE model is trained by updating the same layers as MEMIT, which would be 5 layers.
There needs to be a baseline that updates the same layers as the proposed model using the same FT objective, with the only difference being that the proposed ICE loss component is turned off (lambda = 0).

The clarity of the paper could be improved.
For example, Section 3.2 seems to propose a method but the actual mechanics or motivation are unclear to me. And then it is said that actually this method is equivalent to the vanilla method described in the previous section anyway.

The novelty of the method is somewhat overstated in the paper. The technical solution is essentially the same as previous work such as Snell et al (2022), the main thing changed is the content of the prompt. That paper is indeed referenced but only among a list of different directions. The particular novel aspect of the paper should be made clear and previous work should be attributed accordingly. As far as I can see, the novel aspect is the application of this method to updating facts in the LLM.

---------------------------
Updated after discussion:

It seems the missing baseline is actually included, it was just not clear from the presentation. I have increased my score accordingly. Although it is still a bit unclear which of the two baselines is then the lambda=0 equivalent.

Regarding novelty compared to Snell et al (2022): Even though you frame this conceptually as a regulariser here, the practical method is still essentially the same. The author response did not present any specific differences. This previous work should be highlighted accordingly in the paper.

Meta-review: This paper introduces an optimization framework for knowledge editing in LLMs. Rather than optimize towards one-hot target distributions, the procedure instead optimizes the model towards a soft distribution induced by conditioning the source model on additional context.  This is combined with the standard optimization towards the one-hot target.

Compared to ROME/MEMIT and more basic fine-tuning, this approach has higher locality and lower perplexity (reflecting better preserved language quality) The approach is also effective in a continual editing setting.

This paper's method is an interesting approach for knowledge editing. It is well-written and the experimental evaluation is thorough.

There are a few weaknesses of the paper. One weakness raised by Ectm is the weakness of the baselines. The knowledge editing methods here are dated.  Furthermore, the improvements over the baselines are most substantial on perplexity, which is a metric introduced by this paper to measure fluency of the model.  A second weakness is that the methodological contribution of the paper may not be that general. The method is similar to other approaches, namely the work of Snell et al. (2022), so these ideas of distillation are already being used for related problems; this paper's contribution is chiefly to show that they work here as well.  A final weakness mentioned by the reviewers is the computational cost of the method, but this is not that substantial: the method is slower but not terribly so.

The reviewers end up positive about the paper, but there are a few reservations due to the weaknesses above. Notably, two reviewers (Ectm and c9Gw) remain a bit unimpressed by the novelty and experimental comparisons with the baselines.

Another paper that was raised in private discussion is this one https://arxiv.org/abs/2306.09306 which the authors could consider discussing.

Decision: Accept (Poster)