---
title: Contrastive Prompting for Explanation Generation
url: https://www.emergentmind.com/topics/contrastive-prompting-for-explanation-generation-cpeg
type: topic
---

# Contrastive Prompting for Explanation Generation

Contrastive Prompting for Explanation Generation (CPEG) is introduced in explainable recommendation as **Contrastive Prompting for ground-truth Explanation Generation**, a module that generates higher-quality explanation targets by contrasting a true interacted item with negative candidate items and refining outputs through error-aware retry prompting [2507.06044]. In a broader technical sense, CPEG belongs to a contrastive explanation tradition in which explanations are organized around a fact and a foil, or around the question “Why \(P\) rather than \(Q\)?”, so that the explanation isolates the difference that makes the difference rather than listing generic supporting information [1811.03163; 2106.06823]. This contrastive orientation also appears in task allocation, commonsense question answering, prompt attribution, and prompt-counterfactual analysis, where explanations are most informative when they discriminate among plausible alternatives rather than justify an output in isolation [2002.01640; 2305.08135; 2405.20404].

## 1. Conceptual basis and problem setting

In the explainable recommendation formulation, CPEG is introduced to solve a specific supervision problem: many datasets use the user’s review as the “ground-truth explanation,” yet those reviews are often vague, minimal, or non-explanatory, such as “it’s good” or even an emoji [2507.06044]. The consequence is that a downstream explanation model trained on such targets learns to imitate low-information outputs. CPEG is therefore designed to **replace or refine weak user-written reviews with stronger synthetic explanations** that are more aligned with the user-item interaction and more useful as supervision [2507.06044].

The method differs from ordinary prompting in three ways. First, explanation quality is tied to a **discrimination task**: an explanation is accepted only if the reasoning model identifies the correct positive item among negatives. Second, contrast is built directly into the prompt through a positive item and multiple negative items, including hard negatives. Third, incorrect predictions and explanations are reused as explicit error examples in a retry prompt, so the method is not a one-shot generation procedure [2507.06044].

This design is consistent with the older structural account of contrastive explanation, where an explanation is not merely a cause of \(P\), but a causal difference between \(P\) and a contrast case \(Q\) [1811.03163]. Related prompting work in commonsense reasoning adopts the same logic by defining a contrastive explanation as an answer to “Why \(P\) rather than \(Q\)?”, where \(P\) is the fact and \(Q\) is the foil, and by preferring discriminative attributes over exhaustive causal lists [2106.06823]. This suggests that CPEG is best understood not simply as “prompting for explanations,” but as prompting for explanations that are validated by their ability to separate the selected outcome from competing alternatives.

## 2. Architecture within the PGHIS-CPEG-SFT pipeline

The full method in which CPEG appears has three stages: **PGHIS**, **CPEG**, and **SFT** [2507.06044]. PGHIS, or Profile Generation via Hierarchical Interaction Summarization, replaces embedding-only user and item representations with textual profiles constructed and iteratively updated by a pretrained LLM. CPEG then uses those profiles to synthesize high-quality explanation targets. Finally, a smaller model is fine-tuned so that inference-time explanation generation is efficient.

The pipeline is organized as follows:

| Stage | Input | Output |
|---|---|---|
| PGHIS | Raw user/item attributes and interaction neighborhoods | Textual user and item profiles |
| CPEG | User profile, positive item profile, negative item profiles, review | Accepted synthetic explanation target |
| SFT | User profile + item profile | Fine-tuned explanation generator |

PGHIS initializes user and item profiles from raw attributes:
\[
p_{u_i}^{0} = LLM(\mathcal{P}_{init}, a_{u_i})
\]
\[
p_{i_i}^{0} = LLM(\mathcal{P}_{init}, a_{i_i})
\]
and then updates them hierarchically using neighboring interaction profiles:
\[
p_{u_i}^{l} = LLM(\mathcal{P}_{agg}, p_{u_i}^{l-1}, \mathcal{N}_{i_i}^{l-1})
\]
\[
p_{i_i}^{l} = LLM(\mathcal{P}_{agg}, p_{i_i}^{l-1}, \mathcal{N}_{u_i}^{l-1})
\]
where the aggregation prompt instructs the model to summarize common features of interacted items or users and update the original profile [2507.06044].

CPEG then operates on these textual profiles rather than on raw embeddings. Its inputs are the user profile \(p_{u_i}\), the positive interacted item profile \(p_{i_i^+}\), and a set of negative item profiles \(p_{i_1^-}, \dots, p_{i_{k+m}^-}\), with the prompt text also stating that the **review of the interacted item written by the user** may be included [2507.06044]. The use of textual profiles is central to the paper’s overall position that embeddings “lack inherent semantics,” whereas textual profiles provide explicit representations of user and item characteristics [2507.06044].

At deployment time, CPEG itself is not the main generator. Instead, the accepted synthetic explanations produced by CPEG become supervised fine-tuning targets for **Qwen2.5-7B-Instruct**, so the final inference-time model maps profile pairs directly to explanations [2507.06044]. This means CPEG functions primarily as a **contrastive data-generation module**.

## 3. Prompting mechanism, contrast structure, and formal procedure

CPEG has two substeps: **discrimination** and **refinement** [2507.06044]. In the discrimination step, the reasoning model receives a prompt containing the user profile, the positive item profile, and negative item profiles. The system prompt is described as asking the model to find the item the user interacted with and explain why the user would interact with it [2507.06044]. The first-pass generation is formalized as:
\[
T, \hat{y}, E = RLM(\mathcal{P}, p_{u_i}, p_{i_i^+}, p_{i_1^-}, ...p_{i_{k+m}^-})
\]
where \(T\) is the reasoning process, \(\hat{y}\) is the predicted interacted item, and \(E\) is the generated explanation [2507.06044].

Negative sampling is explicitly contrastive. The paper uses two types of negatives: **hard negatives**, defined as semantically similar to the user profile, and **random negatives**, sampled from the rest of the non-interacted items [2507.06044]. Hard negatives are selected by cosine similarity over profile embeddings:
\[
sim(e_1,e_2) = \frac{e_1 \cdot e_2}{|e_1||e_2|}
\]
with **all-MiniLM-L6-v2** used to embed profiles for this purpose [2507.06044]. This yields a candidate set in which some distractors are close to the user’s interests and others are merely negative.

The refinement step is triggered when the first pass fails. If \(\hat{y}\) is correct, the explanation \(E\) is accepted as a high-quality target. If \(\hat{y}\) is wrong, the mistaken prediction \(\hat{Y_e}\) and erroneous explanation \(E_e\) are retained and inserted into a retry prompt:
\[
T, \hat{y}, E = RLM(\mathcal{P}_{retry}, p_{u_i}, p_{i_i^+}, p_{i_1^-}, ...p_{i_7^-}, \hat{Y_{e}, E_{e})
\]
and the process continues “until the model generates the correct item that the user has interacted with” [2507.06044]. The accepted explanation is then used as the new ground truth.

A notable property is that the method is **contrastive procedurally, not via an explicit differentiable contrastive objective**. The paper states that CPEG does **not** define an explicit contrastive loss, ranking loss, pairwise preference loss, or auxiliary loss. Its contrastiveness is implemented through prompt construction, hard negative sampling, correctness filtering, and retry prompting with error examples [2507.06044]. This places it closer to prompt-level discrimination and rejection-based refinement than to metric learning.

The contrastive structure itself has three layers. It contrasts **positive vs. negative candidate items**, **correct vs. incorrect explanations**, and **hard negatives vs. random negatives** [2507.06044]. A plausible implication is that CPEG does not merely seek an explanation that sounds plausible; it seeks an explanation that survives explicit competition with distractors and prior failed explanations.

## 4. Empirical findings and ablation evidence

The method is evaluated on **Amazon-Book**, **Yelp**, and **Steam**, with 3:1:1 splits and subsets used for profile generation, supervised fine-tuning, and testing [2507.06044]. The full **PGHIS-CPEG-SFT** system outperforms Att2Seq, NRT, PETER, PEPLER, and XRec on explainability and text-quality metrics, and the abstract reports about **5% improvement on GPTScore** as well as **20.6%** and **19.6%** improvements on BLEU/ROUGE variants [2507.06044].

The most direct evidence for CPEG itself comes from the **Ground Truth Explanation Quality** experiment. In that study, GPT-3.5 acts as judge and compares user-written reviews, XRec-generated ground truths, and several CPEG variants. The paper reports that CPEG explanations significantly outperform both user reviews and XRec-generated ground truths, with best-reported win rates of **86.7%** and **93.0%** on Amazon-Books and Steam [2507.06044].

Hard negatives matter materially. Compared to using only 7 random negatives, adding **2 hard negatives + 5 random negatives** improves win rate by **7.1%** and **7.6%** on the two datasets considered in that comparison [2507.06044]. The authors also report a tradeoff: more hard or random negatives can further improve explanation quality, but they make correct selection harder for the reasoning model, which increases retries and computational cost, and gains eventually diminish. The selected setting is:
\[
k = 2,\quad m = 5
\]
for hard and random negatives, respectively [2507.06044].

The paper does not provide an ablation that removes CPEG alone from the full system. Instead, ablations focus mainly on PGHIS variants such as w/o Fine-tuning, w/o PGHIS-user, w/o PGHIS-item, and w/o PGHIS [2507.06044]. Consequently, the strongest direct evidence for CPEG is the ground-truth quality comparison and the hard-negative study, rather than a clean component-removal experiment.

A qualitative case study further reports that even when the original review is extremely weak, such as only an emoji, CPEG can still generate a plausible explanation of why the user interacted with the item, and the fine-tuned model later produces outputs close to the CPEG ground truth [2507.06044]. This reinforces the specific role of CPEG as supervision repair.

## 5. Relation to adjacent contrastive explanation methods

CPEG sits within a larger family of contrastive explanation methods, but its exact instantiation is domain-specific. In commonsense reasoning, prompt-based contrastive explanations have been used to compare answer alternatives through discriminative attributes, such as “Peanuts are salty while raisins tend to be sweet,” and to condition downstream answer prediction on generated explanations [2106.06823]. That work uses manually derived contrastive templates, neutralized context \(c a_0\), multiple candidate explanations, and marginalization over explanations, and it reports that human annotators spontaneously gave contrastive explanations in **76%** of Winogrande and **64%** of PIQA pilot examples [2106.06823]. In multiple-choice QA, **CPACE** similarly converts symbolic knowledge into contrastive natural-language explanations using templates such as “Given concept sets \([OPT_1, ..., OPT_n]\), the difference among them is ...”, and then feeds those explanations back into inference [2305.08135].

In other application areas, contrastive explanation is realized through different substrates. In negotiation-aware task allocation, negotiation-tree based explanations are used to answer counterfactual challenges about alternative allocations, and human studies report that such explanations are more convincing than vacuous baselines [2002.01640]. In prompt attribution and prompt-focused interpretability, **XPrompt** formulates generation explanation as combinatorial search over prompt subsets whose masking most reduces support for the original full output sequence [2405.20404], while **CELL** explains an LLM response through nearby prompt edits that induce a less preferable or contradictory reply under a user-defined scoring function [2406.11785]. **Prompt-Counterfactual Explanations** extend counterfactual explanation to stochastic generative systems by searching for minimal prompt elements whose removal moves a downstream classifier-defined behavior across a threshold [2601.03156].

Prompting methods that contrast positive and negative reasoning traces are also closely related. **Contrastive Chain-of-Thought Prompting** augments each demonstration with both valid and invalid reasoning chains, formalized as
\[
E_j = (Q_j, T_{j,+}, A_{j,+}, T_{j,-}, A_{j,-})
\]
and shows consistent gains across arithmetic and factual QA [2311.09277]. **Contrastive Prompting** in zero-shot reasoning asks the model to “give a correct and a wrong answer,” then extracts the correct answer in a second stage, substantially improving performance in several reasoning benchmarks [2403.08211]. More recent prompt optimization work, such as **ContraPrompt**, treats the difference between failed and successful reasoning traces on the same input as optimization signal and organizes extracted rules into an input-aware decision tree [2604.17937]. These systems are not CPEG in name, but they show that contrastive prompting can operate over answers, rationales, exemplars, prompt subsets, or retry traces.

This broader literature suggests that the distinctive contribution of CPEG is not the abstract idea of contrast alone, but the combination of **profile-based recommendation context**, **candidate-item discrimination**, **hard-negative sampling**, and **error-aware explanation retry** [2507.06044].

## 6. Limitations, controversies, and open directions

The most explicit limitations of CPEG are methodological rather than conceptual. The method has **high computational cost** because it uses a strong reasoning model, candidate sampling, and potentially multiple retries [2507.06044]. Explanation quality is validated by whether the reasoning model selects the correct item among sampled candidates, which assumes that the candidate set is representative and that successful discrimination correlates with explanation quality [2507.06044]. The method also has **no explicit training objective for CPEG**, since it is prompt-engineered rather than trained with a formal contrastive loss [2507.06044]. Reproduction is constrained by **limited prompt specification**, and ground-truth quality is judged by GPT-3.5, which introduces **LLM-as-judge subjectivity** [2507.06044]. Finally, the prompt may include the user’s review of the interacted item, which improves supervision construction but means the synthetic explanation can depend on evidence unavailable at deployment time [2507.06044].

The wider contrastive explanation literature exposes additional open issues. In commonsense prompting, generated explanations are more relevant and helpful than non-contrastive alternatives, but fine-tuned task models can rely less on explanations than zero-shot ones, and extending contrastive prompting to more open-ended tasks remains future work [2106.06823]. In contrastive QA explanation, the gap between generated and ground-truth explanations indicates substantial remaining headroom in explanation quality and possibly faithfulness [2305.08135]. Prompt-attribution methods such as XPrompt explain counterfactual prompt-output relationships but explicitly state that the underlying generation mechanism remains a black box [2405.20404]. CELL provides contrastive evidence through prompt edits, but not polished natural-language rationales [2406.11785]. Prompt-counterfactual explanations depend on downstream classifier quality and can be computationally expensive because they require repeated stochastic generation and subset search [2601.03156].

A plausible implication is that future CPEG systems will need to combine several strands: explicit contrastive prompting, better control over hard-negative construction, stronger faithfulness tests, and more transparent conversion from contrastive evidence into human-facing explanation text. The available work already suggests a stable technical principle, however: explanations improve when they are forced to discriminate among realistic alternatives rather than merely to justify a chosen output [1811.03163; 2507.06044].

Source: https://www.emergentmind.com/topics/contrastive-prompting-for-explanation-generation-cpeg