Table of Contents
Fetching ...

Semantic Surgery: Zero-Shot Concept Erasure in Diffusion Models

Lexiang Xiong, Chengyu Liu, Jingwen Ye, Yan Liu, Yuecong Xu

TL;DR

Semantic Surgery presents a zero-shot, training-free framework that intervenes directly on the text embedding prior to diffusion generation to erase targeted concepts. It leverages semantic vector arithmetic in CLIP space, enhanced by Co-Occurrence Encoding for multi-concept erasure and a visual-feedback loop to counter Latent Concept Persistence, yielding strong completeness and locality. The approach outperforms strong baselines across object, explicit-content, artistic-style, and multi-concept celebrity erasure tasks, while preserving image quality and enabling a built-in threat-detection capability. By operating at inference time and maintaining model-agnostic applicability, Semantic Surgery offers a practical, adaptable safety layer for safer text-to-image generation with potential for broader applicability and future extensions. Theoretical guarantees and extensive empirical evaluations substantiate its effectiveness and robustness against paraphrasing and adversarial prompts.

Abstract

Concept erasure in text-to-image diffusion models is crucial for mitigating harmful content, yet existing methods often compromise generative quality. We introduce Semantic Surgery, a novel training-free, zero-shot framework for concept erasure that operates directly on text embeddings before the diffusion process. It dynamically estimates the presence of target concepts in a prompt and performs a calibrated vector subtraction to neutralize their influence at the source, enhancing both erasure completeness and locality. The framework includes a Co-Occurrence Encoding module for robust multi-concept erasure and a visual feedback loop to address latent concept persistence. As a training-free method, Semantic Surgery adapts dynamically to each prompt, ensuring precise interventions. Extensive experiments on object, explicit content, artistic style, and multi-celebrity erasure tasks show our method significantly outperforms state-of-the-art approaches. We achieve superior completeness and robustness while preserving locality and image quality (e.g., 93.58 H-score in object erasure, reducing explicit content to just 1 instance, and 8.09 H_a in style erasure with no quality degradation). This robustness also allows our framework to function as a built-in threat detection system, offering a practical solution for safer text-to-image generation.

Semantic Surgery: Zero-Shot Concept Erasure in Diffusion Models

TL;DR

Semantic Surgery presents a zero-shot, training-free framework that intervenes directly on the text embedding prior to diffusion generation to erase targeted concepts. It leverages semantic vector arithmetic in CLIP space, enhanced by Co-Occurrence Encoding for multi-concept erasure and a visual-feedback loop to counter Latent Concept Persistence, yielding strong completeness and locality. The approach outperforms strong baselines across object, explicit-content, artistic-style, and multi-concept celebrity erasure tasks, while preserving image quality and enabling a built-in threat-detection capability. By operating at inference time and maintaining model-agnostic applicability, Semantic Surgery offers a practical, adaptable safety layer for safer text-to-image generation with potential for broader applicability and future extensions. Theoretical guarantees and extensive empirical evaluations substantiate its effectiveness and robustness against paraphrasing and adversarial prompts.

Abstract

Concept erasure in text-to-image diffusion models is crucial for mitigating harmful content, yet existing methods often compromise generative quality. We introduce Semantic Surgery, a novel training-free, zero-shot framework for concept erasure that operates directly on text embeddings before the diffusion process. It dynamically estimates the presence of target concepts in a prompt and performs a calibrated vector subtraction to neutralize their influence at the source, enhancing both erasure completeness and locality. The framework includes a Co-Occurrence Encoding module for robust multi-concept erasure and a visual feedback loop to address latent concept persistence. As a training-free method, Semantic Surgery adapts dynamically to each prompt, ensuring precise interventions. Extensive experiments on object, explicit content, artistic style, and multi-celebrity erasure tasks show our method significantly outperforms state-of-the-art approaches. We achieve superior completeness and robustness while preserving locality and image quality (e.g., 93.58 H-score in object erasure, reducing explicit content to just 1 instance, and 8.09 H_a in style erasure with no quality degradation). This robustness also allows our framework to function as a built-in threat detection system, offering a practical solution for safer text-to-image generation.
Paper Structure (76 sections, 7 theorems, 44 equations, 12 figures, 9 tables)

This paper contains 76 sections, 7 theorems, 44 equations, 12 figures, 9 tables.

Key Result

Theorem 1

For input embedding $e_{\text{input}}$ and concept direction $\Delta e_{\text{erase}}$, the presence intensity $\rho$ satisfies: where $e_{\text{input}}'$ represents the ideal sanitized embedding, which is generally unobservable during inference and serves as a theoretical construct for this geometric interpretation.

Figures (12)

  • Figure 1: Overview of the Semantic Surgery Workflow. The process begins with (A) Semantic Analysis: ① Semantic Biopsy analyzes the initial embedding $e_{\text{input}}$ to produce concept presence scores $\{\hat{\rho}_i\}$. These scores determine the set of active concepts, $\mathcal{C}_{\text{active}}$. ② Co-Occurrence Encoding then takes this set to form a unified removal direction $\Delta e_{\text{co}}$. This leads to (B) Core Surgery: the scaled direction vector is subtracted from $e_{\text{input}}$ to produce a sanitized embedding $e'_s$, which is passed to the Diffusion Generator (composed of a U-Net and VAE decoder) to generate an initial image. For critical safety tasks, an optional ④ Visual Feedback Loop (dashed red path) uses a vision detector to check for Latent Concept Persistence (LCP). If a concept is visually detected, a feedback signal updates the set of active concepts, triggering a refined, stronger surgery that leads to the final, clean image. (Note: The surgery step itself is implicitly step ③). This entire framework is supported by a rigorous theoretical analysis (see Appendix \ref{['app:theoretical_guarantees']} for proofs), where we formally prove guarantees for Completeness (Thm. \ref{['thm:Completeness']}), Locality (Thm. \ref{['thm:Locality']}), and Robustness (Thm. \ref{['thm:Robustness']})
  • Figure 2: Multi-Concept Celebrity Erasure. (a) Completeness ($Accuracy_e$, lower is better). (b) Locality ($Accuracy_s$, higher is better). (c) Overall ($H_c$, higher is better). (d) Image Quality (FID-30K on MS-COCO, lower is better). (e) Semantic Alignment (CLIP-30K on MS-COCO, higher is better). X-axis: # of Erased Celebrities. Baseline data adapted from MACE lu2024mace; Receler data generated by us.
  • Figure 3: Qualitative comparison for multi-concept erasure ("dog", "cat"). Our Co-Occurrence Encoding (center) preserves semantics (e.g., "playing together" with children) while the Naive Approach (right) degrades image quality compared to the Original (left).
  • Figure 4: Impact of $\gamma$ (Sigmoid Steepness, log scale) on Object Erasure (CIFAR-10) Performance Metrics. Metrics show high stability across tested $\gamma$ values.
  • Figure 5: Impact of $\beta$ (Concept Presence Threshold) on Object Erasure (CIFAR-10) Performance Metrics. An optimal $\beta$ range balances erasure effectiveness with semantic preservation.
  • ...and 7 more figures

Theorems & Definitions (14)

  • Theorem 1: Concept Presence Projection
  • Corollary 3.1: Angular Formulation
  • Theorem 2: Sigmoid Calibration with High Confidence
  • proof
  • proof
  • proof
  • Theorem 3: LCP Risk Bound via Directional Surgery
  • proof
  • Theorem 4: Completeness
  • proof
  • ...and 4 more