Contrastive explanation

On this page 7

A contrastive explanation is an account of a model decision that answers the question “why P rather than Q?”, where P is the actual output, called the fact, and Q is a specific alternative, called the foil. In explainable AI, it identifies the features or evidence that distinguish the observed prediction from the foil, instead of listing every factor that contributed to the prediction in general.

The approach rests on a well-established finding from philosophy and cognitive science: people rarely ask why something happened in absolute terms, but why it happened instead of something else. A loan applicant does not want a ranked list of all 40 model inputs; the applicant wants to know what separated a rejection from an approval. Contrastive methods therefore tend to produce shorter, more selective explanations that match how humans reason about causes.

How contrastive explanations work

Every contrastive explanation starts by fixing a fact and a foil. The foil may be chosen by the user, such as an alternative class in a classifier, or inferred automatically, typically as the second most likely class or the decision that a user expected. The explanation then reports the difference condition: the attributes present for the fact and absent for the foil, or vice versa.

Technically, most methods solve a constrained optimization problem. They search for the smallest change to the input, or the smallest subset of evidence, that would flip the output from the fact to the foil. The size of that change is measured with a distance function, often the L1 norm to encourage sparse answers that involve only a few features.

The table below lists the components that any contrastive method must define, explicitly or implicitly.

ComponentMeaningTypical choice
FactThe output the model actually producedPredicted class or score
FoilThe alternative the explanation contrasts againstUser-chosen or second-ranked class
Difference conditionEvidence that separates fact from foilSmall set of features or regions
Distance measureHow large a change is consideredL1 or L2 norm, feature costs
ConstraintsRules on allowed changesPlausibility, immutable features
Components of a contrastive explanation

Main methods and variants

Several families of techniques produce contrastive explanations, and they differ in what they return. Counterfactual explanations describe a modified input that leads to the foil, while the Contrastive Explanations Method (CEM) returns pertinent positives that must be present to keep the fact and pertinent negatives whose absence matters for it.

Method familyOutputTypical data
Counterfactual searchNearest input that receives the foilTabular decisions such as credit
Diverse counterfactualsSeveral distinct paths to the foilRecourse for individuals
Contrastive Explanations MethodPertinent positives and negativesImages and tabular data
Contrastive saliency mapsRegions supporting fact over foilImage classifiers
Contrastive text explanationsTokens that favor one labelLanguage models and classifiers
Families of contrastive methods

Gradient-based variants compute attribution for the difference between two logits rather than for a single class score. This simple change turns a standard saliency map into a contrastive one, highlighting what makes an image look like a husky rather than a wolf instead of what makes it look like a dog at all.

Contrastive explanation is a framing of the question, not a single algorithm, so it overlaps with neighboring explanation types. Feature attribution methods such as Shapley values explain a prediction relative to a baseline or average, which is an implicit foil that users rarely notice.

Explanation typeQuestion answeredImplicit reference point
Contrastive explanationWhy P rather than QExplicit foil Q
Feature attributionHow much each feature contributedBaseline or average prediction
Counterfactual explanationWhat change would alter the outcomeDesired outcome
Example-based explanationWhich cases resemble this oneTraining examples
Global explanationHow the model behaves overallWhole data distribution
How contrastive explanations differ from other explanation types

Counterfactual explanations are best seen as a subset of contrastive explanations in which the foil is a desired outcome. Making the foil explicit also exposes a weakness of attribution methods: changing the baseline can change the explanation substantially, which a contrastive formulation states openly.

Practical use and design choices

Contrastive explanations are most valuable where a person must act on or contest a decision. Credit, insurance, hiring and medical triage are typical cases, and adverse action notices in lending already require lenders to state the principal reasons for a denial, which naturally takes a contrastive form.

  • Choose the foil deliberately: the expected or desired outcome is usually more useful than the runner-up class.
  • Mark immutable features such as age or birthplace so that explanations do not suggest impossible changes.
  • Assign feature costs so that suggested changes reflect real effort, not only numerical distance.
  • Keep explanations sparse, typically two to four features, because longer answers lose the contrastive benefit.

Limitations and risks

The quality of a contrastive explanation depends heavily on the foil and the constraints, and poor choices produce answers that are technically correct but useless or misleading. Because many models fit the same data equally well, the Rashomon effect also means that different models may justify the same decision with different contrasts.

ProblemCauseMitigation
Implausible suggestionsSearch leaves the data manifoldAdd density or plausibility constraints
Unactionable adviceImmutable features allowed to changeFreeze protected and fixed attributes
Unstable explanationsSmall input changes alter the resultTest robustness across neighbors
Unfaithful contrastApproximation differs from the modelVerify that the foil is truly reached
Model extraction riskMany counterfactuals reveal boundariesLimit queries and detail per user
Common failure modes

Contrastive explanations also do not establish causality in the real world. They describe what flips the model, not what would change the underlying outcome, and treating them as causal guidance can lead people to game proxy features without improving the property the model was meant to measure.

Understanding it simply

People rarely ask why something happened in general. They ask why it happened instead of something else. Why did the train leave late and not on time? Why was the loan refused and not approved?

A contrastive explanation answers that kind of question for a computer model. It points to the few differences that mattered. A short answer such as “your income was slightly too low for approval” is far more useful than a long list of every factor the system considered.

Applied in practice

A regional bank uses a gradient boosting model to screen small business loans. An applicant with annual revenue of 180,000 dollars and a debt-to-income ratio of 46 percent is refused. The bank’s explanation service sets the foil to approval and searches for the smallest realistic change, with company age and industry marked as immutable.

The service returns two contrasts: reducing the debt-to-income ratio to 38 percent, or adding six more months of positive cash flow history. The loan officer shares the first option in the denial notice. Eight months later, the applicant pays down a credit line, reapplies and is approved, and the bank records the case as successful recourse in its fairness monitoring report.