TextCraftor: Your Text Encoder Can be Image Quality Controller

Yanyu Li, Xian Liu, Anil Kag, Ju Hu, Yerlan Idelbayev, Dhritiman Sagar, Yanzhi Wang, Sergey Tulyakov, Jian Ren

In the rapidly evolving world of text-to-image generation, most research focuses on the "engine"—the UNet or Transformer that does the heavy lifting of denoising pixels. But what about the "steering wheel"? A new paper from researchers at Snap Inc. and Northeastern University suggests that we’ve been overlooking a crucial component: the text encoder. Their proposed framework, TextCraftor, demonstrates that fine-tuning the text encoder can be a more efficient and effective way to boost image quality and alignment than simply building bigger models.

TL;DR

TextCraftor is a novel fine-tuning paradigm that optimizes the text encoder of diffusion models using reward functions (like aesthetic and human preference scores). It significantly improves image quality and text-image alignment without increasing inference costs, and it allows for controllable generation through simple embedding interpolation.

What Problem Does This Paper Address?

Despite the success of models like Stable Diffusion, two persistent challenges remain. First, models often fail to follow prompts accurately (poor text-image alignment). Second, getting a "masterpiece" usually requires extensive prompt engineering or dozens of random seeds.

While some researchers try to solve this by swapping the standard CLIP text encoder for massive Large Language Models (LLMs) like T5, this introduces significant memory and computational overhead. Others fine-tune the UNet, but this can lead to "mode collapse," where the model loses its ability to generate diverse images. TextCraftor asks a different question: Can we make the existing, lightweight text encoder smarter?

Methods

The core idea of TextCraftor is to fine-tune the text encoder using Reward Propagation. Instead of training on static image-caption pairs, the model generates images from prompts and uses automated "reward models" to grade them.

Overview of the TextCraftor fine-tuning paradigm.

The authors introduce two main techniques:

  1. Prompt-Based Fine-tuning: The model runs a full denoising chain (e.g., 25 steps of DDIM) to produce a clean image. It then backpropagates the reward signal through the entire chain back to the text encoder. To make this memory-feasible, they use gradient checkpointing.
  2. CLIP Similarity Constraint: To prevent the model from drifting too far and losing its general knowledge (catastrophic forgetting), they add a constraint that keeps the fine-tuned text embeddings close to the original CLIP image-text space.
  3. Orthogonality: The authors show that this method is "orthogonal" to UNet fine-tuning. You can improve the text encoder first, then fine-tune the UNet on top of it for even better results.

Datasets

  • Training: The researchers used the OpenPrompt dataset, which contains over 10 million high-quality user prompts.
  • Evaluation: Performance was measured using Parti-Prompts (1,632 prompts across various categories) and the HPSv2 benchmark (3,200 prompts).
  • Reward Models: They utilized Aesthetic Score Predictor, PickScore, and HPSv2 to provide the feedback signals during training.

Key Insights and Ideas

  • The "Buried Gem": The text encoder is a highly efficient lever for quality. By fine-tuning it, TextCraftor achieves results that rival or beat much larger models (like SDXL) while keeping the original, lightweight architecture.
  • Controllable Style via Interpolation: Because the optimization happens in the embedding space, you can "dial in" the intensity of the fine-tuning. By interpolating between the original CLIP embedding and the TextCraftor-enhanced embedding, users can precisely control the generative strength and style.
Interpolation between original and TextCraftor embeddings allows for controllable generation.
  • Stability through Constraints: Without the CLIP similarity constraint, reward-based training often leads to weird artifacts or "gaming" the reward model. The constraint acts as an anchor, ensuring the model remains robust and generalizable.

Key Results

TextCraftor shows impressive gains across the board. Qualitatively, it produces sharper, more artistic images that follow complex prompts better than the base Stable Diffusion v1.5.

Figure 1. Example generated images. For each prompt, we show images generated from three different models, which are SDv1.5, TextCraftor, TextCraftor + UNet, listed from left to right. The random seed is fixed for all generation results.

Quantitatively:

  • Human Preference: In head-to-head human evaluations, TextCraftor had a 71.7% win rate over SDv1.5 and even a 59.7% win rate over the much larger SDXL Base 0.9.
  • Benchmark Scores: It consistently outperformed baselines in Aesthetic scores, PickScore, and HPSv2 metrics.
  • Generalization: The fine-tuned encoder can be "plugged into" other models like ControlNet or used for inpainting without any additional training, immediately boosting their performance.

Limitations and Future Work

The authors note that the model is only as good as the reward functions used to train it. For instance, if the HPSv2 reward is weighted too heavily, the model can sometimes generate repeated objects (a known bias in that reward model).

Future work includes exploring token-specific rewards—fine-tuning the encoder to understand specific styles or objects even more deeply—and further reducing the computational cost of backpropagating through long denoising chains.

For engineers and researchers, TextCraftor serves as a reminder: sometimes the best way to improve a complex system isn't to make it bigger, but to refine how its components communicate.

Summary updated

BibTeX
@misc{li2024textcraftor,
  author = {Yanyu Li and Xian Liu and Anil Kag and Ju Hu and Yerlan Idelbayev and Dhritiman Sagar and Yanzhi Wang and Sergey Tulyakov and Jian Ren},
  title = {{TextCraftor: Your Text Encoder Can be Image Quality Controller}},
  year = {2024},
  eprint = {2403.18978},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.18978},
}
Figure