Manuscript Offprint

arXiv:2609.37638

Targeted Visual Counterfactual Explanations for Contrastive Vision-Language Model

Van Bach Nguyen, Jörg Schlötterer, Christin Seifer

Abstract

Current explanation methods for contrastive vision-language models such as CLIP mainly identify important regions without showing how to change the input in order to get a target prediction. We introduce Mask-guided Adaptive Counterfactual Explanations (MACE), a targeted visual counterfactual method designed specifically for CLIP zero-shot classification. MACE constructs an editable region from either source attribution or source-target attribution differences and expands the mask only when needed to reach a specified target class. A latent diffusion inpainting model then modifies the selected region, while a frozen CLIP model provides modification guidance and anchors the remaining image content to the original input. We evaluate MACE on ImageNet, Food-101, Oxford Pets, and CUB-200. The source-mask variant achieves the highest target top-1 success rate across all four datasets, while the difference-mask variant produces the smallest pixel-level and perceptual changes and the best realism scores. Both variants improve proximity and realism over a Stable Diffusion-only baseline using the same generative backbone. These results show that adaptive mask-guided editing produces effective CLIP counterfactuals. They further reveal a tradeoff between counterfactual validity and source-image preservation. The source code is available at https://anonymous.4open.science/r/MACE-04BC/.

1. Introduction

CLIP [28] is widely used for zero-shot classification [22, 26, 31], retrieval [27, 30, 39], and multimodal applications ranging from safety inspection [25, 34] to decision support [45]. However, CLIP explanations remain dominated by attention and gradient maps, which highlight relevant regions without showing how the input must change to alter the prediction [19, 21, 44]. Counterfactual explanations address this limitation by identifying a small, meaningful change that produces a different model outcome [35].

Existing visual counterfactual methods mainly target conventional classifiers and optimize class logits or probabilities [1, 5, 10]. CLIP-guided editing methods instead optimize alignment with a target prompt [9, 40], but prompt alignment does not ensure that the target becomes the top prediction within the full zero-shot class set. These methods also do not necessarily produce the smallest localized edit responsible for the decision change.

We therefore propose Mask-guided Adaptive Counterfactual Explanations (MACE) (overview in Fig. 1), a method for targeted visual counterfactual explanations of CLIP zero-shot predictions. To our knowledge, MACE is the first image-level counterfactual method designed specifically for this setting. It uses CLIP attribution to localize editable regions and CLIP-guided diffusion inpainting to generate target features while preserving the remaining image. We consider two variants: a source-attribution mask and a source-target difference mask. Starting from a small editable region, MACE expands the mask only when needed and selects the smallest mask that changes the zero-shot prediction.

Across ImageNet, Food-101, Oxford Pets, and CUB-200, the source-mask variant achieves the highest validity, while the difference-mask variant produces the smallest image changes and the best realism scores. Both variants improve proximity and realism over a Stable Diffusion-only baseline with the same generative backbone. We also examine how CLIP guidance strength, mask fraction, and adaptive mask expansion affect counterfactual generation in MACE. In summary, our main contributions are:

• We introduce MACE, the first image-level counterfactual method designed specifically for CLIP zero-shot classification. MACE combines adaptive attribution masks, localized diffusion inpainting, and CLIP decision guidance.

• We evaluate two mask variants on four datasets and show consistent gains in validity, proximity, and realism over full-image diffusion editing.

• We show how CLIP guidance strength, mask fraction, and adaptive mask expansion affect counterfactual generation, providing practical insights for other diffusion-based editing methods.

References (45)

  • Diffusion visual counterfactual explanations
  • Universal guidance for diffusion models
  • Interpreting CLIP with sparse linear concept embeddings (SpLiCE)
  • Demystifying MMD GANs
  • Sparse visual counterfactual explanations in image space
  • Food-101 – mining discriminative components with random forests
  • Class activation values: Lucid and faithful visual interpretations for clip-based text-image retrievals
  • Imagenet: A large-scale hierarchical image database
  • StyleGAN-NADA: CLIP-guided domain adaptation of image generators
  • Counterfactual visual explanations
  • CPL: Counterfactual prompt learning for vision and language models
  • GANs trained by a two time-scale update rule converge to a local nash equilibrium
  • Classifier-Free Diffusion Guidance
  • Denoising diffusion probabilistic models
  • Diffusion models for counterfactual explanations
  • Text-to-image models for counterfactual explanations: A black-box approach
  • DiffusionCLIP: Text-guided diffusion models for robust image manipulation
  • Improving vision and language concepts understanding with multimodal counterfactual samples
  • A closer look at the explainability of contrastive language-image pre-training
  • Repaint: Inpainting using denoising diffusion probabilistic models
  • From visual explanations to counterfactual explanations with latent diffusion
  • Transductive zero-shot and few-shot CLIP. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 28816–28826
  • Cats and dogs
  • StyleCLIP: Text-driven manipulation of StyleGAN imagery
  • Safe-CLIP: Removing NSFW concepts from vision-and-language models
  • Online zero-shot classification with CLIP. In Computer Vision – ECCV 2024: 18th European Conference on Computer Vision, Proceedings, pages 462–477
  • CLIP is almost all you need: Towards parameter-efficient scene text retrieval without OCR. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 24873–24883
  • Learning transferable visual models from natural language supervision
  • High-resolution image synthesis with latent diffusion models
  • CLIP for all things zero-shot sketch-based image retrieval, fine-grained or not
  • Interpreting and analysing CLIP’s zero-shot image classification via mutual knowledge
  • Rethinking visual counterfactual explanations through region constraint
  • Designing counterfactual generators using deep model inversion
  • Construction safety inspection with contrastive language-image pretraining (CLIP) image captioning and attention
  • Counterfactual explanations without opening the black box: Automated decisions and the GDPR. Harvard Journal of Law & Technology, 31(2):841–887, 2017
  • The caltech-ucsd birds-200-2011 dataset
  • Visual explanations of image-text representations via multimodal information bottleneck attribution
  • Image quality assessment: From error visibility to structural similarity
  • RA-CLIP: Retrieval-augmented contrastive language-image pre-training
  • Towards counterfactual image manipulation via CLIP. In Proceedings of the 30th ACM International Conference on Multimedia (ACM MM), pages 3637–3645
  • OCTET: Object-aware counterfactual explanations
  • CF-VLM: Counterfactual vision-language fine-tuning
  • The unreasonable effectiveness of deep features as a perceptual metric
  • Gradient-based visual explanation for transformer-based CLIP. In Proceedings of the 41st International Conference on Machine Learning (ICML), pages 61072–61091
  • CLIP in medical imaging: A survey