SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.07553 · ICML · 2022

CheXplaining in Style: Counterfactual Explanations for Chest X-rays using StyleGAN

Nassir Navab, Ashkan Khakzar, Matan Atad, Vitalii Dmytrenko, Yitong Li, Xinyue Zhang, Matthias Keicher, Jan Kirschke, Bene Wiestler

arXiv · PDF · Open in the Atlas

Code that ran

6 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 4 failures of our instrument; 3 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/2207.07553.json · badge: /api/ran/2207.07553.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
camp-explain-ai/style-chexplain canonical (classifier label)
classifier basis: classifier_2025
6 ran · 3 no recorded run
FunctionStatusWhere it lives
get_logits_diff Ran
ran; our contract draft was wrong, not the code
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("e98fcb728a6fc803")
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 dict. 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 torch
import torch.nn as nn

torch.manual_seed(0)

# Build a minimal generator that takes latents and returns images
class MinimalGenerator(nn.Module):
    def forward(self, latents, input_is_latent=False):
        # latents is a list with one tensor of shape [2, latent_dim]
        # Returns (images, _)
        batch_size = latents[0].shape[0]
        images = torch.randn(batch_size, 3, 32, 32)
        return images, None

# Build a minimal classifier that takes images and returns logits
class MinimalClassifier(nn.Module):
    def forward(self, images):
        # images shape: [batch_size, 3, 32, 32]
        # Returns logits of shape [batch_size, num_classes]
        batch_size = images.shape[0]
        return torch.randn(batch_size, 10)

# Create instances
generator = MinimalGenerator()
classifier = MinimalClassifier()

# Create eigenvector matrix: shape [latent_dim, nof_eigenv]
latent_dim = 8
nof_eigenv = 3
eigvec = torch.randn(latent_dim, nof_eigenv)

# Create filtered indices (subset of latent indices to process)
num_latents = 5
filterd_idx = [0, 1, 2]

# Create logits dict: logits[idx] has shape [1, num_classes]
logits = {i: torch.randn(1, 10) for i in range(num_latents)}

# Create latents dict: latents[idx] has shape [1, latent_dim]
latents = {i: torch.randn(1, latent_dim) for i in range(num_latents)}

# Create args object with required attributes
class Args:
    def __init__(self):
        self.nof_eigenv = nof_eigenv
        self.degree = 0.5
        self.device = 'cpu'

args = Args()

ARGS = {
    'generator': generator,
    'classifier': classifier,
    'eigvec': eigvec,
    'filterd_idx': filterd_idx,
    'logits': logits,
    'latents': latents,
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
get_logits_latents_prob Ran
ran on a synthesized input
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("f8131a05f211b124")
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 tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 torch
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal dataset
class MinimalDataset:
    def __init__(self, size=10):
        self.size = size
    
    def __len__(self):
        return self.size
    
    def __getitem__(self, idx):
        img = torch.randn(3, 4, 4)  # 3 channels, 4x4 spatial
        label = 0
        return img, label

# Create a minimal classifier
class MinimalClassifier(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(3 * 4 * 4, 1)
    
    def forward(self, x):
        x = x.view(x.size(0), -1)
        return self.fc(x)

# Create a minimal encoder
class MinimalEncoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(3 * 4 * 4, 512)
    
    def forward(self, x):
        x = x.view(x.size(0), -1)
        return self.fc(x)

# Create a minimal generator
class MinimalGenerator(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(512, 3 * 4 * 4)
    
    def forward(self, z_list, input_is_latent=False):
        z = z_list[0]
        img = self.fc(z)
        img = img.view(1, 3, 4, 4)
        return img, None
    
    def get_latent(self, z):
        return z

# Create args object
class Args:
    def __init__(self):
        self.n_sample = 2
        self.source = 'data'
        self.device = 'cpu'

dataset = MinimalDataset(size=10)
classifier = MinimalClassifier()
encoder = MinimalEncoder()
generator = MinimalGenerator()
args = Args()

ARGS = {
    'dataset': dataset,
    'classifier': classifier,
    'encoder': encoder,
    'generator': generator,
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
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
get_logits_means Ran
ran; our contract draft was wrong, not the code
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("b0f6e42f3e8f699d")
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 dict. 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 torch
import numpy as np

torch.manual_seed(0)

# Analyzing the function:
# - nof_eigenv: int, used in range()
# - logits_diff: dict with keys (_, eigen_idx) and values that are tuples of 2 elements
#   Each element has indexing with class_label and .item() method (torch tensor)
# - class_label: int, used to index into tensors
# - nof_images: int, used for division

nof_eigenv = 3
class_label = 1
nof_images = 2

# Construct logits_diff
# Structure: {(batch_idx, eigen_idx): (diff_pos_tensor, diff_neg_tensor)}
# Each tensor needs to be indexable by class_label and have .item() method
logits_diff = {}
for batch_idx in range(2):
    for eigen_idx in range(nof_eigenv):
        # Create tensors with shape (num_classes,) where num_classes > class_label
        diff_pos = torch.randn(4)  # 4 classes
        diff_neg = torch.randn(4)  # 4 classes
        logits_diff[(batch_idx, eigen_idx)] = (diff_pos, diff_neg)

ARGS = {
    'nof_eigenv': nof_eigenv,
    'logits_diff': logits_diff,
    'class_label': class_label,
    'nof_images': nof_images
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
get_most_significant_eigens_and_direct_in_prob Ran
ran; our contract draft was wrong, not the code
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("d32b7e035f62590c")
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 dict. 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 torch
import numpy as np
from types import SimpleNamespace

torch.manual_seed(0)

# Analyzing the function:
# - prob_means: dict that is called with .items(), values are numeric
# - args: object with attribute nof_significant_eigenv (int)
# - The function sorts prob_means by values, takes top N items
# - It prints eigenvalue, direction, and difference using tuple unpacking (eigen, sign)
# - This suggests keys are tuples like (eigen_idx, direction_str)
# - Values are numeric (floats for the "Diff" column)

prob_means = {
    (0, 'positive'): 0.95,
    (1, 'negative'): 0.87,
    (2, 'positive'): 0.76,
    (3, 'negative'): 0.62,
    (4, 'positive'): 0.45,
}

args = SimpleNamespace(
    nof_significant_eigenv=3
)

ARGS = {
    'prob_means': prob_means,
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
get_prob_means Ran
ran; our contract draft was wrong, not the code
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("d5e9ec386ae47e78")
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 dict. 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 torch
import numpy as np

torch.manual_seed(0)

# Analyzing the function:
# - nof_eigenv: int, number of eigenvalues
# - prob_diff: dict with keys (_, eigen_idx) mapping to tuples of (diff_pos, diff_neg)
#   where each diff is indexable by class_label and has .item() method (torch tensor)
# - class_label: int, index into the diff tensors
# - nof_images: int, number of images for averaging

nof_eigenv = 3
class_label = 1
nof_images = 2

# Construct prob_diff
# Keys are tuples of (something, eigen_idx), values are tuples of (diff_pos, diff_neg)
# Each diff should be a tensor that can be indexed by class_label and has .item()
prob_diff = {}
for eigen_idx in range(nof_eigenv):
    # diff_pos and diff_neg are tensors with at least class_label+1 elements
    diff_pos = torch.tensor([0.1, 0.5, 0.3, 0.2], dtype=torch.float32)
    diff_neg = torch.tensor([0.2, 0.6, 0.1, 0.4], dtype=torch.float32)
    # Key format: (image_idx, eigen_idx)
    for image_idx in range(nof_images):
        prob_diff[(image_idx, eigen_idx)] = (diff_pos, diff_neg)

ARGS = {
    'nof_eigenv': nof_eigenv,
    'prob_diff': prob_diff,
    'class_label': class_label,
    'nof_images': nof_images
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
sigmoid Ran
ran, honoured the contract we drafted
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("c27e5c071e798245")
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 float, ndim 0, dtype family float, shape () 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 math

def sigmoid(x):
    return 1 / (1 + math.exp(-x))

# The sigmoid function takes a single parameter x (a number)
# and returns 1 / (1 + e^(-x))

ARGS = {
    "x": 0.5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () 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
att_find Not yet run
unverified (harvested, no recorded run)
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("6c8aa1d59cb43aae")
How it ran

no invocation recorded.

get_most_significant_eigens_and_direct Not yet run
unverified (harvested, no recorded run)
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("0bd7e17e033664e3")
How it ran

no invocation recorded.

get_prob_diff Not yet run
unverified (harvested, no recorded run)
camp-explain-ai/style-chexplain/code/att_find_eigenvectors.py
code served (permissive licence) · get_code("8763270f14db67c5")
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, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 8 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.

FunctionAlso present inEarliest-datedOthers named
sigmoid 8 other papers
7 dated earlier, 1 later
1509.07892 (2015-09)
Evasion and Hardening of Tree Ensemble Classifiers
1510.03336 (2015-10)
Evaluating Real-time Anomaly Detection Algorithms - the Numenta Anomaly Benchmark
1902.00981 (2019-02)
Learning Counterfactual Representations for Estimating Individual Dose-Response Curves
and 5 more not named here

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

Deep learning models used in medical image analysis are prone to raising reliability concerns due to their black-box nature. To shed light on these black-box models, previous works predominantly focus on identifying the contribution of input features to the diagnosis, i.e., feature attribution. In this work, we explore counterfactual explanations to identify what patterns the models rely on for diagnosis. Specifically, we investigate the effect of changing features within chest X-rays on the classifier's output to understand its decision mechanism. We leverage a StyleGAN-based approach (StyleEx) to create counterfactual explanations for chest X-rays by manipulating specific latent directions in their latent space. In addition, we propose EigenFind to significantly reduce the computation time of generated explanations. We clinically evaluate the relevancy of our counterfactual explanations with the help of radiologists. Our code is publicly available. 1

For agents

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

get_harvested_code_for_paper("2207.07553")
get_code_for_paper("2207.07553")
have("2207.07553")

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

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

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

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

Connect an agent — have() is free.