TL;DR
Large Vision-Language Models (LVLMs) are surprisingly bad at detecting toxic images, even with strong text safety. This paper introduces SafeCLIP, a lightweight method that repurposes the CLS token from CLIP's vision encoder to identify toxic visual content with minimal overhead, achieving high detection rates and low false positives.
What Problem Does This Paper Address?
Modern LVLMs, like those combining vision and language understanding, are trained on massive datasets and excel at many tasks. However, despite having robust safety mechanisms for text, they often fail to detect harmful visual content. Existing solutions, such as pre-filtering images or fine-tuning models specifically for safety, are computationally expensive and can degrade the model's overall performance. This leaves LVLMs vulnerable to generating inappropriate or harmful responses when presented with toxic images, a significant concern for their deployment in real-world applications.
Methods
The core innovation of SafeCLIP is its use of the CLS token, a global semantic representation generated by the vision encoder (specifically CLIP's ViT) during visual feature extraction. Traditionally, this token is discarded after feature extraction. SafeCLIP projects this CLS token into CLIP's text embedding space and compares it against a pre-defined "safety concept bank" of textual descriptors for various toxic categories (e.g., porn, violence, weapons). This comparison, using cosine similarity and probability calibration, allows SafeCLIP to identify toxic scenes in a zero-shot manner without altering the LVLM's architecture.
SafeCLIP can be integrated in two ways:
- Inference-time: It acts as a safety verification step before response generation. If toxic content is detected, a safe instruction is prepended to the original prompt.
- Fine-tuning: It enables dynamic safety correction by sanitizing instructions and aligning safe target responses during the fine-tuning process, making it more efficient than traditional dataset detoxification.
Datasets
The paper uses existing datasets for evaluation:
- Toxic Image Datasets:
- HOD (Ha et al., 2023): Contains 10,631 toxic images across categories like alcohol, cigarette, gun, insulting gesture, bloody, and knife.
- ToViLaG (Wang et al., 2023): Includes 5,600 toxic images, particularly focusing on pornographic content.
- Neutral Images: An additional 4,000 neutral images were collected using GPT-4V to form a neutral dataset for evaluating false positive rates.
- Harmful Text Prompts: 520 harmful prompts from the AdvBench Dataset (Zou et al., 2023) were used for text-based safety evaluation.
Key Insights and Ideas
- The CLS token is a powerful, underutilized safety signal: The paper demonstrates that the CLS token, often overlooked, contains rich semantic information that can be effectively leveraged for zero-shot toxic image detection.
- Zero-shot safety is achievable with minimal overhead: SafeCLIP proves that robust safety mechanisms don't necessarily require extensive fine-tuning or architectural changes, making LVLMs more practical.
- Inherent multimodal alignment is key: By aligning visual semantics (via CLS token) with textual safety descriptors, SafeCLIP taps into the inherent capabilities of models like CLIP.
- Dynamic safety correction is more efficient: Integrating safety checks during fine-tuning, rather than pre-processing entire datasets, significantly reduces computational costs.
Key Results
- Defense Success Rate (DSR): SafeCLIP achieved a 66.9% DSR on toxic images, significantly outperforming baselines like ESCO (52.9%) and LlavaGuard (49.2%) on Llava-1.5.
- False Positive Rate (FPR): SafeCLIP maintained a low FPR of 3.2% on benign inputs, indicating minimal impact on utility.
- Efficiency: SafeCLIP adds only a 7.2% latency increase for neutral inputs and even a 5.7% reduction for toxic inputs (due to shorter refusal responses), a stark contrast to baselines like ESCO (up to 210% overhead) and LlavaGuard (up to 500% overhead).
- Classification Accuracy: In a separate classification task, SafeCLIP with K=5 parameters achieved the best performance, outperforming traditional methods and a basic MLP on the CLS token.
Limitations and Future Work
- Scope of Attacks: The current work focuses on defending against unmodified toxic images. Future research could explore using the CLS token to detect more sophisticated adversarial attacks that might induce harmful responses from seemingly benign images.
- Response Generation: While SafeCLIP effectively detects toxic content, alternative strategies for safe response generation, such as templated refusals or using models with enhanced safety, could be explored.
- Broader Spectrum of Attacks: Expanding the detection capabilities to a wider range of attack methods is a promising avenue.
Summary updated