SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2603.17305 · ICML · 2026

Contrastive Reasoning Alignment: Reinforcement Learning from Hidden Representations

Yan Chen, Binghui Wang, Jiahao Yu, Haozheng Luo, Yimin Wang

arXiv · PDF · Open in the Atlas

Code that ran

6 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 2 have no contract verdict; 4 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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/2603.17305.json · badge: /api/ran/2603.17305.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
robinzixuan/CRAFT community
Papers with Code archive
6 ran · 2 no recorded run
FunctionStatusWhere it lives
ProjectionHead Ran
ran on a synthesized input
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("8c2c1b1dd95dc755")
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, 512) 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.nn as nn
import torch.nn.functional as F
import numpy as np

class ProjectionHead(nn.Module):

    def __init__(self, d_in, d=512):
        super().__init__()
        self.fn1 = nn.Linear(d_in, 1024)
        self.gelu = nn.GELU()
        self.fn2 = nn.Linear(1024, d)

    def forward(self, x):
        x = self.fn1(x)
        x = self.gelu(x)
        x = self.fn2(x)
        return F.normalize(x, dim=-1)


INIT_ARGS = {
    'd_in': 4,
    'd': 512
}

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

if __name__ == '__main__':
    model = ProjectionHead(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output norm (should be ~1.0): {output.norm(dim=-1)}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, 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, 512) — shape (2, 512) 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)
SafetyHead Ran
ran on a synthesized input
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("b04b8e075904df93")
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, 3) 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.nn as nn

class SafetyHead(nn.Module):

    def __init__(self, d, num_classes=3):
        super().__init__()
        self.fc = nn.Linear(d, num_classes)

    def forward(self, z):
        return self.fc(z)


INIT_ARGS = {
    'd': 4,
    'num_classes': 3,
}

ARGS = {
    'z': torch.randn(2, 4),
}

if __name__ == '__main__':
    model = SafetyHead(**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
numpy, 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, 3) — shape (2, 3) 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)
aug_text Ran
ran; our contract draft was wrong, not the code
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("611cd5ae4b05efbb")
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 str. 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 torch.nn.functional as F
import random
import numpy as np

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

# The function aug_text takes a single parameter 't' which is a string
# It splits the string into tokens, randomly removes ~5% of them, and returns the result

ARGS = {
    't': 'the quick brown fox jumps over the lazy dog and runs through the forest'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
contractive_loss Ran
ran; our contract draft was wrong, not the code
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("302f6dafea349431")
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 0, 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
import torch.nn.functional as F
import numpy as np

torch.manual_seed(0)

# Set up tensor arguments
batch_size = 2
embedding_dim = 4

# Create embeddings tensor [B, d]
z = torch.randn(batch_size, embedding_dim)

# Create prototype tensors [d]
mu_safe = torch.randn(embedding_dim)
mu_unsafe = torch.randn(embedding_dim)
mu_rethink = torch.randn(embedding_dim)

# Set margin parameter
margin = 0.2

ARGS = {
    "z": z,
    "mu_safe": mu_safe,
    "mu_unsafe": mu_unsafe,
    "mu_rethink": mu_rethink,
    "margin": margin
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float — no output shape is stated: observe_signature.py could not observe it (read:TypeError)
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
info_nce Ran
ran; our contract draft was wrong, not the code
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("0a662220aa93c170")
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 0, 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
import torch.nn.functional as F

torch.manual_seed(0)

# z1: normalized representation from first view, shape (batch_size, embedding_dim)
z1 = torch.randn(2, 4)

# z2: normalized representation from second view, shape (batch_size, embedding_dim)
z2 = torch.randn(2, 4)

# queue: memory bank of negative samples, shape (queue_size, embedding_dim)
# Can be empty tensor or populated with samples
queue = torch.randn(5, 4)

# tau: temperature parameter for scaling
tau = 0.1

ARGS = {
    "z1": z1,
    "z2": z2,
    "queue": queue,
    "tau": tau,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float — no output shape is stated: observe_signature.py could not observe it (read:TypeError)
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
pool Ran
ran; our contract draft was wrong, not the code
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("b6aa7d2f5a56d6fd")
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 Tensor, ndim 2, dtype family float, shape (2, 3) 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.nn as nn

torch.manual_seed(0)

# Construct arguments for pool(h, attn)
# h: hidden states tensor, shape (batch, seq_len, hidden_dim)
# attn: attention weights tensor, shape (batch, seq_len)

batch_size = 2
seq_len = 4
hidden_dim = 3

# h should be (batch, seq_len, hidden_dim)
h = torch.randn(batch_size, seq_len, hidden_dim)

# attn should be (batch, seq_len) with positive values for attention weights
attn = torch.softmax(torch.randn(batch_size, seq_len), dim=1)

ARGS = {
    "h": h,
    "attn": attn
}
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 Tensor, ndim 2, dtype family float, shape (2, 3) — shape (2, 3) 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
text_safe_prob Not yet run
unverified (harvested, no recorded run)
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("c3b8a7dffd388954")
How it ran

no invocation recorded.

train_latent_contrastive Not yet run
unverified (harvested, no recorded run)
robinzixuan/CRAFT/src/lclr/lca.py
code served (permissive licence) · get_code("e4c026db7297b65c")
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

Content warning: This paper contains examples of harmful language. We propose CRAFT, a red-teaming alignment framework that leverages model reasoning capabilities and hidden representations to improve robustness against jailbreak attacks. Unlike prior defenses that operate primarily at the output level, CRAFT aligns large reasoning models to generate safety-aware reasoning traces by explicitly optimizing objectives defined over the hidden state space. Methodologically, CRAFT integrates contrastive representation learning with reinforcement learning to separate safe and unsafe reasoning trajectories, yielding a latent-space geometry that supports robust, reasoning-level safety alignment. Theoretically, we show that incorporating latent-textual consistency into GRPO eliminates superficially aligned policies by ruling them out as local optima. Empirically, we evaluate CRAFT on multiple safety benchmarks using two strong reasoning models, Qwen3-4B-Thinking and R1-Distill-Llama-8B, where it consistently outperforms state-of-the-art defenses such as IPO and SafeKey. Notably, CRAFT delivers an average 82.1% improvement in reasoning safety and 89.6% improvement in finalresponse safety over the base models, demonstrating the effectiveness of hidden-space reasoning alignment. Code is available at https: //github.com/robinzixuan/CRAFT.

For agents

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

get_harvested_code_for_paper("2603.17305")
get_code_for_paper("2603.17305")
have("2603.17305")

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

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

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

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

Connect an agent — have() is free.