A Closer Look at the Explainability of Contrastive Language-Image Pre-training

Yi Li, Hualiang Wang, Yiqun Duan, Xiaomeng Li, Li, Xiaomeng · DOI

Abstract

Contrastive language-image pre-training (CLIP) is a powerful vision-language model that has shown great benefits for various tasks. However, we have identified some issues with its explainability, which undermine its credibility and limit the capacity for related tasks. Specifically, we find that CLIP tends to focus on background regions rather than foregrounds, with noisy activations at irrelevant positions on the visualization results. These phenomena conflict with conventional explainability methods based on the class attention map (CAM), where the raw model can highlight the local foreground regions using global supervision without alignment. To address these problems, we take a closer look at its architecture and features. Based on thorough analyses, we find the raw self-attentions link to inconsistent semantic regions, resulting in the opposite visualization. Besides, the noisy activations are owing to redundant features among categories. Building on these insights, we propose the CLIP Surgery for reliable CAM, a method that allows surgery-like modifications to the inference architecture and features, without further fine-tuning as classical CAM methods. This approach significantly improves the explainability of CLIP, surpassing existing methods by large margins. Besides, it enables multimodal visualization and extends the capacity of raw CLIP on open-vocabulary tasks without extra alignment.

Introduction

Contrastive Language-Image Pre-training (CLIP) has revolutionized vision-language understanding, yet its internal decision-making process is often visually nonsensical. When researchers attempt to visualize what CLIP "sees" using standard Class Attention Map (CAM) methods, they encounter two major hurdles: opposite visualization, where the model attends to backgrounds (like sky or fences) instead of the target object, and noisy activations, which create irrelevant "hot spots" across the image. These issues undermine the model's credibility for high-precision tasks like semantic segmentation.

Comparison of CLIP visualization issues (opposite and noisy activations) and the improvements achieved by CLIP Surgery.

Methodology: CLIP Surgery

To address these transparency issues without the need for costly fine-tuning, we introduce CLIP Surgery. This training-free approach applies surgical modifications to the model's inference architecture and feature processing.

1. Architecture Surgery

Analysis reveals that CLIP's standard self-attention uses distinct Query ($Q$) and Key ($K$) parameters that often link semantically inconsistent regions, leading to background bias. We replace this with Consistent Self-Attention, utilizing homogeneous parameters (specifically the Value ($V$) parameter) for attention matrix calculation. This ensures tokens link to semantically similar neighbors.

Additionally, we found that Feed-Forward Networks (FFNs) push features toward "negative" labels to aid classification, which inadvertently degrades visual explainability. CLIP Surgery implements a Dual Path strategy that aggregates beneficial self-attention modules while bypassing the detrimental effects of FFNs during visualization.

2. Feature Surgery

Noisy activations are largely caused by features that are redundant across many different categories. By identifying these common biases—averaging features across the class dimension—we can subtract this "redundant feature" from specific class features. This process sharpens the model's focus on the unique, discriminative characteristics of the target object.

Overview of the CLIP Surgery framework, illustrating the dual-path architecture and the data flow for feature-level surgery.

Key Insights and Results

Our investigation into CLIP's architecture yielded several critical findings:

  • FFNs as "Explainability Killers": While crucial for classification accuracy, FFNs are the primary source of messy, non-localized attention maps.
  • The "Empty String" Evidence: Prompting CLIP with an empty text string produces a noise pattern identical to the noise seen during object identification, proving that "noise" is a structural bias in redundant features.

Performance Gains

CLIP Surgery demonstrates massive improvements across multiple benchmarks without any retraining:

  • Explainability: On PASCAL VOC 2012, CLIP Surgery improved mean Intersection over Union (mIoU) by over 35% compared to raw CLIP.
  • Background Bias Mitigation: Using the mean Score Contrast (mSC) metric, CLIP Surgery achieved average improvements of over 47% in foreground-background separation.
  • Open-Vocabulary Superiority: CLIP Surgery outperformed specialized, trained models like MaskCLIP and GroupViT on semantic segmentation, achieving 29.3% mIoU on PASCAL Context.

Conclusion

CLIP Surgery provides a robust, training-free solution to the explainability crisis in contrastive vision-language models. By navigating the existing architecture differently during inference, we unlock CLIP's latent ability to accurately localize objects. While it does not change the final classification rank in single-label scenarios, its impact on multi-label recognition and open-vocabulary segmentation is transformative.

Source: Li et al., "A Closer Look at the Explainability of Contrastive Language-Image Pre-training," Pattern Recognition, 2024.

Summary updated

BibTeX
@article{li2025closer,
  author = {Yi Li and Hualiang Wang and Yiqun Duan and Xiaomeng Li and Li, Xiaomeng},
  title = {{A Closer Look at the Explainability of Contrastive Language-Image Pre-training}},
  journal = {Pattern Recognition},
  year = {2025},
  url = {https://openreview.net/forum?id=pnhwewWTLe},
}
Figure