SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2004.14992 · EMNLP · 2020

How do Decisions Emerge across Layers in Neural Models? Interpretation with Differentiable Masking

Wilker Aziz, Nicola De Cao, Michael Schlichtkrull, Ivan Titov

arXiv · PDF · Open in the Atlas

Code that ran

6 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (4 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 0 failures of our instrument; 4 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/2004.14992.json · badge: /api/ran/2004.14992.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
nicola-decao/diffmask marked official in Papers with Code
Papers with Code archive
4 ran · 1 no recorded run
angelosnal/vision-diffmask community
Papers with Code archive
2 ran · 3 no recorded run
FunctionStatusWhere it lives
BinaryConcrete Ran
ran on a synthesized input · constructed an object; no result was computed
nicola-decao/diffmask/diffmask/models/gates.py
code served (permissive licence) · get_code("9d22095a17af9672")
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, BinaryConcrete: 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 torch
import torch.nn as nn

torch.manual_seed(0)

# BinaryConcrete expects:
# - temperature: a tensor (scalar or batch) with a .device attribute
# - logits: a tensor (scalar or batch) with shape compatible for broadcasting

temperature = torch.tensor(0.5, dtype=torch.float32)
logits = torch.randn(2, 4, dtype=torch.float32)

ARGS = {
    "temperature": temperature,
    "logits": logits,
}
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 BinaryConcrete — 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 BinaryConcrete 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
BinaryConcrete Ran
ran on a synthesized input
angelosnal/vision-diffmask/code/models/gates.py
code served (permissive licence) · get_code("6a5a019aa6eb2889")
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, 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 torch
import torch.distributions as distr

class BinaryConcrete(distr.relaxed_bernoulli.RelaxedBernoulli):

    def __init__(self, temperature: torch.Tensor, logits: torch.Tensor):
        super().__init__(temperature=temperature, logits=logits)
        self.device = self.temperature.device

    def cdf(self, value: torch.Tensor) -> torch.Tensor:
        return torch.sigmoid((torch.log(value) - torch.log(1.0 - value)) * self.temperature - self.logits)

    def log_prob(self, value: torch.Tensor) -> torch.Tensor:
        return torch.where((value > 0) & (value < 1), super().log_prob(value), torch.full_like(value, -float('inf')))

    def log_expected_L0(self, value: torch.Tensor) -> torch.Tensor:
        import torch.nn.functional as F
        return -F.softplus((torch.log(value) - torch.log(1 - value)) * self.temperature - self.logits)


INIT_ARGS = {
    'temperature': torch.tensor(0.5),
    'logits': torch.randn(2, 4)
}

ARGS = {
    'value': torch.rand(2, 4) * 0.8 + 0.1
}

METHOD = 'log_expected_L0'

if __name__ == '__main__':
    dist = BinaryConcrete(**INIT_ARGS)
    result = getattr(dist, METHOD)(**ARGS)
    print(result)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — 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, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
DiffMaskGateInput Ran
ran on a synthesized input · constructed an object; no result was computed
nicola-decao/diffmask/diffmask/models/gates.py
code served (permissive licence) · get_code("42f456f21c831412")
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, DiffMaskGateInput: 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 torch
import torch.nn as nn

torch.manual_seed(0)

# Build a minimal gate_fn that matches MLPMaxGate's interface
class MinimalGate(nn.Module):
    def __init__(self, input_size, hidden_size, bias=True):
        super().__init__()
        self.linear = nn.Linear(input_size, 1, bias=bias)
    
    def forward(self, *args):
        x = torch.cat(args, -1)
        return self.linear(x)

# Parameters for DiffMaskGateInput
hidden_size = 4
hidden_attention = 3
num_hidden_layers = 2
max_position_embeddings = 5
batch_size = 2
seq_len = 5

# Create hidden_states: list of tensors, each [batch, seq, hidden_size]
hidden_states = [
    torch.randn(batch_size, seq_len, hidden_size),
    torch.randn(batch_size, seq_len, hidden_size),
    torch.randn(batch_size, seq_len, hidden_size),
]

# Create mask (though not used in forward, can be any shape)
mask = torch.ones(batch_size, seq_len, dtype=torch.bool)

# layer_pred can be None or an integer
layer_pred = None

# Create gate_fn class
gate_fn = MinimalGate

ARGS = {
    'hidden_size': hidden_size,
    'hidden_attention': hidden_attention,
    'num_hidden_layers': num_hidden_layers,
    'max_position_embeddings': max_position_embeddings,
    'gate_fn': gate_fn,
    'gate_bias': True,
    'placeholder': False,
    'init_vector': None,
}
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 DiffMaskGateInput — 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 DiffMaskGateInput 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
MLPMaxGate Ran
ran on a synthesized input · constructed an object; no result was computed
nicola-decao/diffmask/diffmask/models/gates.py
code served (permissive licence) · get_code("6c897bca72237121")
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, MLPMaxGate: 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 torch

torch.manual_seed(0)

ARGS = {
    'input_size': 4,
    'hidden_size': 3,
    'max_activation': 10,
    'bias': True,
}
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 MLPMaxGate — 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 MLPMaxGate 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
RectifiedStreched Ran
ran on a synthesized input
angelosnal/vision-diffmask/code/models/gates.py
code served (permissive licence) · get_code("1812ba7431095707")
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 1, dtype family float, shape (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 torch
from torch import Tensor
import torch.distributions as distr

class Streched(distr.TransformedDistribution):

    def __init__(self, base_dist, l: float=-0.1, r: float=1.1):
        super().__init__(base_dist, distr.AffineTransform(loc=l, scale=r - l))

    def log_expected_L0(self) -> Tensor:
        value = torch.tensor(0.0, device=self.base_dist.device)
        for transform in self.transforms[::-1]:
            value = transform.inv(value)
        if self._validate_args:
            self.base_dist._validate_sample(value)
        value = self.base_dist.log_expected_L0(value)
        value = self._monotonize_cdf(value)
        return value

    def expected_L0(self) -> Tensor:
        return self.log_expected_L0().exp()

class RectifiedStreched(Streched):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    @torch.no_grad()
    def sample(self, sample_shape: torch.Size=torch.Size([])) -> Tensor:
        return self.rsample(sample_shape)

    def rsample(self, sample_shape: torch.Size=torch.Size([])) -> Tensor:
        x = super().rsample(sample_shape)
        return x.clamp(0, 1)


base_distribution = distr.Normal(loc=0.5, scale=0.3)

INIT_ARGS = {
    'base_dist': base_distribution,
    'l': -0.1,
    'r': 1.1
}

ARGS = {
    'sample_shape': torch.Size([2])
}

METHOD = 'rsample'

instance = RectifiedStreched(**INIT_ARGS)
result = getattr(instance, METHOD)(**ARGS)
print(result)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (2,) — shape (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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
Streched Ran
ran on a synthesized input · constructed an object; no result was computed
nicola-decao/diffmask/diffmask/models/gates.py
code served (permissive licence) · get_code("121b859bf1d3c812")
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, Streched: 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 torch
import torch.distributions as dist

torch.manual_seed(0)

# Create a base distribution that has the required methods and attributes
class CustomBaseDistribution(dist.Normal):
    def __init__(self):
        super().__init__(loc=torch.tensor(0.0), scale=torch.tensor(1.0))
    
    def log_expected_L0(self, value):
        # This method is called in the body, needs to return a tensor
        return torch.tensor(0.5, device=self.device)
    
    @property
    def device(self):
        return self.loc.device

# Create the base distribution
base_dist = CustomBaseDistribution()

# Define arguments for Streched
ARGS = {
    'base_dist': base_dist,
    'l': -0.1,
    'r': 1.1
}
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 Streched — 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 Streched 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
DiffMaskGateInput Not yet run
unverified (harvested, no recorded run)
angelosnal/vision-diffmask/code/models/gates.py
code served (permissive licence) · get_code("ff21479d516498d0")
How it ran

no invocation recorded.

MLPMaxGate Not yet run
unverified (harvested, no recorded run)
angelosnal/vision-diffmask/code/models/gates.py
code served (permissive licence) · get_code("746bf702c11c94f1")
How it ran

no invocation recorded.

RectifiedStreched Not yet run
unverified (harvested, no recorded run)
nicola-decao/diffmask/diffmask/models/gates.py
code served (permissive licence) · get_code("f8f0147cc5dfb672")
How it ran

no invocation recorded.

Streched Not yet run
unverified (harvested, no recorded run)
angelosnal/vision-diffmask/code/models/gates.py
code served (permissive licence) · get_code("71fdc59594de30ac")
How it ran

no invocation recorded.

Also present in other papers' code

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

Attribution methods assess the contribution of inputs to the model prediction. One way to do so is erasure: a subset of inputs is considered irrelevant if it can be removed without affecting the prediction. Though conceptually simple, erasure's objective is intractable and approximate search remains expensive with modern deep NLP models. Erasure is also susceptible to the hindsight bias: the fact that an input can be dropped does not mean that the model 'knows' it can be dropped. The resulting pruning is over-aggressive and does not reflect how the model arrives at the prediction. To deal with these challenges, we introduce Differentiable Masking. DIFFMASK learns to maskout subsets of the input while maintaining differentiability. The decision to include or disregard an input token is made with a simple model based on intermediate hidden layers of the analyzed model. First, this makes the approach efficient because we predict rather than search. Second, as with probing classifiers, this reveals what the network 'knows' at the corresponding layers. This lets us not only plot attribution heatmaps but also analyze how decisions are formed across network layers. We use DIFFMASK to study BERT models on sentiment classification and question answering. 1

For agents

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

get_harvested_code_for_paper("2004.14992")
get_code_for_paper("2004.14992")
have("2004.14992")

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

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

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

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

Connect an agent — have() is free.