DiCE (Diverse Counterfactual Explanations) is an algorithmic framework that generates a set of counterfactual instances—hypothetical input variations—that are both diverse and actionable, showing a user multiple distinct ways to flip a machine learning model's prediction. Unlike single counterfactual methods, DiCE optimizes for a trade-off between proximity to the original input and diversity among the generated alternatives, ensuring the explanations are not redundant.
Glossary
DiCE (Diverse Counterfactual Explanations)

What is DiCE (Diverse Counterfactual Explanations)?
DiCE is a framework for generating multiple, diverse counterfactual explanations that show distinct ways to change input features to achieve a desired model prediction.
The framework formalizes diversity through a determinantal point process (DPP) that maximizes the spread of proposed changes in feature space. By exposing multiple causal pathways—such as increasing income or changing marital status to secure loan approval—DiCE provides a more robust understanding of the model's decision boundary, addressing the critical limitation of single-explanation methods that may suggest impractical or biased recourse.
Key Features of DiCE
DiCE generates multiple, distinct counterfactual scenarios to explain model decisions, ensuring users understand not just one path to a desired outcome, but a diverse set of actionable alternatives.
Diversity via Determinantal Point Processes
DiCE uses Determinantal Point Processes (DPP) to enforce diversity among generated counterfactuals. A DPP models the probability of selecting a subset of diverse items, ensuring the explanations are not just minor variations of each other. This avoids redundant suggestions like 'increase income by $100' and 'increase income by $101', instead offering fundamentally different paths such as 'change job type' or 'reduce loan amount'. The diversity metric is explicitly optimized alongside proximity to the original input.
Proximity and Feasibility Constraints
The optimization objective balances three competing goals:
- Proximity: The counterfactual should be as close as possible to the original input feature vector, minimizing the cost of change.
- Diversity: The set of counterfactuals must be distinct from one another.
- Feasibility: Changes must respect causal constraints and immutable features (e.g., one cannot decrease their age). DiCE integrates a causal model to ensure that intervening on a feature like 'education level' correctly updates downstream features like 'years of study'.
Model-Agnostic and Gradient-Based Access
DiCE is primarily designed for differentiable models where gradient descent can be applied directly to the input space to find counterfactuals. For non-differentiable black-box models, DiCE can operate by building a local surrogate model or using genetic algorithms. The core framework is model-agnostic in principle, though the native implementation leverages TensorFlow or PyTorch backends for efficient gradient computation on deep neural networks.
Causal Graph Integration
A critical feature is the ability to accept a structural causal model (SCM) as input. Without a causal graph, a counterfactual might suggest an impossible or illogical change (e.g., changing 'number of pregnancies' for a male applicant). By encoding parent-child relationships, DiCE ensures that when a feature is altered, its downstream effects are propagated correctly, generating actionable and realistic explanations that respect the data-generating process.
Quantitative Evaluation Metrics
DiCE provides specific metrics to evaluate the quality of generated explanations:
- Diversity: Average pairwise distance between counterfactuals.
- Proximity: Mean distance from counterfactuals to the original query point (often using L1 or L2 norm).
- Feasibility: A score measuring how many counterfactuals violate known causal constraints or fall outside the data manifold.
- Sparsity: The average number of features changed per counterfactual.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear, technical answers to the most common questions about generating and applying DiCE for model interpretability and actionable recourse.
DiCE (Diverse Counterfactual Explanations) is a model-agnostic method for generating a set of distinct counterfactual examples that show multiple, realistic ways a user can change their input features to flip a machine learning model's prediction to a desired outcome. Unlike single counterfactual methods, DiCE explicitly optimizes for diversity alongside proximity and feasibility.
The algorithm works by solving a constrained optimization problem with a loss function that has three components:
- Proximity loss: Minimizes the distance between the original input and the counterfactual, ensuring minimal change.
- Diversity loss: Uses a determinantal point process (DPP) or a simple distance metric to enforce that generated counterfactuals are distinct from one another.
- Feasibility loss: Penalizes changes that violate causal constraints or domain-specific rules (e.g., age cannot decrease).
DiCE can operate in a gradient-based mode for differentiable models like neural networks, or a genetic algorithm mode for non-differentiable models like tree ensembles. The output is a ranked list of actionable "what-if" scenarios, such as "If your income increased by $5,000 AND your loan term decreased by 12 months, the loan would be approved."
Related Terms
DiCE operates within a broader landscape of interpretability techniques. These related concepts provide alternative or complementary approaches to understanding model behavior.
Feasibility Constraints in Counterfactuals
A critical extension to basic counterfactual generation that ensures recommended changes are actionable in the real world. Unconstrained DiCE might suggest 'decrease your age by 10 years'—an immutable feature. Feasibility-aware methods incorporate:
- Immutability constraints: features like age or race cannot change
- Causal constraints: changing 'education level' may require changing 'years of schooling' first
- Domain-specific rules: a credit score cannot jump 200 points in one month These constraints transform counterfactuals from mathematical artifacts into practical recourse.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us