SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.11770 · ICML · 2025

Internal Causal Mechanisms Robustly Predict Language Model Out-of-Distribution Behaviors

Jing Huang, Christopher Potts, Thomas Icard, Diyi Yang, Junyi Tao

arXiv · PDF · Open in the Atlas

Code that ran

4 of 4 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 0 have no contract verdict; 4 failures of our instrument; 0 no recorded run), measured 2026-11-24; 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/2505.11770.json · badge: /api/ran/2505.11770.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
explanare/ood-prediction canonical (classifier label)
classifier basis: classifier_2025
4 ran · 0 no recorded run
FunctionStatusWhere it lives
compute_auc_roc_for_all_locations Ran
ran; our contract draft was wrong, not the code
explanare/ood-prediction/src/probe.py
code served (permissive licence) · get_code("689bba449c6f1984")
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. 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 numpy as np
import collections

torch.manual_seed(0)

# Build hidden_states structure
# hidden_states['train'][loc_key] should be shape (num_examples, num_layers, feature_dim)
# hidden_states['val'][loc_key] should be shape (num_examples, num_layers, feature_dim)
# hidden_states['test'][loc_key] should be shape (num_examples, num_layers, feature_dim)

hidden_states = {
    'train': {
        'loc_0': torch.randn(8, 3, 4),  # 8 examples, 3 layers, 4 features
        'loc_1': torch.randn(8, 3, 4),
    },
    'val': {
        'loc_0': torch.randn(6, 3, 4),  # 6 examples, 3 layers, 4 features
        'loc_1': torch.randn(6, 3, 4),
    },
    'test': {
        'loc_0': torch.randn(4, 3, 4),  # 4 examples, 3 layers, 4 features
        'loc_1': torch.randn(4, 3, 4),
    },
}

# Build example_labels
# For train and val, we need labels that match the class_labels used in probing
# The function will extract examples by class_labels
# For test, we need 'correct' and 'wrong' labels
example_labels = {
    'train': ['class_a', 'class_b', 'class_a', 'class_b', 'class_a', 'class_b', 'class_a', 'class_b'],
    'val': ['class_a', 'class_b', 'class_a', 'class_b', 'class_a', 'class_b'],
    'test': ['correct', 'correct', 'wrong', 'wrong'],
}

ARGS = {
    'hidden_states': hidden_states,
    'example_labels': example_labels,
    'method': 'svm',
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, sklearn, 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
extract_all_hidden_states_batched Ran
ran; our contract draft was wrong, not the code
explanare/ood-prediction/src/probe.py
code served (permissive licence) · get_code("49fc71840de1db52")
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
import numpy as np

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __call__(self, texts, return_tensors=None, padding=None, max_length=None):
        batch_size = len(texts)
        seq_len = max_length if max_length else 10
        
        # Create minimal encoded inputs
        input_ids = torch.randint(0, 100, (batch_size, seq_len))
        attention_mask = torch.ones(batch_size, seq_len)
        
        class EncodedInputs:
            def __init__(self, input_ids, attention_mask):
                self.input_ids = input_ids
                self.attention_mask = attention_mask
            
            def to(self, device):
                self.input_ids = self.input_ids.to(device)
                self.attention_mask = self.attention_mask.to(device)
                return self
            
            def keys(self):
                return ['input_ids', 'attention_mask']
            
            def __getitem__(self, key):
                if key == 'input_ids':
                    return self.input_ids
                elif key == 'attention_mask':
                    return self.attention_mask
        
        return EncodedInputs(input_ids, attention_mask)

# Create a minimal model
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.device = torch.device('cpu')
        self.config = type('Config', (), {'output_hidden_states': False})()
        self.embedding = nn.Embedding(100, 4)
        self.linear = nn.Linear(4, 4)
    
    def forward(self, input_ids, attention_mask, position_ids=None, **kwargs):
        # Generate hidden states for each layer
        batch_size, seq_len = input_ids.shape
        num_layers = 3
        
        hidden_state = self.embedding(input_ids)
        hidden_state = self.linear(hidden_state)
        
        # Create tuple of hidden states (one per layer)
        hidden_states = tuple(hidden_state + torch.randn(batch_size, seq_len, 4) * 0.01 for _ in range(num_layers))
        
        class Output:
            pass
        
        output = Output()
        output.hidden_states = hidden_states
        return output

# Create test data
model = MinimalModel()
tokenizer = MinimalTokenizer()
prompts = ["Hello world", "Test prompt"]
input_max_length = 10
token_positions = {"pos_0": 0, "pos_1": 1}
batch_size = 64

ARGS = {
    "model": model,
    "tokenizer": tokenizer,
    "prompts": prompts,
    "input_max_length": input_max_length,
    "token_positions": token_positions,
    "batch_size": batch_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, sklearn, 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
remove_invalid_token_id Ran
ran; our contract draft was wrong, not the code
explanare/ood-prediction/src/causal_interventions.py
code served (permissive licence) · get_code("0a4efe5cf8c13920")
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 Tensor, ndim 2, dtype family int, 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

torch.manual_seed(0)

# Create a small tensor with some negative values to test the function
token_ids = torch.tensor([
    [1, -1, 3, 0],
    [2, 5, -2, 4]
], dtype=torch.long)

pad_id = 2

ARGS = {
    "token_ids": token_ids,
    "pad_id": pad_id
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 int, 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: none by the harness; any seed is in the setup block
train_linear_binary_classifier Ran
ran; our contract draft was wrong, not the code
explanare/ood-prediction/src/probe.py
code served (permissive licence) · get_code("178c8576ac598b9c")
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 LinearSVC. 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)

# Create small feature tensors for two classes
# Shape: (batch_size, feature_dim) = (2, 4)
class_a_train = torch.randn(2, 4)
class_b_train = torch.randn(2, 4)

class_a_val = torch.randn(2, 4)
class_b_val = torch.randn(2, 4)

# Create dictionaries mapping class labels to feature tensors
train_feats = {
    'class_a': class_a_train,
    'class_b': class_b_train
}

val_feats = {
    'class_a': class_a_val,
    'class_b': class_b_val
}

ARGS = {
    'train_feats': train_feats,
    'val_feats': val_feats,
    'cls_type': 'SVC',
    'class_labels': ['class_a', 'class_b'],
    'return_accuracy': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, sklearn, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LinearSVC — a LinearSVC output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a LinearSVC 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

Also present in other papers' code

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

Repositories linked to this paper

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

Abstract

Interpretability research now offers a variety of techniques for identifying abstract internal mechanisms in neural networks. Can such techniques be used to predict how models will behave on out-ofdistribution examples? In this work, we provide a positive answer to this question. Through a diverse set of language modeling tasks-including symbol manipulation, knowledge retrieval, and instruction following-we show that the most robust features for correctness prediction are those that play a distinctive causal role in the model's behavior. Specifically, we propose two methods that leverage causal mechanisms to predict the correctness of model outputs: counterfactual simulation (checking whether key causal variables are realized) and value probing (using the values of those variables to make predictions). Both achieve high AUC-ROC in distribution and outperform methods that rely on causal-agnostic features in out-of-distribution settings, where predicting model behaviors is more crucial. Our work thus highlights a novel and significant application for internal causal analysis of language models.

For agents

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

get_harvested_code_for_paper("2505.11770")
get_code_for_paper("2505.11770")
have("2505.11770")

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

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

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

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

Connect an agent — have() is free.