SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1910.06772 · 2019

Counterfactual diagnosis

arXiv · PDF · Open in the Atlas

Code that ran

7 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; 0 honoured the contract we drafted, 0 violated it and 7 have no contract verdict; 0 failures of our instrument; 1 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/1910.06772.json · badge: /api/ran/1910.06772.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
babylonhealth/counterfactual-diagnosis canonical (classifier label)
classifier basis: census
7 ran · 1 no recorded run
FunctionStatusWhere it lives
disease_ids Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/inference.py
code served (permissive licence) · get_code("ff64413107909f8c")
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 list, ndim 1, 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 torch

torch.manual_seed(0)

# The function iterates over network_data.items() and checks if each value
# has a 'label' key with value 'Disease'. It returns the keys (indices) where this is true.

network_data = {
    0: {'label': 'Disease', 'data': 'some_info'},
    1: {'label': 'Gene', 'data': 'other_info'},
    2: {'label': 'Disease', 'data': 'more_info'},
    3: {'label': 'Protein', 'data': 'additional_info'},
}

ARGS = {
    'network_data': network_data
}
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 list, ndim 1, dtype family int — a list 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_doctor_differential Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/helpers.py
code served (permissive licence) · get_code("8e1c8c6bb72249aa")
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 list, 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 numpy as np

def get_doctor_differential(li):
    return [val['concept']['id'] for val in li if val['concept']['id'] is not None]

# Construct valid arguments for the function
# The function expects a list of dictionaries, where each dict has a 'concept' key
# which itself is a dict with an 'id' key

ARGS = {
    'li': [
        {'concept': {'id': 'condition_001'}},
        {'concept': {'id': None}},
        {'concept': {'id': 'condition_002'}},
        {'concept': {'id': 'condition_003'}},
    ]
}
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 list, ndim 1, dtype family float — a list 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_evidence_from_casecard Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/inference.py
code served (permissive licence) · get_code("6f7d117a5495bd08")
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 list, 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 numpy as np

# Construct a valid card argument for get_evidence_from_casecard
card = {
    'card': {
        'risk_factors': [
            {
                'label': 'Risk',
                'concept': {'id': 'rf_001'},
                'presence': 'PRESENT'
            },
            {
                'label': 'Risk',
                'concept': {'id': 'rf_002'},
                'presence': 'ABSENT'
            },
            {
                'label': 'Other',
                'concept': {'id': 'rf_003'},
                'presence': 'PRESENT'
            }
        ],
        'symptoms': [
            {
                'label': 'Symptom',
                'concept': {'id': 'sym_001'},
                'severity': 'PRESENT'
            },
            {
                'label': 'Symptom',
                'concept': {'id': 'sym_002'},
                'severity': 'NOT_PRESENT'
            },
            {
                'label': 'Super',
                'concept': {'id': 'sym_003'},
                'severity': 'PRESENT'
            },
            {
                'label': 'Symptom',
                'concept': {'id': None},
                'severity': 'PRESENT'
            }
        ]
    }
}

ARGS = {
    'card': card
}
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 list, ndim 1, dtype family float — a list 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
load_from_json Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/utils.py
code served (permissive licence) · get_code("dfb7370128ac17f7")
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 json
import tempfile
import os

# Create a temporary JSON file with valid content
temp_dir = tempfile.gettempdir()
temp_filename = os.path.join(temp_dir, "test_data.json")

# Write a simple JSON file
test_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "object"}
}

with open(temp_filename, 'w') as f:
    json.dump(test_data, f)

ARGS = {
    "filename": temp_filename
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 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
load_from_pickle Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/utils.py
code served (permissive licence) · get_code("295309e250349980")
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 pickle
import tempfile
import os

# Create a temporary file and pickle some data into it
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.pkl')
temp_filename = temp_file.name
temp_file.close()

# Write some sample data to the pickle file
sample_data = {'key': 'value', 'number': 42, 'list': [1, 2, 3]}
with open(temp_filename, 'wb') as f:
    pickle.dump(sample_data, f)

ARGS = {
    'filename': temp_filename
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 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
produce_differentials Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/helpers.py
code served (permissive licence) · get_code("fe019b26bf3d5e91")
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

# Construct a valid card argument for produce_differentials
card = {
    'outcomes': [
        {
            'user': {'id': 'user_1'},
            'doctor_diseases': [
                {'concept': {'id': 'disease_1'}},
                {'concept': {'id': 'disease_2'}},
                {'concept': {'id': None}},
            ]
        },
        {
            'user': {'id': 'user_2'},
            'doctor_diseases': [
                {'concept': {'id': 'disease_3'}},
                {'concept': {'id': None}},
            ]
        },
        {
            'user': {'id': 'user_3'},
            # This outcome lacks 'doctor_diseases', so it should be skipped
        }
    ]
}

ARGS = {'card': card}
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 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
risk_factor_ids Ran
ran on a synthesized input
babylonhealth/counterfactual-diagnosis/inference.py
code served (permissive licence) · get_code("b4c2e0c2ba912c98")
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 list, ndim 1, 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 torch
import numpy as np

# Construct network_data as a dictionary where values have a 'label' key
# The function iterates through items and checks if j['label'] == 'Risk'
network_data = {
    0: {'label': 'Risk', 'data': 'node_0'},
    1: {'label': 'Normal', 'data': 'node_1'},
    2: {'label': 'Risk', 'data': 'node_2'},
    3: {'label': 'Other', 'data': 'node_3'},
    4: {'label': 'Risk', 'data': 'node_4'},
}

ARGS = {
    'network_data': network_data,
}
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 list, ndim 1, dtype family int — a list 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
write_to_pickle Not yet run
unverified (harvested, no recorded run)
babylonhealth/counterfactual-diagnosis/utils.py
code served (permissive licence) · get_code("899871c91882927a")
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, 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 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.

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

Machine learning promises to revolutionize clinical decision making and diagnosis. In medical diagnosis a doctor aims to explain a patient's symptoms by determining the diseases \emph{causing} them. However, existing diagnostic algorithms are purely associative, identifying diseases that are strongly correlated with a patients symptoms and medical history. We show that this inability to disentangle correlation from causation can result in sub-optimal or dangerous diagnoses. To overcome this, we reformulate diagnosis as a counterfactual inference task and derive new counterfactual diagnostic algorithms. We show that this approach is closer to the diagnostic reasoning of clinicians and significantly improves the accuracy and safety of the resulting diagnoses. We compare our counterfactual algorithm to the standard Bayesian diagnostic algorithm and a cohort of 44 doctors using a test set of clinical vignettes. While the Bayesian algorithm achieves an accuracy comparable to the average doctor, placing in the top 48% of doctors in our cohort, our counterfactual algorithm places in the top 25% of doctors, achieving expert clinical accuracy. This improvement is achieved simply by changing how we query our model, without requiring any additional model improvements. Our results show that counterfactual reasoning is a vital missing ingredient for applying machine learning to medical diagnosis.

For agents

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

get_harvested_code_for_paper("1910.06772")
get_code_for_paper("1910.06772")
have("1910.06772")

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

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

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

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

Connect an agent — have() is free.