Main API
CounterfactualTraining.jl can be used with deep learning models from the FluxML ecosystem.
Teaching Models Plausible and Actionable Explanations using Taija’s new package CounterfactualTraining.jl
Delft University of Technology
2026-03-23
Taija hosts research software geared towards Trustworthy Artificial Intelligence in Julia. Developed during my PhD.
Tweaking Parameters
Objective:
\[ \begin{aligned} \min_{\textcolor{orange}{\theta}} \{ {\text{yloss}(M_{\theta}(\mathbf{x}),\mathbf{y})} \} \end{aligned} \]
Tweaking Parameters ::: {.columns} ::: {.column width=75%} Objective:
\[ \begin{aligned} \min_{\textcolor{orange}{\theta}} \{ {\text{yloss}(M_{\theta}(\mathbf{x}),\mathbf{y})} \} \end{aligned} \]
Solution:
\[ \begin{aligned} \theta_{t+1} &= \theta_t - \nabla_{\textcolor{orange}{\theta}} \{ {\text{yloss}(M_{\theta}(\mathbf{x}),\mathbf{y})} \} \\ \textcolor{orange}{\theta^*}&=\theta_T \end{aligned} \] ::: ::: {.column width=25%}
::: :::
Tweaking Inputs–CounterfactualExplanations.jl
Tweaking Inputs–CounterfactualExplanations.jl
Objective:
\[ \begin{aligned} \min_{\textcolor{purple}{\mathbf{x}}} \{ {\text{yloss}(M_{\textcolor{orange}{\theta^*}}(\mathbf{x}),\mathbf{y^{\textcolor{purple}{+}} }) + \lambda \text{reg}(\mathbf{x};\cdot)} \} \end{aligned} \]
Solution:
\[ \begin{aligned} \mathbf{x}_{t+1} &= \mathbf{x}_t - \nabla_{\textcolor{purple}{\mathbf{x}}} \{ \text{yloss}(M_{\textcolor{orange}{\theta^*}}(\mathbf{x}),\mathbf{y^{\textcolor{purple}{+}} }) \\&+ \lambda \text{reg}(\mathbf{x};\cdot) \} \\ \textcolor{purple}{\mathbf{x}^*}&=\mathbf{x}_T \end{aligned} \]
All of these counterfactuals are valid explanations for the model’s prediction.
Pick your poison …
First, Tweaking Inputs1
\[ \begin{aligned} \mathbf{x}_{t+1} &= \mathbf{x}_t - \nabla_{\textcolor{purple}{\mathbf{x}}} \{ {ECCCo(M_{\textcolor{orange}{\theta^*}}(\mathbf{x}),\mathbf{y^{\textcolor{purple}{+}} })} \} \\ \textcolor{purple}{\mathbf{x}^*}&=\mathbf{x}_T \end{aligned} \]
Then, Tweaking Parameters
\[ \begin{aligned} \theta_{t+1} &= \theta_t - \nabla_{\textcolor{orange}{\theta}} \{ {\text{yloss}(M_{\theta}(\mathbf{x}),\mathbf{y})} + \text{div}(\textcolor{purple}{\mathbf{x}^*},\mathbf{x}^+,y^+; \theta) \} \\ \textcolor{orange}{\theta^*}&=\theta_T \end{aligned} \]
CounterfactualTraining.jl can be used with deep learning models from the FluxML ecosystem.
| Pros | Cons |
|---|---|
| ✅ Access to comprehensive CE.jl generator suite | ❌ Bottlenecked by CE.jl performance |
| ✅ Viable alternative for GPU-poor | ❌ Large models |
| ✅ Generate CEs in parallel | ❌ Generate CEs on GPU |
NativeGenerator: GPU-friendly re-implementation of CE.jl’s ECCoGenerator.counterfactual_training to (1) generate counterfactuals on GPU, (2) train model on GPU.ResNet for MNIST anyone? New branch supports large neural networks (even when you don’t need them).
Taija was my PhD project. Unfortunately, I am more constrained these days 😔