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

CPL: Counterfactual Prompt Learning for Vision and Language Models

Xuehai He, Diji Yang, Weixi Feng, Tsu-Jui Fu, Arjun R. Akula, Varun Jampani, Pradyumna Narayana, Sugato Basu, William Yang Wang, Xin WangEMNLP 2022

Introduction

Large-scale vision-language models (VLMs), such as CLIP, have demonstrated remarkable capabilities in bridging the gap between visual and textual information. However, the performance of these models is often contingent on the quality of the text prompts used to guide them. While manual prompt engineering is labor-intensive, automated "prompt tuning"—learning continuous vector representations or "soft prompts"—has emerged as a popular alternative.

Despite its success, current prompt tuning methods suffer from a significant limitation: they frequently learn spurious correlations. For instance, if a model consistently sees a "train" on a "track" during training, it may incorrectly identify the track as a defining feature of the train. This entanglement of causal and non-causal features leads to poor generalization when the model encounters the same concept in a novel or unseen context. To address this, we introduce Counterfactual Prompt Learning (CPL), a framework designed to enhance the robustness of VLMs through counterfactual reasoning.

The CPL Framework

CPL shifts the focus from simple predictive accuracy to identifying the causal features that define a concept. It achieves this by asking "what if" scenarios: what minimal change in an image would cause its label to change? The CPL framework consists of three primary components:

1. Text-based Negative Sampling

To identify the most informative "hard" negative examples, CPL utilizes BERTScore to measure semantic similarity in the text domain. Rather than comparing a positive label (e.g., "Tabby cat") against a random, unrelated class (e.g., "Airplane"), the model identifies semantically similar negatives (e.g., "Tiger cat"). This ensures that the model focuses on the subtle nuances that distinguish closely related concepts.

2. Controllable Counterfactual Generation

Once a hard negative is identified, the model determines the minimal modification required in the visual feature space ($v$) to flip the predicted label to the negative class ($v^-$). By mixing these features, the model constructs a "counterfactual" feature ($v'$) that represents a near-miss scenario. This process effectively performs a virtual intervention on the data, isolating the features that are truly essential to the positive class.

3. Joint Optimization

The learnable prompts are trained using a dual-loss objective. A standard cross-entropy loss ensures basic predictive accuracy, while a contrastive loss (InfoNCE) forces the prompt to align closely with the factual image features while explicitly distancing it from the generated counterfactual features. This training regime encourages the model to ignore background noise and focus on causal attributes.

Experimental Evaluation

The researchers evaluated CPL across three diverse vision-and-language domains to test its generalization capabilities:

  • Image Classification: Tested on seven datasets, including ImageNet, SUN397 (scenes), OxfordPets, StanfordCars, and Flowers102.
  • Image-Text Retrieval: Evaluated using MSCOCO and Flickr30K.
  • Visual Question Answering (VQA): Tested on the VQAv2 dataset.

To rigorously assess generalization, the datasets were split into "seen" and "unseen" classes. The models were trained only on the seen classes and then evaluated on their ability to recognize and retrieve concepts they had never encountered during training.

Key Insights and Results

CPL demonstrates that focusing on causality rather than mere correlation significantly improves model robustness. Key findings include:

  • Superior Generalization: CPL consistently outperformed state-of-the-art baselines like CoCoOp. It achieved a 3.55% average relative improvement on unseen classes in classification tasks and up to a 4.09% improvement in Recall@1 for retrieval tasks.
  • Dramatic Gains in VQA: The most significant impact was observed in Visual Question Answering, where CPL achieved a 25.08% relative improvement on VQAv2, suggesting that counterfactual reasoning is particularly effective for complex reasoning tasks.
  • Data Efficiency: CPL proved highly effective in few-shot scenarios, maintaining strong performance even when using as little as 0.5% of the available training data. This indicates that counterfactual signals are much more informative than standard supervised signals.

Limitations and Future Directions

While CPL marks a significant step forward, several challenges remain. As the method is built upon CLIP, it may inherit inherent biases from the original large-scale pre-training data. Furthermore, the learned "soft prompts" exist as abstract vectors, making them difficult for humans to interpret. Future research will focus on "back-mapping" these vectors into natural language to improve explainability and bridging the domain gap between retrieval-based prompts and question-based prompts in VQA.

By teaching models to distinguish between what a concept is and what it is not through minimal interventions, CPL provides a scalable path toward more reliable and generalizable artificial intelligence.

Summary updated

BibTeX
@inproceedings{he2022cpl,
  author = {Xuehai He and Diji Yang and Weixi Feng and Tsu-Jui Fu and Arjun R. Akula and Varun Jampani and Pradyumna Narayana and Sugato Basu and William Yang Wang and Xin Wang},
  title = {{CPL: Counterfactual Prompt Learning for Vision and Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.224},
}
Figure