Abstract
As text-to-image (T2I) diffusion models become increasingly sophisticated, the risk of generating harmful, biased, or infringing content grows. Traditional mitigation strategies, such as dataset filtering or parameter fine-tuning, often suffer from high computational costs, "catastrophic forgetting" of benign concepts, or poor adaptability. We present Semantic Surgery, a training-free, zero-shot framework that erases unwanted concepts by performing precise vector arithmetic on text embeddings. By operating at the semantic source before the diffusion process begins, Semantic Surgery achieves robust erasure with minimal impact on general model performance.
Introduction
The rapid advancement of models like Stable Diffusion has democratized high-quality image generation but also introduced significant safety and ethical challenges. Existing solutions generally fall into two categories: Dataset Filtering, which is expensive and easily bypassed by creative prompting, and Parameter-Modifying Methods, which fine-tune the model to "unlearn" specific concepts.
However, parameter modification often acts like a "sledgehammer," damaging the model’s general capabilities or accidentally erasing related, benign concepts—a phenomenon known as poor locality. Furthermore, these methods are static and require costly retraining for every new concept to be removed. Semantic Surgery offers a "scalpel"—a way to surgically remove specific concepts at inference time without modifying the model's weights.
Methodology: The Surgical Framework
Semantic Surgery operates on the principle that the CLIP text embedding space possesses a linear structure where concepts can be represented as vectors. The framework consists of three primary stages:
1. Semantic Biopsy
Before image generation, the system analyzes the input prompt's embedding ($e_{input}$). It calculates a "presence score" for target concepts using cosine similarity against predefined concept vectors. If a concept is detected above a specific threshold ($\tau$), the surgery is activated. This "binary gate" effect makes the system resilient to adversarial attacks, as attempts to "sneak" a concept past the filter typically trigger a high presence score.
2. Co-Occurrence Encoding
To handle multiple concepts simultaneously (e.g., erasing both "dogs" and "cats"), the method employs a unified removal direction. Simply subtracting vectors sequentially can lead to over-erasure of shared semantic traits. Instead, Semantic Surgery creates a composite prompt to resolve semantic overlaps, ensuring that only the intended concepts are neutralized.
3. Visual Feedback Loop (LCP Mitigation)
A unique challenge in concept erasure is Latent Concept Persistence (LCP), where a model generates a forbidden concept due to internal priors even if it isn't explicitly in the prompt (e.g., a prompt for "a road" triggering "trees"). Semantic Surgery includes an optional second pass: if a vision detector identifies a forbidden concept in the initial output, it sends a feedback signal to reinforce the erasure in a second, cleaner generation.
Experimental Evaluation
The authors evaluated Semantic Surgery across several benchmarks, including object erasure (CIFAR-10), explicit content removal (I2P dataset), artistic style erasure, and multi-celebrity erasure. General image quality was monitored using MS-COCO 30k to ensure no degradation in non-sensitive tasks.
Key Results
The framework demonstrated exceptional performance in both safety and quality preservation:
- Superior Safety: On the I2P safety benchmark, Semantic Surgery reduced nudity instances from 751 in the original model to just 1 instance. This significantly outperformed other inference-time methods like SAFREE (82 instances).
- Quality Preservation: In style erasure tasks, it maintained high harmonic balance while preserving the original model's FID and CLIP scores on general tasks.
- Adversarial Robustness: The method achieved a 0.0% Attack Success Rate against white-box adversarial attempts, outperforming parameter-modifying baselines like MACE.
Discussion and Limitations
Semantic Surgery represents a shift toward training-free safety mechanisms. By neutralizing concepts at their semantic origin, it prevents the diffusion U-Net from ever processing the forbidden idea. Furthermore, it functions as a real-time alarm for adversarial probing at the pre-generation stage.
However, the method relies on the near-linear structure of the CLIP text encoder. It may struggle with highly abstract or metaphorical concepts that lack a clear vector representation. Additionally, the visual feedback loop's effectiveness is tied to the accuracy of the underlying vision detector; false positives can lead to unnecessary second-stage erasures.
Conclusion
Semantic Surgery provides a precise, efficient, and robust solution for concept erasure in diffusion models. By treating the text embedding space as a surgical field, it enables the removal of harmful or infringing content without the overhead or side effects of model retraining, paving the way for safer and more controllable generative AI.
Summary updated