SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2204.04440 · NeurIPS · 2022

Are Two Heads the Same as One? Identifying Disparate Treatment in Fair Neural Networks

Francesco Locatello, Krishnaram Kenthapadi, Michael Lohaus, Matthäus Kleindessner, Chris Russell

arXiv · PDF · Open in the Atlas

Code that ran

6 of 7 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 3 have no contract verdict; 3 failures of our instrument; 1 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/2204.04440.json · badge: /api/ran/2204.04440.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
mlohaus/disparatetreatment canonical (classifier label)
classifier basis: classifier_2025
6 ran · 1 no recorded run
FunctionStatusWhere it lives
BinaryAttributeClassifier Ran
ran on a synthesized input
mlohaus/disparatetreatment/models/attr_classifier.py
code served (permissive licence) · get_code("4db9b3a47cc1b61f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned NoneType. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 torch.optim as optim
from torch.utils.data import DataLoader, TensorDataset

# Create a minimal mock for pre_trained_nets module
class pre_trained_nets:
    @staticmethod
    def get_pre_trained_model(model_name, n_classes=1, pretrained=True, require_all_grads=False):
        # Return a simple mock model instead of real pretrained models
        class MockModel(nn.Module):
            def __init__(self, n_classes):
                super().__init__()
                self.conv = nn.Conv2d(3, 8, 3, padding=1)
                self.pool = nn.AdaptiveAvgPool2d((1, 1))
                self.fc = nn.Linear(8, n_classes)
            
            def forward(self, x):
                x = self.conv(x)
                x = self.pool(x)
                x = x.view(x.size(0), -1)
                x = self.fc(x)
                return x
        
        return MockModel(n_classes=n_classes)

# Create a minimal mock for fairness_regularizer module
class fairness_regularizer:
    @staticmethod
    def get_second_head_criterion(second_head_criterion='MSE'):
        if second_head_criterion == 'MSE':
            criterion = torch.nn.MSELoss()
        elif second_head_criterion == 'BCE':
            return torch.nn.BCEWithLogitsLoss()
        
        def my_loss(outputs, targets):
            loss = criterion(torch.sigmoid(outputs), targets)
            return loss
        return my_loss

# Create mock data loader
images = torch.randn(4, 3, 32, 32)  # batch_size=4, 3 channels, 32x32 images
targets = torch.randint(0, 2, (4, 1)).float()  # binary targets
dataset = TensorDataset(images, targets)
loader = DataLoader(dataset, batch_size=2)

INIT_ARGS = {
    'model_name': 'resnet50',
    'tuning': 'last_layer',
    'two_headed': False,
    'second_head_weight': 0.5,
    'optimizer_settings': {'learning_rate': 0.001},
    'model_path': None,
    'only_warmstart': False,
    'print_freq': 100,
    'writer': None,
    'device': 'cpu',
    'pretrained': False,
    'dtype': torch.float32
}

ARGS = {
    'loader': loader
}

METHOD = 'train'
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type NoneType — a NoneType output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a NoneType 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
MobileNet Ran
ran on a synthesized input
mlohaus/disparatetreatment/models/attr_classifier.py
code served (permissive licence) · get_code("25686bd2ea842ed8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, 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
from torchvision.models import mobilenet_v3_small, MobileNet_V3_Small_Weights

class MobileNet(nn.Module):

    def __init__(self, n_classes=1, pretrained=True, require_all_grads=False):
        super().__init__()
        if pretrained:
            self.mobilenet = mobilenet_v3_small(weights=MobileNet_V3_Small_Weights.DEFAULT)
        else:
            self.mobilenet = mobilenet_v3_small()
        for param in self.mobilenet.parameters():
            param.requires_grad = require_all_grads
        last_layer_size = self.mobilenet.classifier._modules['3'].in_features
        self.mobilenet.classifier._modules['3'] = nn.Linear(last_layer_size, n_classes)

    def forward(self, x):
        output = self.mobilenet(x)
        return output


INIT_ARGS = {
    'n_classes': 1,
    'pretrained': False,
    'require_all_grads': False,
}

ARGS = {
    'x': torch.randn(2, 3, 224, 224),
}

if __name__ == '__main__':
    model = MobileNet(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
ResNet50 Ran
ran on a synthesized input
mlohaus/disparatetreatment/models/attr_classifier.py
code served (permissive licence) · get_code("81de33cc20ad25dc")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, 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
from torchvision.models import resnet50, ResNet50_Weights

class ResNet50(nn.Module):

    def __init__(self, n_classes=1, pretrained=True, require_all_grads=False):
        super().__init__()
        if pretrained:
            self.resnet = resnet50(weights=ResNet50_Weights.DEFAULT)
        else:
            self.resnet = resnet50(weights=None)
        for param in self.resnet.parameters():
            param.requires_grad = require_all_grads
        last_layer_size = self.resnet.fc.in_features
        self.resnet.fc = nn.Linear(last_layer_size, n_classes)

    def forward(self, x):
        output = self.resnet(x)
        return output


INIT_ARGS = {
    'n_classes': 2,
    'pretrained': False,
    'require_all_grads': False,
}

ARGS = {
    'x': torch.randn(2, 3, 224, 224),
}

if __name__ == '__main__':
    model = ResNet50(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: torch.Size([2, 2])")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
get_second_head_criterion Ran
ran; our contract draft was wrong, not the code
mlohaus/disparatetreatment/models/attr_classifier.py
code served (permissive licence) · get_code("96928a119f074402")
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 function. 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

torch.manual_seed(0)

ARGS = {
    'second_head_criterion': 'MSE'
}
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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
learn_fair_classifier_via_grid_search Ran
ran; our contract draft was wrong, not the code
mlohaus/disparatetreatment/explicit_approaches/grid_search_two_heads.py
code served (permissive licence) · get_code("2df091cf978595e8")
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 numpy as np

# Create small synthetic data
np.random.seed(0)

# y_score: shape (n_samples, 2) - scores for the classifier
# Column 0: main score, Column 1: sensitive feature score
n_samples = 10
y_score = np.random.randn(n_samples, 2)

# y_true: shape (n_samples, 2)
# Column 0: true labels (0 or 1)
# Column 1: sensitive features (0 or 1, representing two groups)
labels = np.random.randint(0, 2, n_samples)
sensitive_features = np.random.randint(0, 2, n_samples)
y_true = np.column_stack([labels, sensitive_features])

# fairness_parameter: maximum allowed fairness violation (difference in prediction rates)
fairness_parameter = 0.3

# Optional grid parameters with defaults
grid_range_b = (-10, 10)
grid_size_b = 101
grid_range_c = (-10, 10)
grid_size_c = 101

ARGS = {
    "y_score": y_score,
    "y_true": y_true,
    "fairness_parameter": fairness_parameter,
    "grid_range_b": grid_range_b,
    "grid_size_b": grid_size_b,
    "grid_range_c": grid_range_c,
    "grid_size_c": grid_size_c,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 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
learn_fair_classifier_via_grid_search_RECURSIVE Ran
ran; our contract draft was wrong, not the code
mlohaus/disparatetreatment/explicit_approaches/grid_search_two_heads.py
code served (permissive licence) · get_code("048a899f89fc0b58")
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 numpy as np

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

# Create synthetic data
# y_score: shape (n_samples, 2) - scores for the classifier
# y_true: shape (n_samples, 2) - first column is labels, second column is sensitive features
n_samples = 50

# Generate y_score with 2 features
y_score = np.random.randn(n_samples, 2)

# Generate y_true: labels (0 or 1) and sensitive features (0 or 1)
labels = np.random.randint(0, 2, n_samples)
sensitive_features = np.random.randint(0, 2, n_samples)
y_true = np.column_stack([labels, sensitive_features])

# Fairness parameter - tolerance for fairness violation
fairness_parameter = 0.2

# Define arguments for learn_fair_classifier_via_grid_search_RECURSIVE
ARGS = {
    'y_score': y_score,
    'y_true': y_true,
    'fairness_parameter': fairness_parameter,
    'grid_range_b': (-15, 15),
    'grid_range_c': (-15, 15),
    'grid_size': 200,
    'nr_of_recursions': 4
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 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_pre_trained_model Not yet run
unverified (harvested, no recorded run)
mlohaus/disparatetreatment/models/attr_classifier.py
code served (permissive licence) · get_code("54ac9bd0894bea5d")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 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 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.

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

We show that deep networks trained to satisfy demographic parity often do so through a form of race or gender awareness, and that the more we force a network to be fair, the more accurately we can recover race or gender from the internal state of the network. Based on this observation, we investigate an alternative fairness approach: we add a second classification head to the network to explicitly predict the protected attribute (such as race or gender) alongside the original task. After training the two-headed network, we enforce demographic parity by merging the two heads, creating a network with the same architecture as the original network. We establish a close relationship between existing approaches and our approach by showing (1) that the decisions of a fair classifier are well-approximated by our approach, and (2) that an unfair and optimally accurate classifier can be recovered from a fair classifier and our second head predicting the protected attribute. We use our explicit formulation to argue that the existing fairness approaches, just as ours, demonstrate disparate treatment and that they are likely to be unlawful in a wide range of scenarios under US law.

For agents

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

get_harvested_code_for_paper("2204.04440")
get_code_for_paper("2204.04440")
have("2204.04440")

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

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

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

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

Connect an agent — have() is free.