HyConEx: Hypernetwork classifier with counterfactual explanations for tabular data

Patryk Marszałek, Kamil Książek, Oleksii Furman, Ulvi Movsum-zada, Przemysław Spurek, Marek Śmieja · DOI

TL;DR

HyConEx is an "all-in-one" deep learning framework for tabular data that simultaneously outputs highly accurate class predictions and realistic counterfactual explanations in a single forward pass. By embedding the explanation mechanism directly into a hypernetwork architecture, it eliminates the computationally expensive, iterative post-hoc optimization loops required by traditional explainability tools.

What Problem Does This Paper Address?

While deep learning models have recently caught up to—and sometimes exceeded—gradient-boosted trees on tabular data, they remain notorious "black boxes." To trust these models in high-stakes domains like finance or medicine, we need explanations.

One of the most actionable forms of explanation is a counterfactual example: showing a user exactly how to change their features to alter the model's decision (e.g., "If your income were \$5,000 higher, your loan would be approved").

Currently, generating these counterfactuals relies on post-hoc methods. An external algorithm treats the trained classifier as a black box and runs a time-consuming optimization process for every single data point at inference time to find the minimal feature changes. This makes real-time deployment virtually impossible. The authors of HyConEx tackle this bottleneck by asking: Can we build a high-performing classifier that natively outputs its own counterfactual explanations instantly?

Comparison of HyConEx with related explainability methods

Methods

HyConEx achieves this unified prediction and explanation capability by combining two powerful architecture components: Hypernetworks and Invertible Normalizing Flows (INFs).

  1. The Hypernetwork Classifier: Instead of learning static weights, HyConEx uses a hypernetwork (built on a Tabular ResNet backbone) that takes an input sample $x$ and dynamically generates the weights $W$ for a local linear classifier tailored specifically to that sample.
  2. Instant Counterfactuals: The rows of this generated weight matrix $W$ serve a dual purpose. While one row determines the logit for the predicted class, the remaining rows act as translation vectors. To find the counterfactual candidate $x'$ for an alternative class $m$, the model simply computes $x' = x - W_m$. This happens instantly during the initial forward pass.
  3. Plausibility via Normalizing Flows: To ensure the generated counterfactuals are realistic (in-distribution) rather than weird, adversarial anomalies, the authors integrate a conditional Masked Autoregressive Flow (MAF). The INF estimates data density per class, and a dedicated "flow plausibility loss" forces the generated counterfactuals to land in high-density regions of the target class manifold.
  4. Categorical Feature Smoothing: To handle categorical variables natively without breaking the density estimation, the authors introduce a low-temperature softmax smoothing technique ($T=0.01$) on the one-hot encoded positions.

The training process is split into three distinct phases: pre-training the hypernetwork using a stable $k$-means clustering approximation for the counterfactuals, training the conditional INF on the data density, and finally fine-tuning the hypernetwork using a joint loss function that balances classification accuracy, feature proximity, and flow-based plausibility.

Illustration of HyConEx architecture

Datasets

The authors evaluated HyConEx across two distinct experimental setups:

  • Predictive Performance: Evaluated on 18 diverse tabular datasets from the OpenML repository (including benchmarks like credit-g, vehicle, blood-transfusion, and adult).
  • Counterfactual Quality: Tested across specialized datasets categorized by problem type:
  • Binary: Moons, Law, Audit, Heloc
  • Multi-class: Blobs, Digits, Wine
  • Categorical Features: Adult, Credit-A, Credit-G

Key Insights and Ideas

  • The "All-in-One" Paradigm Shift: Instead of treating explanation as an afterthought or a separate downstream task, HyConEx proves that explanation vectors can be structurally embedded into the classification weights themselves.
  • Density as a Regularizer: Without the normalizing flow component, optimizing for class flipping results in out-of-distribution, adversarial examples. The INF acts as a guide, ensuring the model alters features in a way that aligns with real-world data distributions.
Illustration of the impact of all components of the cost function
  • Overcoming the One-Hot Trap: Standard normalizing flows struggle to generate strict binary (0/1) values for categorical features. The introduction of low-temperature softmax smoothing provides a differentiable workaround that yields near-perfect validity for categorical data.

Key Results

  • Zero Efficiency Overhead: HyConEx generates counterfactuals orders of magnitude faster than competitive baselines. For example, on the Moons dataset, traditional optimization methods like Wachter's took 2,724.99 seconds to process the test set, whereas HyConEx completed the task in just 0.003 seconds.
  • Uncompromised Accuracy: A common drawback of intrinsically interpretable models is a drop in predictive power. HyConEx maintains strong performance, achieving the highest AUROC score on 5 of the 18 OpenML datasets and performing competitively with state-of-the-art black-box models like CatBoost and standard TabResNet.
Mean AUROC scores of comparative methods
  • High-Quality Explanations: Across binary, multi-class, and categorical datasets, HyConEx consistently achieved near-100% coverage and validity, while outperforming baselines on in-distribution metrics like Log Density and Local Outlier Factor (LOF).

Limitations and Future Work

Despite its strong performance, the authors note a few limitations:

  • Tabular Specificity: The architecture is strictly optimized for tabular data. Extending it to text or images would require significant architectural redesigns.
  • Single Candidate Limitation: HyConEx generates exactly one counterfactual candidate per alternative class. It cannot currently offer a diverse set of multiple distinct paths for a user to choose from.
  • Robustness to Boundary Shifts: The model does not explicitly account for how counterfactuals might change under minor perturbations to the decision boundary.

For future work, the authors suggest exploring alternative hypernetwork backbones (such as FT-Transformer or TabR) and testing other differentiable density estimation techniques to further improve performance on high-dimensional datasets.

Summary updated

BibTeX
@article{marszaek2026hyconex,
  author = {Patryk Marszałek and Kamil Książek and Oleksii Furman and Ulvi Movsum-zada and Przemysław Spurek and Marek Śmieja},
  title = {{HyConEx: Hypernetwork classifier with counterfactual explanations for tabular data}},
  journal = {Neurocomputing},
  year = {2026},
  doi = {10.1016/j.neucom.2026.132748},
}
Figure