SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.04669 · NeurIPS · 2024

Towards a Theoretical Understanding of the 'Reversal Curse' via Training Dynamics

Michael Jordan, Stuart Russell, Baihe Huang, Yuandong Tian, Hanlin Zhu, Jiantao Jiao, Shaolun Zhang

arXiv · PDF · Open in the Atlas

Code that ran

7 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 0 have no contract verdict; 7 failures of our instrument; 0 no recorded run), measured 2026-11-22; 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/2405.04669.json · badge: /api/ran/2405.04669.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
marlo-z/reversal_curse_analysis canonical (classifier label)
classifier basis: census
7 ran · 0 no recorded run
FunctionStatusWhere it lives
create_forward_with_rotary_pe Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/model/Add_Rotary_PE.py
code served (permissive licence) · get_code("2a84924c2adf7a2c")
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
import torch.nn as nn
from typing import Tuple, Optional

torch.manual_seed(0)

class RotaryEmbedding:
    """Minimal rotary embedding implementation"""
    def __init__(self, dim):
        self.dim = dim
    
    def rotate_queries_or_keys(self, x):
        # Just return x unchanged for testing purposes
        return x

class MinimalGPT2Attention(nn.Module):
    """Minimal GPT2Attention module with required attributes and methods"""
    def __init__(self, hidden_size=4, num_heads=2):
        super().__init__()
        self.num_heads = num_heads
        self.head_dim = hidden_size // num_heads
        self.split_size = hidden_size
        self.reorder_and_upcast_attn = False
        
        # Linear layers for attention
        self.c_attn = nn.Linear(hidden_size, hidden_size * 3)
        self.c_proj = nn.Linear(hidden_size, hidden_size)
        self.resid_dropout = nn.Dropout(0.1)
    
    def _split_heads(self, tensor, num_heads, head_dim):
        """Split heads: (batch, seq, hidden) -> (batch, num_heads, seq, head_dim)"""
        batch_size, seq_length, _ = tensor.shape
        tensor = tensor.reshape(batch_size, seq_length, num_heads, head_dim)
        return tensor.permute(0, 2, 1, 3)
    
    def _merge_heads(self, tensor, num_heads, head_dim):
        """Merge heads: (batch, num_heads, seq, head_dim) -> (batch, seq, hidden)"""
        batch_size, _, seq_length, _ = tensor.shape
        tensor = tensor.permute(0, 2, 1, 3)
        return tensor.reshape(batch_size, seq_length, num_heads * head_dim)
    
    def _attn(self, query, key, value, attention_mask, head_mask):
        """Minimal attention computation"""
        # query, key, value: (batch, num_heads, seq, head_dim)
        scores = torch.matmul(query, key.transpose(-1, -2))
        scores = scores / (self.head_dim ** 0.5)
        
        if attention_mask is not None:
            scores = scores + attention_mask
        
        attn_weights = torch.softmax(scores, dim=-1)
        
        if head_mask is not None:
            attn_weights = attn_weights * head_mask
        
        attn_output = torch.matmul(attn_weights, value)
        return attn_output, attn_weights

# Create instances
rotary_embed = RotaryEmbedding(dim=4)
attention_module = MinimalGPT2Attention(hidden_size=4, num_heads=2)

# Create sample inputs
batch_size = 2
seq_length = 3
hidden_size = 4

hidden_states = torch.randn(batch_size, seq_length, hidden_size)
layer_past = None
attention_mask = None
head_mask = None
encoder_hidden_states = None
encoder_attention_mask = None
use_cache = False
output_attentions = False

ARGS = {
    'rotary_embed': rotary_embed,
}
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
generate_chain_dataset Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/datasets/ChainDataset.py
code served (permissive licence) · get_code("2beefe019a13b6f1")
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 numpy as np
import torch

torch.manual_seed(0)

ARGS = {
    'vocab_size': 20,
    'word_size': 2,
    'device': 'cpu',
    'split_ratio': 0.7,
    'SEED': 0,
}
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 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
generate_chain_dataset Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/datasets/ChainDataset_logits.py
code served (permissive licence) · get_code("efa17b00486faf3f")
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
import numpy as np

torch.manual_seed(0)
np.random.seed(0)

ARGS = {
    "vocab_size": 100,
    "word_size": 2,
    "device": torch.device("cpu"),
    "split_ratio": 0.7,
    "SEED": 0,
}
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 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
generate_chain_dataset_v2 Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/datasets/ChainDataset_related_tokens.py
code served (permissive licence) · get_code("e13e1fce2d0b0ecc")
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. 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 numpy as np
import torch
from torch.utils.data import Dataset

torch.manual_seed(0)
np.random.seed(0)

ARGS = dict(
    vocab_size=100,
    alphabet_size=10,
    num_train=5,
    num_val=3,
    device='cpu',
    SEED=0
)
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 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
generate_reverse_dataset Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/datasets/ReverseDataset.py
code served (permissive licence) · get_code("2a41a86260e2a69f")
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 numpy as np
import torch
from torch.utils.data import Dataset, DataLoader

torch.manual_seed(0)

ARGS = {
    'vocab_size': 32,
    'word_size': 2,
    'device': 'cpu',
    'split_ratio': 0.7,
    'SEED': 0
}
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 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
generate_reverse_dataset Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/datasets/ReverseDataset_logits.py
code served (permissive licence) · get_code("9bfc6b75de3254a1")
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 copy
import numpy as np
import itertools
import torch
from torch.utils.data import Dataset

torch.manual_seed(0)
np.random.seed(0)

# Define ARGS dictionary with all parameters for generate_reverse_dataset
ARGS = {
    'vocab_size': 32,
    'word_size': 2,
    'device': torch.device('cpu'),
    'split_ratio': 0.7,
    'SEED': 0
}
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 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
generate_reverse_dataset_ICL Ran
ran; our contract draft was wrong, not the code
marlo-z/reversal_curse_analysis/src/datasets/ReverseDataset_ICL.py
code served (permissive licence) · get_code("22223853110ce7ce")
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 numpy as np
import torch
from torch.utils.data import Dataset

torch.manual_seed(0)
np.random.seed(0)

ARGS = {
    'vocab_size': 50,
    'num_x_tokens': 5,
    'num_y_tokens': 3,
    'device': 'cpu',
    'split_ratio': 0.7,
    'SEED': 0
}
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 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

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

Auto-regressive large language models (LLMs) show impressive capacities to solve many complex reasoning tasks while struggling with some simple logical reasoning tasks such as inverse search: when trained on "A → B" (e.g., Tom is the parent of John), LLM fails to directly conclude "B ← A" (e.g., John is the child of Tom) during inference even if the two sentences are semantically identical, which is known as the "reversal curse". In this paper, we theoretically analyze the reversal curse via the training dynamics of (stochastic) gradient descent for two auto-regressive models: (1) a bilinear model that can be viewed as a simplification of a one-layer transformer; (2) one-layer transformers under certain assumptions. Our analysis reveals that for both models, the reversal curse is a consequence of the (effective) model weights asymmetry, i.e., the increase of weights from a token A to token B during training does not necessarily cause the increase of the weights from B to A, which is caused by the training dynamics under certain choice of loss function and the optimization space of model parameters. Moreover, our analysis can be naturally applied to other logical reasoning tasks such as chain-of-thought (COT), which provides a new perspective different from previous work that focuses on expressivity. Finally, we conduct experiments to validate our theory on multi-layer transformers under different settings. Our code is available at https://github.com/marlo-z/reversal_curse_analysis/. Large language models (LLMs) have shown great performance in solving complex reasoning tasks that require multiple reasoning steps through in-context learning (ICL), such as zero-shot learning [1, 2], few-shot learning [3,4,5], or via further fine-tuning [6,7,8]. However, without the above inferencetime techniques or model fine-tuning (probably combined with data manipulations), an auto-regressive LLM might struggle with simple logical reasoning tasks that require multiple reasoning steps learned during training separately [9], where the reversal curse [10] serves as a well-known example.

For agents

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

get_harvested_code_for_paper("2405.04669")
get_code_for_paper("2405.04669")
have("2405.04669")

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

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

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

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

Connect an agent — have() is free.