ReFACT: Updating Text-to-Image Models by Editing the Text Encoder

Dana Arad, Hadas Orgad, Yonatan BelinkovSubmission to ICLR 2024 · Rejected

TL;DR

ReFACT is a surgical approach to updating factual knowledge in text-to-image (T2I) models by editing the weights of the text encoder rather than the image generator. By modifying just 0.24% of the model’s parameters using a closed-form solution, it successfully updates "outdated" facts (like changing the President of the United States) while maintaining high image quality and preventing interference with unrelated concepts.

The Challenge of Outdated Knowledge

Text-to-image models like Stable Diffusion are trained on massive, static snapshots of the internet. Consequently, they "bake in" factual associations that quickly become obsolete—such as who holds a political office or the current appearance of a celebrity.

Until now, updating this knowledge required either expensive retraining or "prompt engineering" by the end-user. Previous state-of-the-art editing methods focused on the cross-attention layers of the diffusion model. However, these methods often struggle to generalize (the edit only works for specific phrasing) or suffer from poor specificity (editing one concept accidentally breaks another). ReFACT shifts the focus to the text encoder, treating it as the primary repository of world knowledge that needs correction.

Examples of factual updates using ReFACT

How ReFACT Works

ReFACT (Revising FACTual knowledge) treats the MLP layers within a transformer-based text encoder (specifically CLIP) as a linear associative memory. In this view, facts are stored as key-value pairs.

The process involves three main steps:

  1. Identifying the Key ($k^*$): The "key" is the average representation of the subject (e.g., "The President of the United States") at a specific layer in the text encoder.
  2. Optimizing the Value ($v^*$): The researchers find a new "value" vector that minimizes a contrastive loss. This ensures the representation of the edit prompt becomes similar to the target (e.g., "Joe Biden") while staying distinct from the source (e.g., "Donald Trump") and other unrelated "negative" examples.
  3. Weight Update: Using a closed-form solution (inspired by the ROME method for Large Language Models), the weights of a single MLP layer are updated to map the old key to the new value.

This approach is incredibly efficient, modifying only 0.24% of the model's total parameters, compared to nearly 2% in previous methods.

Datasets and Evaluation

The authors evaluated ReFACT using two primary benchmarks:

  • TIME: An existing dataset used to edit implicit model assumptions (e.g., making roses blue instead of red).
  • RoAD (Roles and Appearances Dataset): A new, more challenging dataset curated by the authors. It contains 100 entries covering "Roles" (e.g., changing the Prince of Wales from Charles to William) and "Appearances" (e.g., changing the look of a specific car model). RoAD includes positive prompts to test generalization and negative prompts to test specificity.

Key Insights

  • The Text Encoder is the Brain: While the U-Net generates the pixels, the text encoder (CLIP) acts as the "knowledge base." Editing the encoder allows the model to understand the concept of the change, which then naturally flows into the image generation process.
  • Surgical Precision vs. Fine-tuning: Standard fine-tuning often leads to "catastrophic forgetting," where the model loses its ability to generate complex scenes. ReFACT’s rank-one update preserves the model's general generative capabilities.
  • Layer-wise Interpretability: The authors discovered that different types of information are stored in different layers. For instance, "world facts" are best edited in middle-to-late layers (layer 9), while facial expressions and emotions are more effectively edited in the very early layers of the encoder.
  • Generalization is Key: A successful edit shouldn't just work for the prompt "The President." It should also work for "An oil painting of the President" or "The President in a park." ReFACT demonstrates significantly better generalization than cross-attention editing.

Results

  • Superior Performance: On the TIME dataset, ReFACT achieved 98.19% efficacy, significantly outperforming the previous state-of-the-art (TIME) at 83.23%.
  • Better Specificity: On the new RoAD dataset, ReFACT maintained a specificity of 95.44%, meaning it rarely corrupted unrelated concepts, whereas previous methods were more prone to "collateral damage."
  • Scalability: The model can handle sequential edits. The researchers successfully performed up to 90 consecutive factual updates on a single model with only a minimal drop in performance.
  • Quality Preservation: Metrics like FID and CLIP scores remained virtually identical to the unedited base model, proving that ReFACT doesn't degrade the overall aesthetic quality of generated images.

Limitations and Future Work

  • Optimization Speed: Unlike some closed-form methods that are near-instant, ReFACT requires a short optimization loop (about 2 minutes on an A40 GPU) to find the ideal value vector $v^*$ before the weights are updated.
  • Facial Identity: While ReFACT can add "glasses" to a person, it sometimes unintentionally alters other facial features, indicating that facial identity is deeply entangled within the encoder's representations.
  • Novel Entities: ReFACT is designed to swap existing associations. It struggles to introduce a completely "new" person that the model has never seen before. The authors suggest combining ReFACT with personalization techniques like DreamBooth to solve this in the future.

Summary updated

Abstract

Our world is marked by unprecedented technological, global, and socio-political transformations, posing a significant challenge to text-to-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.
BibTeX
@misc{arad2023refact,
  author = {Dana Arad and Hadas Orgad and Yonatan Belinkov},
  title = {{ReFACT: Updating Text-to-Image Models by Editing the Text Encoder}},
  year = {2023},
  eprint = {2306.00738},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.00738},
}
Figure