TLDR: Wukong is a new AI framework that efficiently detects Not Safe For Work (NSFW) content in text-to-image systems like Stable Diffusion. Unlike traditional methods that filter text prompts or wait for full image generation, Wukong identifies potential NSFW content early in the image creation process by analyzing intermediate visual data, making it faster, more accurate, and robust against adversarial attacks.
Text-to-Image (T2I) generation has become a popular technology, allowing users to create diverse and creative images from simple text descriptions. However, this powerful capability also comes with a challenge: the potential to generate Not Safe For Work (NSFW) content, such as violence or explicit imagery, which violates community guidelines. Ensuring that these AI systems adhere to ethical standards is crucial.
The Limitations of Current Safeguards
Currently, there are two main approaches to safeguarding T2I systems. The first involves text filters, which analyze the user’s prompt for forbidden words or phrases. While simple and efficient, these filters often fall short because they don’t account for how T2I models actually generate images. A seemingly safe prompt might still produce unsafe content due to the model’s specific behavior or even random variations (like different ‘seeds’ in the generation process). Moreover, these text filters can be easily bypassed by clever rephrasing or ‘adversarial attacks’ that make unsafe prompts appear harmless.
The second approach uses image filters, which analyze the final generated image to detect NSFW content. These are generally more accurate as they directly inspect the visual output. However, they are computationally expensive and introduce significant delays, as they require the entire image generation process to complete before any safety check can be performed. This makes them impractical for real-time applications.
Introducing Wukong: An Early Detection System
Researchers from Nanyang Technological University in Singapore have proposed a novel solution called Wukong, a transformer-based framework designed for NSFW detection in T2I systems. Inspired by the mythological figure Wukong, who can swiftly identify disguised demons, this framework aims to detect unsafe content at a very early stage of the image generation process, even when the image is still just ‘white noise’ to the human eye.
The core insight behind Wukong is that the early steps in a diffusion model (the technology behind modern T2I systems like Stable Diffusion) are critical in defining the semantic layout and structure of the final image. Additionally, specific parts of the model, called ‘cross-attention layers’, are crucial for aligning text descriptions with visual regions in the image.
How Wukong Works
Wukong operates by leveraging these observations. Instead of waiting for a full image to be generated, it taps into the intermediate outputs of the T2I model during its early ‘denoising’ steps. It uses a U-Net-based encoder (reusing parts of the T2I model itself) to extract these early-stage ‘latent representations’ of the image.
Then, a transformer-based decoder takes these representations and combines them with ‘NSFW query embeddings’ – essentially, digital representations of unsafe concepts like ‘violence’ or ‘sexual’. By reusing the pre-trained cross-attention parameters from the T2I model’s U-Net, Wukong can effectively identify if these unsafe concepts are beginning to form in the nascent image. If NSFW content is detected at this early stage, the image generation process is immediately halted, saving significant computational resources and time. If the content is deemed safe, the generation continues with minimal overhead.
Also Read:
- Deepfake Detection Breakthrough: Unlocking Multi-Modal AI’s Middle Layers for Universal Forensics
- MMBERT: Advanced Multimodal AI for Robust Chinese Hate Speech Detection
Key Contributions and Performance
To support their research, the team also introduced a new dataset called Wukong-Demons. Unlike previous datasets that relied solely on text prompts for labeling, Wukong-Demons provides NSFW labels based on the *generated image itself* and accounts for variations introduced by different random seeds. This makes it a more realistic and robust benchmark for evaluating T2I safety.
Experiments show that Wukong significantly outperforms existing text-based safeguards, demonstrating its effectiveness in accurately detecting NSFW content. Crucially, it achieves comparable accuracy to image-based filters while being much more efficient, offering a speedup of over 5 times. Furthermore, Wukong proved to be highly robust against ‘adversarial prompts’ – cleverly crafted text inputs designed to bypass traditional text filters – by directly analyzing the visual formation process rather than just the text.
In conclusion, Wukong represents a significant step forward in safeguarding AI-generated content. By integrating an efficient and accurate detection mechanism directly into the early stages of the image generation process, it offers a practical solution for ensuring ethical and responsible use of T2I technologies. You can find more details in the full research paper: Wukong Framework for Not Safe For Work Detection in Text-to-Image systems.


