Latent Guard: a Safety Framework for Text-to-image Generation
Runtao Liu, Ashkan Khakzar, Jindong Gu, Qifeng Chen, Philip Torr, Fabio Pizzati
TL;DR
Latent Guard addresses the safety challenges of text-to-image generation by shifting from direct input classification to identifying blacklisted concepts within a learned latent space atop the text encoder. It introduces a trainable Embedding Mapping Layer and a contrastive learning regime to align prompt representations with concept embeddings, enabling fast, test-time webhook-like blocking of unsafe prompts without retraining the diffusion model. The authors construct CoPro, a large dataset of unsafe and safe prompts around 723 concepts, and demonstrate strong performance and generalization on in-distribution and out-of-distribution concepts, outperforming several baselines across multiple evaluation metrics. The approach offers practical benefits in deployment due to low computational overhead, adaptability to changing safety requirements, and compatibility with existing T2I pipelines, while acknowledging limitations related to concept list coverage and potential distribution shifts. Overall, Latent Guard provides a robust, scalable framework for proactive content safety in text-to-image systems and lays groundwork for open-set, adaptable safety mechanisms in generative AI.
Abstract
With the ability to generate high-quality images, text-to-image (T2I) models can be exploited for creating inappropriate content. To prevent misuse, existing safety measures are either based on text blacklists, which can be easily circumvented, or harmful content classification, requiring large datasets for training and offering low flexibility. Hence, we propose Latent Guard, a framework designed to improve safety measures in text-to-image generation. Inspired by blacklist-based approaches, Latent Guard learns a latent space on top of the T2I model's text encoder, where it is possible to check the presence of harmful concepts in the input text embeddings. Our proposed framework is composed of a data generation pipeline specific to the task using large language models, ad-hoc architectural components, and a contrastive learning strategy to benefit from the generated data. The effectiveness of our method is verified on three datasets and against four baselines. Code and data will be shared at https://latentguard.github.io/.
