Optimizing Prompts for Text-to-Image Generation

Yaru Hao, Zewen Chi, Li Dong, Furu Wei

TL;DR

Researchers at Microsoft have developed PROMPTIST, a framework that automatically transforms simple user queries into high-quality prompts optimized for text-to-image models like Stable Diffusion. By combining supervised fine-tuning with reinforcement learning (RL) based on aesthetic and relevance rewards, the system significantly outperforms manual prompt engineering and generalizes well to unseen domains.

What Problem Does This Paper Address?

Generative models like Stable Diffusion are notoriously finicky. While they can produce breathtaking art, they often require "prompt engineering"—the practice of adding specific, often non-intuitive modifiers like "trending on artstation," "8k," or specific artist names—to achieve high-quality results.

This creates two major hurdles:

  1. Laborious Effort: Users must spend significant time trial-and-erroring their way to a good image.
  2. Model Specificity: A prompt that works for Stable Diffusion v1.4 might fail on v2.0 or a different architecture like DALL-E 2.

The authors tackle the "misalignment" between what a human naturally types (e.g., "a rabbit in a space suit") and what the model actually prefers to see to produce a high-quality image.

Methods

The authors propose a two-stage framework called PROMPTIST, which uses a language model (specifically GPT-2 117M) as a "prompt adapter."

Figure 1: Overview of PROMPTIST training: (1) supervised fine-tuning (SFT) on manually engineered prompts; (2) reinforcement learning (RL) to increase the rewards of generated images after prompt optimization.
  1. Stage 1: Supervised Fine-Tuning (SFT): The model is first trained on a dataset of prompt pairs. The "source" is a simplified version of a prompt, and the "target" is a manually engineered version. This gives the model a baseline understanding of how to add stylistic modifiers.
  2. Stage 2: Reinforcement Learning (RL): To go beyond just mimicking humans, the model uses Proximal Policy Optimization (PPO). It explores new prompt variations and receives a reward based on two factors:
  3. Aesthetic Score: A predictor trained on human ratings to judge how "pretty" the resulting image is.
  4. Relevance Score: A CLIP-based similarity check to ensure the optimized prompt doesn't drift away from the user's original intent (e.g., turning a "rabbit" into a "cat" just because cats look better in the model).

To prevent the model from drifting too far from natural language, they also include a KL-divergence penalty against the SFT model.

Datasets

The study utilized several key datasets for different stages:

  • Lexica: 90k high-quality, human-engineered prompts crawled from the web, used to create 360k paired examples for SFT via data augmentation (e.g., stripping modifiers, rephrasing).
  • DiffusionDB: A large-scale gallery of real user prompts used for in-domain RL exploration.
  • MS-COCO & ImageNet-21k: Used as "out-of-domain" data to test how well the model adapts prompts for concepts it didn't see during the initial supervised training.

Key Insights and Ideas

  • RL as a Generalizer: While SFT helps the model learn the "language" of prompt engineering, RL is what allows it to generalize. The authors found that RL significantly boosted performance on out-of-domain prompts (like COCO captions) where the SFT model struggled.
  • The Relevance-Aesthetic Tradeoff: A key challenge in prompt optimization is preventing "reward hacking," where the model adds so many modifiers that the original subject is lost. The dual-reward system (Aesthetic + Relevance) acts as a crucial check-and-balance.
  • Diverse Beam Search: During RL, the authors used diverse beam search to ensure the model explored a wide variety of prompt styles rather than settling on a single "perfect" string of tags.

Key Results

PROMPTIST consistently outperformed both raw user inputs and manual prompt engineering across multiple metrics.

Figure 2: Reward comparison of optimized prompts with other baselines on in-domain and out-of- domain data. For in-domain Lexica prompts, we evaluate on four augmentations: main content (MC), main content with random modifiers (MCM), rephrasing of main content (RMC) and rephrasing of target prompt (RTP). Results indicate that the text-to-image model benefits a lot from our method.
  • Quantitative Gains: In Table 2, the authors show that RL provides a massive gain over SFT—up to +127% improvement in reward for certain rephrased prompts.
  • Human Preference: In head-to-head human evaluations, users preferred images generated by PROMPTIST-optimized prompts 72% of the time compared to the original user input.
  • Visual Quality: Qualitative results show that simple prompts like "the roof is wet from the rain" are transformed into descriptive, artistically rich prompts that produce much more evocative imagery.
Qualitative examples comparing images from original user inputs vs. PROMPTIST-optimized prompts.

Limitations and Future Work

The authors acknowledge a few key limitations:

  • Dataset Bias: Since the training data came from Lexica, the model has a slight bias toward "artistic" styles rather than realistic photography.
  • Subject Bias: There is a higher proportion of portrait-related prompts in the training set, which can skew results.
  • Scope: The current framework is specific to text-to-image. The authors suggest that future work could extend this to text-to-video or even text-to-code tasks where prompt sensitivity is also a major issue.

By treating prompt engineering as a translation task that can be optimized via RL, PROMPTIST offers a glimpse into a future where "talking" to AI is as natural as talking to a human, without losing the technical edge of the underlying model.

Summary updated

BibTeX
@inproceedings{hao2023optimizing,
  author = {Yaru Hao and Zewen Chi and Li Dong and Furu Wei},
  title = {{Optimizing Prompts for Text-to-Image Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=BsZNWXD3a1},
}
Figure