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

Dana Arad, Hadas Orgad, Yonatan Belinkov

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 relying 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 (T2I) models, such as Stable Diffusion, are trained on massive datasets that capture a snapshot of the world at a specific point in time. During this process, they implicitly memorize a vast array of facts, ranging from the identities of political leaders to the typical colors of natural objects. However, these factual associations are static, while the real world is dynamic. A model trained in 2021 may correctly associate "The President of the United States" with Donald Trump for its training period, but this knowledge becomes an error once the administration changes.

Traditionally, correcting these outdated associations required either computationally expensive retraining or complex prompt engineering. ReFACT offers a "surgical" alternative: a method to directly patch specific factual associations within the model's weights, modifying only 0.24% of the total parameters.

Methodology: The Text Encoder as Associative Memory

ReFACT (Revising FACTual knowledge) shifts the focus of model editing from the image-generating UNet to the text encoder (specifically the CLIP model). The researchers treat the Multi-Layer Perceptron (MLP) layers within the transformer architecture as a linear associative memory, where facts are stored as key-value pairs.

The editing process involves three primary steps:

  1. Key Identification ($k^*$): The model calculates the average representation of a subject (e.g., "The President") at a specific target layer.
  2. Value Optimization ($v^*$): A new vector is optimized to align the "edit prompt" with a "target prompt" (e.g., making "The President" map to the representation of "Joe Biden"). A contrastive loss is employed to ensure the new representation is distinct from the old source and unrelated concepts.
  3. Rank-One Edit: A closed-form mathematical update is applied to a single MLP layer, mapping the identified key to the new optimized value.

Experimental Setup and Datasets

The efficacy of ReFACT was tested using two distinct benchmarks:

  • TIME: A dataset designed to edit implicit model assumptions, such as changing the default color of a rose.
  • RoAD (Roles and Appearances Dataset): A new dataset featuring 100 entries categorized into Roles (e.g., politicians, pop-culture icons) and Appearances (e.g., changing the visual traits of objects).
Figure 3: A successful 'Role' update where the model correctly identifies Prince William as the 'Prince of Wales' following a ReFACT edit.

RoAD includes positive prompts to test the model's ability to generalize the new fact and negative prompts to ensure that unrelated concepts remain stable and unaffected by the edit.

Figure 4: An example of an 'Appearance' edit from the RoAD dataset, where the model is updated to generate a laptop when prompted for a computer.

Results and Key Insights

ReFACT demonstrates significant improvements over previous state-of-the-art methods like TIME. On the TIME dataset, ReFACT achieved an efficacy of 98.19% and a generalization rate of 88.02%, substantially outperforming the baseline.

Key findings include:

  • Layer Specialization: Lower layers in the text encoder primarily handle low-level visual features (emotions, expressions), while higher layers (layers 7-9) manage abstract concepts and social roles.
  • Preservation of Quality: Standard metrics such as FID and CLIP scores indicate that ReFACT edits do not degrade the overall image generation quality.
  • Sequential Scalability: The method supports up to 90 sequential edits with minimal performance degradation, proving its utility for continuous model maintenance.

Limitations

While highly effective, ReFACT requires approximately two minutes of optimization on an NVIDIA A40 GPU, which is slower than purely mathematical methods. Additionally, the researchers noted "facial entanglement," where editing specific facial features can sometimes inadvertently alter the subject's entire identity. Finally, the method is currently optimized for swapping existing concepts rather than introducing entirely novel entities that the model has never encountered during training.

Conclusion

ReFACT provides a precise and efficient mechanism for keeping text-to-image models aligned with an ever-changing world. By targeting the text encoder's associative memory, it allows for factual updates that generalize well across prompts while preserving the model's core generative capabilities.

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