TL;DR
TEA (Text Encoder Alignment) is a lightweight, highly efficient framework that robustly erases unsafe or copyrighted concepts from text-to-image models by fine-tuning only the text encoder. By framing concept erasure as an adversarial domain alignment problem in the text representation space, TEA permanently suppresses targeted concepts in just a few seconds of training, introducing zero inference-time overhead while preserving the model's overall generation quality.
What Problem Does This Paper Address?
While text-to-image diffusion models have achieved incredible synthesis capabilities, they remain highly vulnerable to misuse. Malicious users can easily bypass standard keyword blacklists or post-hoc safety filters using paraphrased, indirect, or adversarial prompts (e.g., "jailbreaking") to generate Not-Safe-For-Work (NSFW) content or infringe on copyrights.
Existing solutions to permanently remove these concepts ("concept erasure") typically suffer from three major flaws:
- Lack of Robustness: They fail against sophisticated white-box or black-box adversarial prompt attacks.
- Utility Degradation: Modifying the massive image-generation backbone (like the U-Net or Diffusion Transformer) often inadvertently degrades the quality of benign, unrelated images.
- Inference Overhead: Methods that intervene during inference time add persistent computational delays to every single user query.
TEA addresses these challenges by shifting the focus entirely to the text encoder, treating concept erasure as a representation-space domain alignment problem.
Methods
The core idea behind TEA is simple: if the text encoder represents an unsafe prompt identically to a safe "anchor" prompt, the frozen generative backbone will be physically incapable of producing an unsafe image.
The framework operates via a lightweight adversarial training setup:
- Prompt Pair Construction: Using an LLM, the authors generate pairs consisting of a concept prompt ($p^c$, e.g., "a nude woman in a forest") and a semantically matched anchor prompt ($p^a$, e.g., "a woman in a forest").
- Token-Level Adversarial Alignment: A lightweight discriminator ($D$) is trained to distinguish the token-level representations of concept prompts from anchor prompts. Simultaneously, the text encoder ($\tau_\theta$) is fine-tuned to fool the discriminator, making the representations indistinguishable.
- Non-Fixed Target Embeddings: Crucially, anchor prompts are passed through the current text encoder at each training step rather than holding original embeddings fixed. This prevents representation collapse and stabilizes the adversarial optimization.
- Preservation Loss: To ensure the text encoder doesn't forget how to process normal text, a token-level cosine distance loss regularizes the encoder, keeping anchor embeddings close to their original pre-trained states.
Throughout this process, the entire generative backbone (U-Net or DiT) remains completely frozen.
Datasets
The authors evaluated TEA using several datasets and adversarial benchmarks:
- Training Data: 50 explicit (NSFW) prompts generated via GPT-5.3 Instant, each paired with 5 semantically matched anchor prompts (250 pairs total). For artistic style erasure, 20 target artist prompts were paired with 5 anchors each.
- Adversarial Benchmarks: Evaluated against red-teaming datasets designed to bypass safety filters: Ring-A-Bell, P4D, and MMA (covering both black-box and white-box attack variants).
- I2P (Inappropriate Image Prompts) Benchmark: A collection of 4,703 real-world user prompts used to test real-world erasure completeness.
- COCO-Caption: 1,000 samples used exclusively to evaluate whether the model preserves high-quality generation on benign, safe prompts.
Key Insights and Ideas
- The "Attention Leak" Phenomenon: The authors discovered that restricting alignment to only the specific concept words (e.g., just the word "nude") is ineffective. Because text encoders use self-attention, concept information quickly redistributes across all non-padding tokens in a sentence. Therefore, TEA enforces all-token alignment, which is vital for preventing adversarial prompts from exploiting unaligned tokens.
- Moving Targets Stabilize Training: In typical adversarial setups, mapping to a fixed target causes the generator to collapse. By letting the anchor embeddings evolve dynamically alongside the encoder updates, the discriminator is prevented from becoming overly confident, resulting in highly stable training.
- Architecture Agnosticism: Because TEA only alters the text conditioning pathway, it is entirely model-agnostic. It seamlessly transfers from older CNN-based U-Net backbones (Stable Diffusion v1.4) to modern Rectified Flow Transformers (Stable Diffusion v3.5 and FLUX.1).
Key Results
State-of-the-Art Robustness
TEA achieved exceptional defense metrics against adversarial attacks. On Stable Diffusion v1.4, it reduced the average black-box attack success rate (ASR) to just 1.14%, outperforming established baselines like ESD and UCE.
In white-box scenarios—where attackers have full access to model weights to optimize their prompts—TEA consistently maintained the lowest ASR across UnlearnDiff, MMA, and Ring-A-Bell attacks.
Zero-Shot Transferability
In an impressive display of flexibility, the authors took the text encoders trained on Stable Diffusion v3.5 and plugged them directly into FLUX.1-dev without any additional training. TEA successfully suppressed explicit content generation on this entirely different backbone, dropping the baseline ASR from 66.86% to 24.78% (with independent verification via LlavaGuard showing true residual safety risks fell well below 1%).
Extreme Efficiency
Because it only updates a fraction of the overall system parameters, TEA is incredibly fast. It requires only ~5 seconds of training on a single GPU, compared to 42 minutes for ESD or 15 hours for AdvUnlearn, all while introducing 1x (zero) inference overhead.
Limitations and Future Work
- Dependence on LLM Prompt Generation: TEA relies on an external language model to generate high-quality, semantically matched anchor prompts. If the anchor prompts fail to capture the exact context or introduce stylistic shifts, it could impact preservation quality.
- Zero-Shot Evaluation Discrepancies: When transferring encoders to FLUX.1-dev, automated detectors like NudeNet flagged several false positives due to exposed skin (shoulders, midriffs) on fully clothed subjects. Developing more nuanced evaluation metrics that move beyond simple body-part detection remains an open area for future work.
Summary updated