Abstract
Recent advancements in diffusion models have showcased their impressive capacity to generate visually striking images. Nevertheless, ensuring a close match between the generated image and the given prompt remains a persistent challenge. In this work, we identify that a crucial factor leading to the text-image mismatch issue is the inadequate cross-modality relation learning between the prompt and the output image. To better align the prompt and image content, we advance the cross-attention with an adaptive mask, which is conditioned on the attention maps and the prompt embeddings, to dynamically adjust the contribution of each text token to the image features. This mechanism explicitly diminishes the ambiguity in semantic information embedding from the text encoder, leading to a boost of text-to-image consistency in the synthesized images. Our method, termed MaskDiffusion, is training-free and hot-pluggable for popular pre-trained diffusion models. When applied to the latent diffusion models, our MaskDiffusion can significantly improve the text-to-image consistency with negligible computation overhead compared to the original diffusion models.
Introduction: The Challenge of Prompt Faithfulness
While state-of-the-art models like Stable Diffusion can generate high-quality imagery, they frequently struggle with "prompt faithfulness"—the ability to accurately reflect all entities and attributes specified in a text prompt. Common failure modes include missing objects (e.g., generating only a horse when a dog and horse are requested) or attribute leakage (e.g., swapping colors between two distinct objects).
The authors identify three primary causes for these discrepancies within the cross-attention mechanism:
- Overlapping Attentive Regions: Unrelated objects compete for the same spatial coordinates in the attention map, often resulting in one suppressing the other.
- Preempted Attentive Regions: High-magnitude tokens (like "elephant") dominate the attention scores, causing smaller or weaker tokens (like "glasses") to vanish.
- Wrong Attentive Regions: Attributes such as color are incorrectly mapped to spatial coordinates, leading to "color bleeding" or mismatched traits.
Methodology: The Conditional Mask
MaskDiffusion addresses these issues by introducing an Adaptive Conditional Mask into the cross-attention layers. Unlike existing solutions that require retraining or slow optimization loops, MaskDiffusion is a training-free, "hot-pluggable" modification. The core innovation modifies the standard attention formula by adding a mask ($M$) to the attention scores before the Softmax operation:
$$Attention = Softmax\left(\frac{QK^T}{\sqrt{D}} + M\right)V$$
Implementation Workflow
- Entity Extraction: The system utilizes the SpaCy library to parse the prompt and identify nouns (entities) and adjectives (attributes).
- Mask Generation: It identifies regions in the attention map with high response values for these tokens and applies a mask to boost specific regions, ensuring "weak" tokens are not drowned out by dominant ones.
- Momentum Updating: To maintain stability across iterative denoising steps, a momentum term is introduced to smooth attention maps over time, preventing object "flickering."
- Targeted Resolution: The authors found that applying the mask specifically to $16 \times 16$ resolution feature maps yielded optimal results, as this resolution aligns best with the internal representations of the CLIP text encoder.
Experimental Results
MaskDiffusion was evaluated using Stable Diffusion v1.4 on MS-COCO and GPT-synthesized complex prompts. The method demonstrates significant improvements in both qualitative and quantitative metrics.
Key Performance Metrics
- Inference Efficiency: MaskDiffusion maintains an inference time of 81 seconds, identical to vanilla Stable Diffusion. In contrast, optimization-based baselines like Attend-and-Excite require 215 seconds.
- Human Preference: In user studies focusing on complex prompts, MaskDiffusion achieved a 74.77% support rate, significantly outperforming vanilla Stable Diffusion (9.16%) and Structured Diffusion (2.87%).
- Quantitative Alignment: The method achieved the highest CLIP Score (26.82) among tested models, confirming its superior semantic alignment.
Discussion and Limitations
The primary insight of this work is that "missing object" issues often stem from mathematical competition within attention layers rather than a lack of training data. By simply "nudging" these maps during inference, spatial reasoning can be corrected without expensive fine-tuning.
However, the method remains dependent on the CLIP text encoder. If the encoder itself fails to distinguish between complex semantic relationships (e.g., "green book in a pink basket" vs. "pink book in a green basket"), the mask may be applied to incorrect regions. Future work will explore more robust text-processing techniques to mitigate this bottleneck.
Summary updated