NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Visualizing and Understanding Contrastive Learning

Fawaz Sammani, Boris Joukovsky, Nikos Deligiannis · DOI

TL;DR

Traditional Explainable AI (XAI) tools fail to explain contrastive learning models because they evaluate single images in isolation, ignoring the interdependent pairs used during training. This paper introduces novel, architecture-independent XAI methods specifically designed to visualize pair-based similarity and invariance, alongside adapted evaluation metrics to measure their faithfulness.

What Problem Does This Paper Address?

Self-supervised contrastive learning (CL) has revolutionized computer vision by learning powerful representations from unlabeled data. It works by maximizing the similarity between different augmented views of the same image (positive pairs) while minimizing it for different images (negative pairs).

However, understanding why a contrastive model deems two images similar has remained a black box. Traditional local post-hoc attribution methods—like Grad-CAM, Integrated Gradients, or Occlusion analysis—were built for single-image classification tasks. They assume independent inputs, making them fundamentally ill-suited for CL models that process shared, entangled, and interdependent pairs of images.

Contrastive models compare pairs of inputs to determine similarity, requiring specialized explanation methods.

Furthermore, the field has lacked quantitative evaluation metrics designed to assess pairs of visual explanations simultaneously. This paper fills these gaps by introducing tailored XAI methods and evaluation frameworks for similarity-based vision models.

Methods

The authors propose three architecture-independent visual explanation techniques that account for both similarity and invariance spaces:

  1. Averaged Transforms (Saliency-based): Instead of computing gradients on a single image view, this method decomposes a data transformation (such as color jitter or Gaussian blur) into a gradient of varying strengths and averages the resulting saliency maps. This directly incorporates the model's learning objective—invariance to transformations—into the explanation.
  2. Pairwise Occlusion (Perturbation-based): Standard occlusion techniques mask a region in one image while keeping the other fully visible. However, if the model can infer the missing part from the surrounding context, the similarity score won't drop. Pairwise Occlusion simultaneously perturbs both images across random sizes, locations, and aspect ratios, using a softmax operation to distribute importance to highly activated features.
  3. Interaction-CAM (Activation-based): This method extends Grad-CAM by introducing a joint activation term (the element-wise product of feature maps from both images) and a gradient interaction matrix (a cross-correlation matrix of the gradients). This captures how the channel gradients of the two images influence each other, highlighting features that are jointly active.

To quantitatively evaluate these pairs of explanations, the authors adapt standard single-image metrics (Insertion, Deletion, and Average Drop) into two new settings: Simultaneous Evaluation (altering both images at once) and Conditional Evaluation (altering one image while keeping the other fully observed).

Datasets

The methods were evaluated using a randomly selected subset of 2,000 images from the ImageNet ILSVRC-2012 validation set. The explanations were tested across five prominent self-supervised models:

  • SimCLRv2 (1× and 2×)
  • Barlow Twins
  • SimSiam
  • MoCov3 (utilizing a Vision Transformer backbone)

Key Insights and Ideas

  • Invariance Increases with Depth: Feature inversion experiments confirmed that as representations move deeper into a contrastive model, color and saturation information are progressively discarded. This proves that CL models successfully learn latent representations invariant to standard data augmentations.
  • The Texture Shortcut Bias: Contrastive models are highly prone to texture shortcuts. When evaluating 50 image pairs containing entirely different objects that shared a common texture (e.g., a tiger and a striped cat), the models based their similarity explanations on the texture (stripes) rather than the actual object structure in 64% of cases.
  • Diagnosing Harmful Augmentations: The proposed XAI tools can pinpoint exactly why a model fails. The authors discovered that combining heavy blur with extreme "blackening" (low brightness from color jitter) severely harms similarity estimation, causing the model to focus on meaningless background concepts in 94% of analyzed failure cases.
  • Explainability Correlates with Performance: The authors found a strong positive correlation between a model's explainability score and its accuracy on downstream tasks (like ImageNet linear probing). Better-performing models naturally produce more faithful and localized joint explanations.

Key Results

  • Faithfulness: Averaged Transforms (with gradient interaction) achieved the highest scores in faithfulness metrics, such as Simultaneous and Conditional Insertion, across the SimCLRv2 models. For deletion and average drop metrics, Conditional Occlusion performed best on average.
  • Computational Efficiency: Activation-based methods proved to be the fastest by orders of magnitude. Interaction-CAM (with gradient interaction) took only 0.050 seconds per image pair, compared to 2.258 seconds for Smooth-Grad and 0.980 seconds for Conditional Occlusion.
  • Sanity Checks: All proposed methods successfully passed parameter randomization sanity checks, proving they are genuinely sensitive to model weights and do not merely function as low-level edge detectors.

Limitations and Future Work

  • Sample Size for Qualitative Analysis: The exploration of failure modes and texture biases was conducted on relatively small sample sizes (e.g., 50 image pairs), meaning some subtle biases might have been overlooked.
  • Evaluation Scope: While the paper covers five major self-supervised models, expanding the benchmarks to a wider variety of architectures and newer contrastive objectives would provide a more comprehensive industry standard.
  • Pairwise Occlusion Artifacts: Pairwise Occlusion tends to create plateaus in evaluation curves because it assigns uniform softmax scores over broad masked regions, which penalizes its Area Under the Curve (AUC) metrics compared to baseline occlusion methods. Refining how scores are distributed across perturbed regions remains an open challenge.

Summary updated

BibTeX
@article{sammani2024visualizing,
  author = {Fawaz Sammani and Boris Joukovsky and Nikos Deligiannis},
  title = {{Visualizing and Understanding Contrastive Learning}},
  journal = {IEEE Trans. Image Process.},
  year = {2024},
  doi = {10.1109/tip.2023.3346295},
}
Figure