SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2309.08395 · 2023

Learning by Self-Explaining

arXiv · PDF · Open in the Atlas

Code that ran

6 of 8 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, 1 violated it and 0 have no contract verdict; 4 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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/2309.08395.json · badge: /api/ran/2309.08395.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
ml-research/learning-by-self-explaining canonical (classifier label)
classifier basis: census
6 ran · 2 no recorded run
FunctionStatusWhere it lives
Bern Ran
ran, violated the contract we drafted
ml-research/learning-by-self-explaining/CNN-LSX/load_decoy_mnist.py
code served (permissive licence) · get_code("9817b40445c2c460")
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 bool, 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 numpy as np

def Bern(p):
    return np.random.rand() < p

# The function Bern takes a single parameter 'p' which is used in a comparison
# with a random value. It expects a scalar probability value between 0 and 1.

ARGS = {
    "p": 0.5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, 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
augment Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
ml-research/learning-by-self-explaining/CNN-LSX/load_decoy_mnist.py
code served (permissive licence) · get_code("9f058b9acf0b2d1c")
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 tuple, ndim 2, dtype family int; 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 numpy as np

# Set random seed for reproducibility
np.random.seed(0)

# Create a small image array (4x4 to match the indexing in the function)
image = np.random.randint(0, 256, size=(4, 4), dtype=np.uint8)

# Create a digit parameter
digit = 3

# Create the ARGS dictionary with all parameters
ARGS = {
    "image": image,
    "digit": digit,
    "randomize": False,
    "mult": 25,
    "all_digits": range(10)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family int — 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
compute_intra_inter Ran
ran, honoured the contract we drafted
ml-research/learning-by-self-explaining/CNN-LSX/expl_sim.py
code served (permissive licence) · get_code("c00dc736d28c1960")
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 tuple, ndim 2, 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
import numpy as np

torch.manual_seed(0)

# Build model_expl
class ExplanationModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def get_explanation_batch(self, inputs, labels):
        # Return explanations as tensors
        return self.linear(inputs)

# Build model_sim with classifier that has enc attribute
class Classifier(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
        self.enc = None
    
    def forward(self, x):
        self.enc = x  # Store encoding before final layer
        return self.linear(x)

class SimModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.classifier = Classifier()
    
    def forward(self, x):
        return self.classifier(x)

# Build loaders object with test attribute
class Loaders:
    def __init__(self):
        # Create small test batches: (inputs, labels)
        # 2 batches with batch_size=2, input_dim=4, num_classes=3
        batch1_inputs = torch.randn(2, 4)
        batch1_labels = torch.tensor([0, 1])
        batch2_inputs = torch.randn(2, 4)
        batch2_labels = torch.tensor([2, 0])
        self.test = [
            (batch1_inputs, batch1_labels),
            (batch2_inputs, batch2_labels)
        ]

# Instantiate all components
model_expl = ExplanationModel()
model_sim = SimModel()
loaders = Loaders()

ARGS = {
    "model_expl": model_expl,
    "model_sim": model_sim,
    "loaders": loaders
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, 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_expls Ran
ran; our contract draft was wrong, not the code
ml-research/learning-by-self-explaining/CNN-LSX/expl_sim_clf.py
code served (permissive licence) · get_code("3994748dd44b37f2")
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 tuple. 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
import numpy as np

torch.manual_seed(0)

class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(28 * 28, 10)
    
    def get_explanation_batch(self, inputs, labels):
        # Return a batch of explanations with shape (batch_size, 28, 28)
        batch_size = inputs.shape[0]
        explanations = torch.randn(batch_size, 28, 28)
        return explanations

class DummyLoaders:
    def __init__(self):
        self.test = [
            (torch.randn(2, 28, 28), torch.tensor([3, 7])),
            (torch.randn(2, 28, 28), torch.tensor([1, 9])),
            (torch.randn(2, 28, 28), torch.tensor([4, 2])),
        ]

model = DummyModel()
loaders = DummyLoaders()

ARGS = {
    'model': model,
    'loaders': loaders,
    'plot': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
matplotlib, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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_expls Ran
ran; our contract draft was wrong, not the code
ml-research/learning-by-self-explaining/CNN-LSX/faithful_remove.py
code served (permissive licence) · get_code("b5b46879cf057ccc")
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 tuple. 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 model with classifier and get_explanation_batch methods
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.classifier = nn.Linear(4, 3)  # 4 input features, 3 classes
    
    def get_explanation_batch(self, inputs, labels):
        # Return explanations same shape as inputs
        return torch.randn_like(inputs)

model = MinimalModel()

# Build a minimal loaders object with a test attribute
class MinimalLoaders:
    def __init__(self):
        # Create test data: list of (inputs, labels) tuples
        # inputs: batch_size=2, features=4
        # labels: batch_size=2
        self.test = [
            (torch.randn(2, 4), torch.tensor([0, 1])),
            (torch.randn(2, 4), torch.tensor([2, 0])),
        ]

loaders = MinimalLoaders()

ARGS = {
    "model": model,
    "loaders": loaders,
    "random": False,
    "background": False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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_viz_test_data Ran
ran; our contract draft was wrong, not the code
ml-research/learning-by-self-explaining/CNN-LSX/utils.py
code served (permissive licence) · get_code("01bee8dedc9a7ad7")
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 DataLoader. 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 torch.utils.data import TensorDataset, DataLoader

torch.manual_seed(0)

class MockDataset:
    def __init__(self):
        # Create mock dataset with targets and data attributes
        self.targets = torch.tensor([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2])
        self.data = torch.randn(12, 4, 3, 3)

args = {}
dataset_test = MockDataset()
batch_size = 4
n_samples = 40

ARGS = {
    "args": args,
    "dataset_test": dataset_test,
    "batch_size": batch_size,
    "n_samples": n_samples,
}
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 DataLoader — a DataLoader output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataLoader 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
compute_encs Not yet run
unverified (harvested, no recorded run)
ml-research/learning-by-self-explaining/CNN-LSX/expl_sim.py
code served (permissive licence) · get_code("dc0bfc4df0a63427")
How it ran

no invocation recorded.

download_mnist Not yet run
unverified (harvested, no recorded run)
ml-research/learning-by-self-explaining/CNN-LSX/load_decoy_mnist.py
code served (permissive licence) · get_code("640438d8e72595aa")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 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, 0 later) and 7 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
Bern 1 other paper
1 dated earlier
1703.03717 (2017-03)
Right for the Right Reasons: Training Differentiable Models by Constraining their Explanations

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-23.

Repositories linked to this paper

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

Abstract

Much of explainable AI research treats explanations as a means for model inspection. Yet, this neglects findings from human psychology that describe the benefit of self-explanations in an agent's learning process. Motivated by this, we introduce a novel workflow in the context of image classification, termed Learning by Self-Explaining (LSX). LSX utilizes aspects of self-refining AI and human-guided explanatory machine learning. The underlying idea is that a learner model, in addition to optimizing for the original predictive task, is further optimized based on explanatory feedback from an internal critic model. Intuitively, a learner's explanations are considered "useful" if the internal critic can perform the same task given these explanations. We provide an overview of important components of LSX and, based on this, perform extensive experimental evaluations via three different example instantiations. Our results indicate improvements via Learning by Self-Explaining on several levels: in terms of model generalization, reducing the influence of confounding factors, and providing more task-relevant and faithful model explanations. Overall, our work provides evidence for the potential of self-explaining within the learning phase of an AI model.

For agents

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

get_harvested_code_for_paper("2309.08395")
get_code_for_paper("2309.08395")
have("2309.08395")

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

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

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

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

Connect an agent — have() is free.