SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2305.11997 · ICML · 2023

Robust Counterfactual Explanations for Neural Networks With Probabilistic Guarantees

Sanghamitra Dutta, Saumitra Mishra, Daniele Magazzeni, Faisal Hamman, Erfaun Noorani

arXiv · PDF · Open in the Atlas

Code that ran

7 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 1 violated it and 1 has no contract verdict; 3 failures of our instrument; 2 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2305.11997.json · badge: /api/ran/2305.11997.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
faisalhamman/trex-counterfactuals canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FaisalHamman/TReX-Counterfactuals marked official in Papers with Code
Papers with Code archive
6 ran · 2 no recorded run
FunctionStatusWhere it lives
StableNeighborSearch Ran
ran on a synthesized input · constructed an object; no result was computed
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("f1d41520cefa2f03")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, StableNeighborSearch: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tensorflow as tf
import numpy as np

# Create a minimal TensorFlow model that satisfies the function's requirements
class SimpleClassifier(tf.keras.Model):
    def __init__(self, num_classes=2, input_dim=4):
        super(SimpleClassifier, self).__init__()
        self.dense1 = tf.keras.layers.Dense(8, activation='relu')
        self.dense2 = tf.keras.layers.Dense(num_classes)
    
    def call(self, x, training=False):
        x = self.dense1(x)
        x = self.dense2(x)
        return x

# Initialize model
model = SimpleClassifier(num_classes=2, input_dim=4)

# Create dummy input to build the model
dummy_input = np.random.randn(2, 4).astype(np.float32)
model(dummy_input)

ARGS = {
    'model': model,
    'clamp': [0.0, 1.0],
    'num_classes': 2,
    'sns_eps': 0.3,
    'sns_nb_iters': 100,
    'sns_eps_iter': 0.001,
    'n_interpolations': 20,
    'batch_size': 32
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type StableNeighborSearch — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a StableNeighborSearch output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
clip_with_clamp Ran
ran, violated the contract we drafted
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("4d4615a7744c5f0b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned EagerTensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tensorflow as tf
import numpy as np

# Create a small delta tensor (batch size 2, dimension 4)
delta = tf.constant([[1.5, -0.5, 2.0, -1.0],
                     [0.3, 1.2, -2.5, 0.8]], dtype=tf.float32)

# Create clamp bounds as floats
clamp = [0.0, 1.0]

ARGS = {
    "delta": delta,
    "clamp": clamp
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
find_k_neighbors Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
faisalhamman/trex-counterfactuals/baselines.py
code served (permissive licence) · get_code("fa92ac9ae7819d87")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned ndarray, ndim 2, dtype family int, shape (1, 2) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from sklearn.neighbors import NearestNeighbors

np.random.seed(0)

# Create a small dataset: 5 points in 4-dimensional space
dataset = np.random.rand(5, 4).astype(np.float32)

# Create a single datapoint to query: 1 point in 4-dimensional space
datapoint = np.random.rand(1, 4).astype(np.float32)

# Set k to 2 (find 2 nearest neighbors)
k = 2

ARGS = {
    "dataset": dataset,
    "datapoint": datapoint,
    "k": k
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, sklearn — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family int, shape (1, 2) — shape (1, 2) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
l2_norm Ran
ran, honoured the contract we drafted
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("b7f8b80927ae3ce4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned EagerTensor, ndim 2, dtype family float, shape (2, 1) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tensorflow as tf
import numpy as np

# Create a small tensor for the l2_norm function
# The function expects a tensor and computes L2 norm along the last axis
x = tf.constant(np.random.randn(2, 4).astype(np.float32))

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family float, shape (2, 1) — shape (2, 1) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
linear_integral Ran
ran; our contract draft was wrong, not the code
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("8b9d457986deacbd")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned EagerTensor, ndim 2, dtype family float, shape (50, 2) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import tensorflow as tf

# Create a simple model that takes input and returns logits
class SimpleModel(tf.Module):
    def __init__(self):
        super().__init__()
        self.dense1 = tf.keras.layers.Dense(8)
        self.dense2 = tf.keras.layers.Dense(2)
    
    def __call__(self, x, training=False):
        x = self.dense1(x)
        x = self.dense2(x)
        return x

# Create model instance
model = SimpleModel()

# Create small test tensors
batch_size = 2
feature_dim = 4
num_class = 2

x = tf.constant(np.random.randn(batch_size, feature_dim).astype(np.float32))
y = tf.constant([0, 1], dtype=tf.int64)

ARGS = {
    "model": model,
    "x": x,
    "y": y,
    "res": 50,
    "num_class": num_class
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family float, shape (50, 2) — shape (50, 2) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
unit_vector Ran
ran, honoured the contract we drafted
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("1b2bcf5bb57b781b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned EagerTensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tensorflow as tf
import numpy as np

# Create a small tensor to test the unit_vector function
# Using shape (2, 4) - batch size 2, feature dimension 4
x = tf.constant(np.random.randn(2, 4).astype(np.float32))

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
update_delta Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("5c9de896d6de458d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned EagerTensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import tensorflow as tf

# Create small test tensors
batch_size = 2
input_dim = 4

# x: original input tensor (batch_size, input_dim)
x = tf.constant(np.random.randn(batch_size, input_dim), dtype=tf.float32)

# delta: perturbation tensor (batch_size, input_dim)
delta = tf.constant(np.random.randn(batch_size, input_dim) * 0.01, dtype=tf.float32)

# grad: gradient tensor (batch_size, input_dim)
grad = tf.constant(np.random.randn(batch_size, input_dim), dtype=tf.float32)

# step_size: learning rate for the update
step_size = 0.01

# epsilon: perturbation budget
epsilon = 0.3

# p: norm type (can be 1, 2, or np.inf)
p = 2

# clamp: tuple of (min_value, max_value) for clipping
clamp = (0.0, 1.0)

ARGS = {
    "x": x,
    "delta": delta,
    "grad": grad,
    "step_size": step_size,
    "epsilon": epsilon,
    "p": p,
    "clamp": clamp
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
SNS Not yet run
unverified (harvested, no recorded run)
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("557503066f0101f5")
How it ran

no invocation recorded.

batch_sns_search Not yet run
unverified (harvested, no recorded run)
FaisalHamman/TReX-Counterfactuals/consistency/attack_methods.py
code served (permissive licence) · get_code("fd9a4033f6f32ccd")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

There is an emerging interest in generating robust counterfactual explanations that would remain valid if the model is updated or changed even slightly. Towards finding robust counterfactuals, existing literature often assumes that the original model m and the new model M are bounded in the parameter space, i.e., ∥Params(M )-Params(m)∥<∆. However, models can often change significantly in the parameter space with little to no change in their predictions or accuracy on the given dataset. In this work, we introduce a mathematical abstraction termed naturally-occurring model change, which allows for arbitrary changes in the parameter space such that the change in predictions on points that lie on the data manifold is limited. Next, we propose a measure -that we call Stability -to quantify the robustness of counterfactuals to potential model changes for differentiable models, e.g., neural networks. Our main contribution is to show that counterfactuals with sufficiently high value of Stability as defined by our measure will remain valid after potential "naturally-occurring" model changes with high probability (leveraging concentration bounds for Lipschitz function of independent Gaussians). Since our quantification depends on the local Lipschitz constant around a data point which is not always available, we also examine practical relaxations of our proposed measure and demonstrate experimentally how they can be incorporated to find robust counterfactuals for neural networks that are close, realistic, and remain valid after potential model changes 1 . This work also has interesting connections with model multiplicity, also known as, the Rashomon effect.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2305.11997")
get_code_for_paper("2305.11997")
have("2305.11997")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2305.11997.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2305.11997.svg)](https://syntology.ai/paper/2305.11997)

Connect an agent — have() is free.