xai-cola: A Python library for sparsifying counterfactual explanations
Organizations: Technical University of Denmark, Copenhagen, Denmark
Abstract
Counterfactual explanation (CE) is an important domain within post-hoc explainability. However, the explanations generated by most CE generators are often highly redundant. This work introduces an open-source Python library xai-cola, which provides an end-to-end pipeline for sparsifying CEs produced by arbitrary generators, reducing superfluous feature changes while preserving their validity. It offers a documented API that takes as input raw tabular data in pandas DataFrame form, a preprocessing object (for standardization and encoding), and a trained scikit-learn or PyTorch model. On this basis, users can either employ the built-in or externally imported CE generators. The library also implements several sparsification policies and includes visualization routines for analysing and comparing sparsified counterfactuals. xai-cola is released under the MIT license and can be installed from PyPI. Empirical experiments indicate that xai-cola produces sparser counterfactuals across several CE generators, reducing the number of modified features by up to 50% in our setting. The source code is available at https://github.com/understanding-ml/COLA.
Figures & tables
| CE generator | Type | Publication | German credit | COMPAS | ||
| sklearn | pytorch | sklearn | pytorch | |||
| Wachter | instance-level | Harv. JL & Tech., 2017 | — | 10.4% | — | 13.8% |
| DiCE | instance-level | FAccT, 2020 | 24.9% | 12.0% | 11.2% | 8.2% |
| GLOBE-CE | group-level | ICML, 2023 | 9.2% | 8.4% | 14.4% | 10.0% |
| DisCount | distribution-level | AISTATS, 2025 | — | 30.3% | — | 45.3% |
Explainable Artificial Intelligence
Explainable artificial intelligence develops ways to make AI decisions understandable, testable, and useful to people.
See all 326 papers