R e FACT : Updating Text-to-Image Models by Editing the Text Encoder (2024)

Abstract: Our world is marked by unprecedented technological, global, and socio-political transformations, posing a significant challenge to textto-image generative models. These models encode factual associations within their parameters that can quickly become outdated, diminishing their utility for end-users. To that end, we introduce ReFACT, a novel approach for editing factual associations in text-to-image models without relaying on explicit input from end-users or costly re-training. ReFACT updates the weights of a specific layer in the text encoder, modifying only a tiny portion of the model’s parameters and leaving the rest of the model unaffected.We empirically evaluate ReFACT on an existing benchmark, alongside a newly curated dataset.Compared to other methods, ReFACT achieves superior performance in both generalization to related concepts and preservation of unrelated concepts.Furthermore, ReFACT maintains image generation quality, making it a practical tool for updating and correcting factual information in text-to-image models.

## introduction text-to-image generative models @xcite @xcite are trained on extensive amounts of data, leading them to implicitly encode factual associations within their parameters. while some facts are useful, others may be incorrect or become outdated (e.g., the current president of the united states; see figure 1 ). once these models have been trained, they quickly become outdated and misrepresent the state of the world in their generations. however, model providers and creators currently have no efficient means to update them without either retraining them-which figure 1 : refact edits knowledge in text-to-image models using an editing prompt and a target prompt (e.g., "the president of the united states" is edited to "joe biden"). the edit generalizes to prompts unseen during editing. is costly in computation and time-or requiring explicit prompt engineering from the end user. in this work we present refact, a new method for revising factual knowledge in text-to-image models. refact views facts as key-value pairs encoded in the linear layers of the transformer and updates the weights of a specific layer in the textencoder by editing a key-value mapping using a closed form solution @xcite . our method utilizes three textual inputs: an edit prompt, a source, and a target, representing the desired edit. for example, "the president of the united states" as the edit prompt, "donald trump" as the source, and "joe biden" as the target. then, an edit can be token. then, we optimize a vector v * that, when inserted in a specific layer, will reduce the distance between the edit and the target prompts representation, and increase the distance with respect to the contrastive examples. the vector v * is then planted in the mlp layer using a closed form solution. viewed as changing the value the model retrieves for the corresponding key ("the president of the united states") from source to target ("donald trump" → "joe biden"). by doing so, refact edits the factual associations of the model without fine-tuning. refact modifies only a tiny portion of the model's parameters (0.24%), far fewer than the previous editing method, time (1.95%). once refact is applied to the model, we achieve a persistent change in factual information, resulting in a model that consistently generates images of joe biden for the desired prompt. moreover, refact is able to generalize to closely related prompts and demonstrate the desire update, while not affecting unrelated concepts. notably, refact preserves the general quality of generated images. we evaluate refact on the time dataset @xcite , a benchmark for evaluating the editing of implicit model assumptions on specific attributes (e.g., editing roses to be blue instead of red). moreover, we curate a new dataset, the roles and appearances dataset (road), for editing other types of factual associations. we show that refact successfully edits a wide range of factual association types, demonstrates high generalization, and does not hurt the representations of unrelated facts. our method achieves superior results compared to a recent editing method, time @xcite . overall, our method is a significant improvement in text-to-image model editing. ## editing for interpretability so far, we edited a particular layer for all facts, which was selected using the validation set. however, we hypothesize that different layers encode distinct features, as was also found in a concurrent work @xcite . to investigate differences among different layers in the text encoder, we employ refact as a causal analysis tool, editing individual layers and observing the corresponding outcomes. we focus here on facial expressions. we use six "universal" emotions @xcite ) (happiness, sadness, anger, fear, disgust, and surprise) and use refact with a target text of people expressing the emotions. we edit each layer and generate 50 images for each emotion (25 females and 25 males). appendix j gives more details. results. editing lower layers tends to affect the emotions in the generated images more than editing deeper layers, as demonstrated in figure 9 and quantified in figure 10 . these results indicate that emotions are more encoded in the lower layers of the text encoder. this is different from most other editing cases, where we found that generally higher layers are more suitable for editing (layer 9 in time dataset and 7 in road). ## related work editing knowledge embedded within deep neural networks has been the focus of several lines of work, achieving success in editing generative adversarial networks @xcite @xcite , image classifiers (santurkar et al., 2021), and large language models (llms) @xcite @xcite . several methods were proposed to update weights in llms in particular, including fine-tuning on edited facts @xcite , weight predictions using hyper-networks @xcite , identifying and editing specific neurons @xcite , and rank one model editing @xcite . the task of factual editing in text-to-image models was introduced by @xcite , who targeted the cross-attention layers. in contrast, we target a specific layer in the text encoder of the text-to-image model, allowing a more precise edit that changes fewer model parameters (0.24% compared to 1.95% of model parameters) and outperforms orgad et al. on all metrics. the task of editing knowledge in (the parameters of) text-to-image models is separate from two other lines of work. first, a large body of work has been devoted to image editing @xcite @xcite @xcite @xcite . image editing aims to modify specific attributes of an input image based on some auxiliary inputs, recently using texts and instructions @xcite @xcite . for example, given an image of a cat riding a bicycle, one might want to change the bicycle to a car without changing other attributes and objects in the image. model editing, however, does not apply to specific input images, but rather aims to make a persistent change in the model by changing the model's weights. model editing aims to update the association of a given entity within the model (e.g., "the president of the united states"), from a source (e.g., "donald trump") to a target (e.g., "joe biden"), such that all subsequent generations related to the entity will reflect the updated information. another distinct line of work is personalization of text-to-image diffusion models, where the goal is to adapt the model to a specific individual or object @xcite , given a specific word or pseudo-word @xcite @xcite . personalization methods provide the user with a new token or embedding that represents a novel entity, while preserving the original class of objects (for example, using "[v]" to represent a specific dog in "a @xcite dog", while pre-serving the original generic meaning of "a dog"). in contrast, our work focuses on a fundamentally different task: completely transforming the factual associations without preserving the original value. for example, after editing, the model should consistently generate images of joe biden for all prompts and phrases related to "the president of the united states", without the need to include a special token in the user's prompt, and without preserving the original outdated association to donald trump. thus, our method provides a practical way for model providers to keep their models up to date. ## editing versus personalization although personalization and editing differ in use (section 6), we adapted dreambooth @xcite , a popular personalization method, to perform a variation of the task that is related to editing for comparison purposes. namely, we introduce the edited entity using a personalized token that is added to the editing prompt (e.g., introducing "[v]" in "the [v] president of the united state"). notably, our approach does not fully align with editing goals, as original prompts still produce images with the initial fact. dreambooth underperforms compared to refact on the road validation set, achieving f1 scores of 75.7% and 91.0%, respectively, with its original hyper-parameters. even with hyperparameter optimization, dreambooth only reaches 81.4%, generating lower-quality and less diverse images than refact. further examples and details are available in appendix i.1. novel entities. our main experiments with roles entail swapping a given role with a known person, such as updating the model's association of "the president of the united states" to biden instead of trump. what happens if a previously unknown figure 11 : combining refact and personalization to achieve editing with novel entities. first, we use dreambooth, a personalization method, to introduce the new concept using a new token "[v]". then, we apply refact and preform an edit using the special token as the textual target. ## discussion and conclusion in this work, we presented refact, an editing method that modifies knowledge encoded in textto-image models without requiring fine-tuning. refact is effective at editing various types of factual associations, such as implicit model assumptions or the appearance of an entire subject, while maintaining specificity and leaving other pieces of knowledge unaffected. compared to the previous method, refact only updates a small portion of the models' parameters (0.24%), leaving the majority of the model unchanged, while achieving improvement on all editing metrics. we demonstrated that refact can perform multiple edits on the same model with minimal performance impact compared to single edits. refact targets the text encoder of text-toimage models, and updates the weights of the second matrix within the mlp of a specific layer. this view follows a large body of work which characterizes mlp layers as layers that store knowledge @xcite , while self attention layers are responsible for passing and copying information @xcite . within the mlp, there are a few hypotheses on the way in which factual information is stored. we follow the hypothesis that identifies the second matrix within the mlp as a linear associative memory, where facts are stored as key-value pairs @xcite . alternative approaches propose different hypotheses which are interesting to explore. for example, geva et al. views both mlp matrices as two-layer key-value memories. we leave the exploration of editing under different assumptions as future work. initial experiments demonstrate that editing serves as an effective interpretability tool, providing insights into the encoded information within different layers of the model. while our focus was on editing the final mlp module in a specific layer, further exploration of other model components holds promising potential for investigating diverse knowledge encoding mechanisms and their editing outcomes. we encourage future investigations in these areas to enhance our understanding of the mechanistic structure of knowledge in models. finally, refact was specifically designed to edit existing associations based on user-specified prompts, not to introduce entirely new visual concepts beyond the model's training data. however, our preliminary explorations suggest exciting possibilities for combining refact with other personalization methods to achieve end-to-end encoding of novel concepts without the need for full retraining. we believe this promising avenue deserves further investigation in future work.