This is the official codebase for the paper "CFX-Bench: A Benchmark for Counterfactual Explanations".
The full pipeline implemented in the repository is as follows:
To run the first three layers, namely Dataset, Generation and Evaluation, run:
python -u main.py \
--dataset german-credit \
--explainer_name dice \
--model lr \
--test_case_sel_method auto-refuseFor each argument, the options are:
datasetgerman-creditlending-clubadultcompas- More datasets can be manually added by exteding the base class
Datasetindataset.py
explainer_name: the counterfactual generation methodardicefaceniceoptbinprocearesfacegroupglanceglobe-cellm-globalllm-local- More explainers can be added by estending the base class
BaseExplainerinexplainers/base.py
model_name: the classifier to trainlr- default- More models can be added in
classifiers.py
test_case_sel_method: which factuals to selectauto-refuse: records whose positive class predicted probability is below0.5- defaultborder: records whose positive class predicted probability is between0.45and0.55neg_border: records whose positive class predicted probability is between0.45and0.50pos_border: records whose positive class predicted probability is between0.50and0.55fp: false positivesfn: false negatives- Model factual selection methods can be added in
test_case_generator.py
To verbalize the generated counterfactual explanations and evaluate LLM-based metrics, run:
python -u scripts/llm_eval.py \
--dataset german-credit \
--test_case_sel_method auto-refuse \
--explainer_name dice \
--model lr \
--llm gpt-4o-miniFor each arguments, the options are:
llmllama-3.1-8b:Llama-3.1-8B-Instruct, can run locally with the HuggingFace interfacemistral-small-3.2:Mistral-Small-3.2-24B-Instruct-2506, can run locally but needs its custom interface on top of HuggingFacegpt-4o-mini: requires API calls- More LLMs can be added
llm_clients
dataset,explainer_name,model_name,test_case_sel_method: see above.
