ConceptEraser<T>
Models & Types · AiDotNet.Diffusion.Safety
Concept erasure for removing unwanted concepts from diffusion model representations.
For Beginners
Imagine the model’s understanding of concepts as directions in a high-dimensional space. Concept erasure finds the “direction” corresponding to an unwanted concept and removes it, like erasing one axis from a coordinate system. The model can still generate everything else, but it loses the ability to produce the erased concept.
How It Works
Concept erasure removes specific concepts (e.g., artistic styles, identities, or unsafe content) from a diffusion model’s internal representations by projecting embeddings onto the null space of the target concept direction. This prevents the model from generating content related to the erased concept.
Reference: Gandikota et al., “Erasing Concepts from Diffusion Models”, ICCV 2023
Constructors
| Constructor | Summary |
|---|---|
ConceptEraser(double erasureStrength, bool preserveGeneralCapability) |
Initializes a new concept eraser. |
Properties
| Property | Summary |
|---|---|
bool PreserveGeneralCapability { get; } |
Gets whether general capability preservation is enabled. |
double ErasureStrength { get; } |
Gets the erasure strength. |
int ConceptCount { get; } |
Gets the number of registered concept directions. |
Methods
| Method | Summary |
|---|---|
Vector<T> EraseFromEmbedding(Vector<T> embedding) |
Erases registered concepts from an embedding by projecting onto the null space. |
double ComputeConceptPresence(Vector<T> embedding, int conceptIndex) |
Computes the concept presence score for an embedding (0 = absent, 1 = fully present). |
void AddConceptDirection(Vector<T> conceptEmbedding) |
Registers a concept direction to be erased. |