Prompt-Guided Contrastive Learning
- Prompt-guided contrastive learning is a paradigm that uses task-specific prompts to create semantic structures and shape discriminative representation learning.
- It integrates prompts with various contrastive objectives—ranging from instance-level clustering to prototype formation—to reduce sensitivity to prompt wording and labeled data scarcity.
- The approach is applied in NLP, vision-language, and control tasks, enhancing generalization, robustness, and efficiency in both few-shot and continual learning scenarios.
Prompt-guided contrastive learning denotes a family of methods in which prompts are used to define task structure, generate alternative views, construct prototypes or counterfactuals, retrieve adaptive conditioning variables, or specify contrastive references, while contrastive objectives organize representations, prompt parameters, or generative scores. The paradigm emerged in prompt-based few-shot NLP, where continuous or discrete prompts were coupled with contrastive objectives to reduce prompt sensitivity and label scarcity, and has since expanded to named entity recognition, unsupervised sentence embedding, code search, medical image-text pretraining, CLIP adaptation, diffusion guidance, federated continual learning, and embodied control (Xu et al., 2022, Jian et al., 2022, He et al., 2022).
1. Early formulations and defining motivations
The earliest formulations in this literature addressed a common weakness of prompt-based few-shot learning: prompts can expose pretrained knowledge, but performance remains highly sensitive to prompt wording, verbalizer design, and the scarcity of labeled examples. CP-Tuning introduced an end-to-end contrastive prompt tuning framework that removed manual task-specific prompts and verbalizers by combining task-invariant continuous prompt encoding with a pair-wise cost-sensitive contrastive objective on dense [OMSK] embeddings, together with an auxiliary MLM loss (Xu et al., 2022). In parallel, prompt-based few-shot classification was recast as supervised contrastive learning over prompt-generated views, where the standard prompt-based masked-language-model setup was retained but supplemented with class-level clustering and separation in representation space (Jian et al., 2022).
These early works established two durable ideas. First, prompting is not only an interface for converting downstream tasks into cloze-style prediction problems; it is also a mechanism for creating semantically valid contrastive structure. Second, contrastive learning can replace or supplement verbalizer-based supervision by directly shaping the geometry of the hidden space. ConPVP extended this line to unsupervised sentence embedding by deriving virtual semantic prototypes from prompts and negative forms of prompts, rather than relying exclusively on instance-wise augmentation (Zeng et al., 2022). ConsPrompt further argued that few-shot prompt learning benefits from “multi-degree” contrastive supervision at both prompt level and batch level, using contrastive sampling and scoring modules to improve robustness and reduce overfitting (Weng et al., 2022).
2. Core mechanisms and recurring design patterns
Across the literature, prompt-guided contrastive learning follows a recurring joint-training pattern in which a task loss is combined with a contrastive term, but the object being contrasted varies substantially. In prompt-based few-shot classification, the total objective is written as (Jian et al., 2022). In ContrastNER, a weighted combination balances a supervised contrastive loss with a cross-entropy term for soft prompt learning (Layegh et al., 2023). In PromptCL, event representation learning combines contrastive loss, Event-oriented MLM, and prototype-based clustering loss (Feng et al., 2024). The unifying feature is not a single formula but the use of prompts to determine what constitutes a meaningful positive or negative relation.
One major pattern uses prompts as view constructors. In few-shot language learning, multiple views of the same labeled instance are created by changing the template and/or the contextual demonstrations, so that the underlying example is fixed while prompt context varies (Jian et al., 2022). LM-CPPF replaces template variation with paraphrasing-guided augmentation, using LLM-generated paraphrases as semantically consistent views of the same example, while still preserving the LM-BFF-style prompt-based classification setup (Abaskohi et al., 2023). PromptCL applies prompt insertion probabilistically to short event texts, creating prompt-augmented positives for dual-positive contrastive learning and thereby reducing the mismatch between event length and PLM pretraining length (Feng et al., 2024).
A second pattern treats prompts as trainable adapters or latent parameters rather than fixed strings. This includes continuous prompt encoding in CP-Tuning, continuous implicit prompts in UMCL, soft-hard prompt tuning in ContrastNER, separate continuous prompts for NL and PL encoders in CPLCS, and prompt pools or deep layer-wise prompt insertion in later CLIP-based methods (Xu et al., 2022, Wang, 2023, Layegh et al., 2023, Zhang et al., 2023, Zhan et al., 7 Sep 2025). In these systems, the contrastive objective often supervises the prompts themselves rather than merely the backbone representation.
A third pattern uses prompts to define prototypes, anchors, or counterfactuals. ConPVP interprets [MASK] states under positive and negative prompts as virtual semantic prototypes (Zeng et al., 2022). ContrastNER removes manual verbalizers and instead predicts entity types by comparing learned masked-label embeddings in a contrastive space (Layegh et al., 2023). CPL constructs counterfactual image features from semantically similar positive and negative samples and then contrasts factual and counterfactual prompt-conditioned alignments to suppress spurious correlations (He et al., 2022). An even broader variation appears in diffusion guidance, where the contrastive object is not an embedding pair but the score difference between a positive prompt and a baseline prompt (Wu et al., 2024).
3. Text-centric applications
The most developed text-centric strand is few-shot classification. In “Contrastive Learning for Prompt-Based Few-Shot Language Learners,” prompt and demonstration variation are used as natural augmentations, and the method improves over state-of-the-art prompt-based baselines on 15 language tasks with 16 training examples per class; the reported average gain over LM-BFF is about 2.5 points, with gains up to 6.3 points on QQP (Jian et al., 2022). LM-CPPF retains the prompt-based MLM classification view but uses paraphrases generated by LLMs such as GPT-3 and OPT-175B as positive views for supervised contrastive learning, and reports that this augmentation outperforms easy data augmentation, back translation, and multiple templates on six text classification benchmarks (Abaskohi et al., 2023). ConsPrompt emphasizes robustness rather than verbalizer removal, combining prompt encoding, contrastive sampling, and contrastive scoring; it reports up to 87.5 on TREC, 77.3 on SNLI, 72.0 on QNLI, and 95.0 on SST-2, while also stressing lower variance than baselines (Weng et al., 2022).
Named entity recognition adapted the same paradigm in a verbalizer-free direction. ContrastNER formulates NER as prompt-based classification with mixed discrete and continuous tokens, uses supervised contrastive learning on the predicted masked-label embeddings, and performs inference through nearest neighbors in embedding space rather than manual label-word mapping. Its reported full-resource CoNLL03 F1 is 92.22, and its in-domain few-shot CoNLL03 F1 is 79.27, with particularly strong results on LOCATION at 73.98 and MISCELLANEOUS at 75.13 (Layegh et al., 2023).
Prompt-guided contrastive learning has also been used to improve more structured or representation-oriented text tasks. PromptCL expands short event tuples into semantically explicit prompt templates such as “subject is ... predicate is ... object is ...”, combines this with SPO word order and EventMLM, and reports 81.7 on the original hard similarity task, 78.7 on the extended version, 0.82 on transitive sentence similarity, and 47.06 on zero-shot MCNC (Feng et al., 2024). In code search, CPLCS combines dual-encoder prompt tuning, PL-NL contrastive learning, and a cross-modal interaction matrix, reporting an overall MRR of 0.789 and Recall@1/5/10 of 0.701, 0.902, and 0.940 on CodeSearchNet across six languages (Zhang et al., 2023).
The unsupervised sentence embedding literature provides a complementary perspective. ConPVP does not rely on labeled classes; instead it derives prompt-conditioned positive and negative prototypes and trains anchors to approach their semantic prototypes while avoiding negative prototypes and prototypes of other sentences. On average STS performance, it reports 80.18 with RoBERTa-large versus 78.90 for SimCSE, and on clustering it reports 63.86 with BERT-base versus 57.58 for SimCSE (Zeng et al., 2022). This suggests that prompt-guided contrastive learning is not limited to supervised label separation; it can also impose semantic organization on otherwise instance-wise embedding objectives.
4. Vision-language, medical, and generative variants
In vision-language transfer, the paradigm shifts from prompting text-only PLMs to steering frozen multimodal backbones. CPL frames standard prompt tuning for CLIP as prone to spurious or entangled features and responds by constructing counterfactual image features from semantically similar negative samples, then applying contrastive learning to factual and counterfactual prompt-conditioned pairs. It reports a 3.55% average relative improvement on unseen classes across seven image-classification datasets, up to 4.09% relative improvement on image-text retrieval, and up to 25.08% relative improvement on VQA (He et al., 2022).
UMCL adapts the same broad idea to medical image-text pretraining. It uses continuous prompts to unify image-text and image-label supervision in a shared contrastive space, explicitly addressing false negatives caused by highly similar medical images and semantically related reports. The framework reports zero-shot ACC values of 0.527, 0.497, 0.707, and 0.670 for UMCL, and 0.541, 0.505, 0.748, and 0.764 for UMCL-ENS on CheXpert-5x200, MIMIC-5x200, COVID, and RSNA, respectively; on CheXpert-5x200 retrieval it reports P@1 of 0.467, P@2 of 0.472, P@5 of 0.480, and P@10 of 0.467 (Wang, 2023).
Later CLIP-based work made prompt selection dynamic. AttriPrompt argues that deep text prompting suffers from static prompts and over-reliance on global contrastive alignment, and therefore retrieves prompts from a prompt pool using intermediate-layer visual attributes, injects them into every text-encoder layer, and adds a dual-stream contrastive objective together with self-regularization. It reports an average base-to-novel harmonic mean of 81.09, exceeding PromptSRC at 79.97 and MaPLe at 78.55, and a EuroSAT novel score of 81.27, described as a 7.37% improvement over MaPLe (Zhan et al., 7 Sep 2025).
Prompt-guided contrastive learning has also been used adversarially. PDCL-Attack trains a perturbation generator with a surrogate-model loss plus a CLIP-guided prompt-driven contrastive loss in which the adversarial image feature is pulled toward a selected adversarial text feature and pushed away from the ground-truth text feature. It reports average post-attack accuracies of 43.91 in cross-domain settings and 38.60 in cross-model settings, and an attack success rate of 54.78 on a balanced ImageNet subset, outperforming several iterative attacks (Yang et al., 2024).
A distinct generative formulation appears in diffusion models. “Contrastive Guidance” does not train a new prompt encoder or an InfoNCE loss; instead it modifies classifier-free guidance so that an intended factor is defined by the difference between a positive prompt and a baseline prompt. The resulting score term, proportional to , is used to improve disentanglement in domain-specific diffusion, provide continuous rig-like controls, and strengthen zero-shot editors. In the editing setting, the method is reported to make SDEdit and CycleDiffusion about more efficient in practice while improving directional CLIP, PSNR, and SSIM (Wu et al., 2024).
5. Continual, federated, and embodied adaptation
Outside static supervised benchmarks, prompt-guided contrastive learning has become a mechanism for efficient adaptation under heterogeneity and nonstationarity. Fed-CPrompt addresses rehearsal-free federated continual learning by freezing a pretrained ViT, learning task-specific prompts and classifier heads, and regularizing prompt evolution with a contrastive continual loss that keeps each task prompt close to its previous server-side version while separating it from prompts of other tasks. The paper states that non-prompt methods optimize about 86 million parameters whereas Fed-CPrompt optimizes about 4 million, roughly 4.18% of the full amount. On CIFAR-100 split into 10 tasks across 10 clients, it reports 79.43 accuracy and 4.75 forgetting under IID conditions, 65.45 accuracy and 9.15 forgetting under non-IID label skew, and average asynchronous gains of 2.07% in IID and 11.79% in non-IID settings (Bagwe et al., 2023).
Embodied reinforcement learning adds another layer of complexity because the prompt-conditioned representation must remain useful for control under domain shifts. ConPE uses a pretrained CLIP ViT-B/32, learns a pool of visual prompts in an offline contrastive phase so that each prompt specializes to a domain factor such as brightness, camera position, step size, or weather, and then combines the prompted embeddings with a guided-attention ensemble during policy learning. On AI2THOR, it reports ObjectNav source, seen-target, and unseen-target scores of 96.3, 83.3, and 79.7; it also reports that comparable performance on unseen domains requires less than 50% of ATC samples, about 60% of EmbCLIP samples for seen domains, and about 50% for unseen domains (Choi et al., 2024).
CAPO develops this line further for cross-embodiment visuomotor control. It learns a prompt pool with three objectives—visual contrastive learning for appearance factors, BYOL-style temporal action contrastive learning for embodiment-related factors, and text contrastive learning for semantic grounding—and then uses adaptive prompt orchestration to form observation-conditioned convex combinations of prompt-conditioned features. On source domains it reports SR and SPL ; on unseen target domains it reports SR and SPL ; it also reports successful deployment on unseen robot embodiments including Stretch RE1 and LoCoBot after training on ManipulaTHOR (Zhang et al., 1 Feb 2026). In these systems, prompts are no longer static tokens but domain-factor experts selected or weighted online.
6. Benefits, misconceptions, and limitations
Several benefits recur across the literature. Prompt-guided contrastive learning often improves generalization under severe label scarcity, as in few-shot text classification and NER (Jian et al., 2022, Layegh et al., 2023). It can reduce dependence on manual prompt engineering or verbalizer design, as emphasized by CP-Tuning, ContrastNER, and UMCL (Xu et al., 2022, Layegh et al., 2023, Wang, 2023). In vision-language and embodied settings, it is repeatedly used to disentangle nuisance factors from task semantics and to improve transfer to unseen classes, domains, or embodiments (He et al., 2022, Zhan et al., 7 Sep 2025, Zhang et al., 1 Feb 2026). A plausible implication is that prompting becomes more stable when it is constrained by geometric structure rather than evaluated only through next-token likelihood or plain classification loss.
A common misconception is that any augmentation suffices once a contrastive objective is added. The evidence is more selective. In prompt-based few-shot language learning, standard text augmentations such as synonym replacement, random insertion, random swap, random deletion, and EDA often hurt performance, whereas template and demonstration variation preserve label semantics and work substantially better (Jian et al., 2022). LM-CPPF similarly reports that LLM-generated paraphrases outperform EDA, back translation, and multiple templates (Abaskohi et al., 2023). Another misconception is that prompt-guided contrastive learning always means standard instance discrimination. The literature contains supervised contrastive objectives over masked-token states, prototypical contrast over prompt-derived virtual prototypes, prompt-space margin regularization in federated continual learning, dual-stream alignment in CLIP adaptation, and score-space prompt differences in diffusion (Zeng et al., 2022, Bagwe et al., 2023, Zhan et al., 7 Sep 2025, Wu et al., 2024).
The field also has clear limitations. The prompt-based few-shot classification framework of Jian et al. is designed for classification tasks where labels can be clustered and relies on large batch sizes, making it memory-intensive (Jian et al., 2022). Contrastive Guidance in diffusion depends strongly on the quality of the positive/baseline prompt pair and reports failures or biases on concepts such as AR glasses, certain pose directions, storm weather, exposure, and some colors (Wu et al., 2024). ConsPrompt identifies comparison-sample selection as an unresolved controllability issue, indicating that contrastive gains remain sensitive to the quality of positive and negative sampling (Weng et al., 2022). In automated prompt optimization, LCP shows a 76.67% win rate on Big-Bench Hard when the best training-accuracy prompt is selected, but its cross-lingual results also indicate that query translation often remains stronger overall, even though LCP prompt refinement beats prompt baselines on 7 of 11 languages (Li et al., 2024).
Taken together, these works define prompt-guided contrastive learning less as a single algorithm than as a design space. Prompts may serve as semantic scaffolds, trainable adapters, retrieval keys, counterfactual constructors, or optimization objects; contrastive learning may act on embeddings, prototypes, prompts, or generative scores. What remains stable across the literature is the claim that prompting alone exposes pretrained structure, whereas contrastive objectives make that structure discriminative, transferable, and, in many settings, more resistant to spurious correlations.