SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.12853 · ACL · 2025

S 2 R: Teaching LLMs to Self-verify and Self-correct via Reinforcement Learning

Jia Li, Jiaqi Chen, Nan Du, Bang Zhang, Xin Zhou, Cheng Liu, Peisong Wang, Ruotian Ma, Xingyan Liu

arXiv · PDF · Open in the Atlas

Code that ran

10 of 12 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 7 have no contract verdict; 3 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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/2502.12853.json · badge: /api/ran/2502.12853.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
nineabyss/s2r canonical (classifier label)
classifier basis not recorded on the link
10 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_baseline Ran
ran on a synthesized input
nineabyss/s2r/code/data_process_offline_rl.py
code served (permissive licence) · get_code("12f058fedbfebe48")
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 float, ndim 0, dtype family float, shape () 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 numpy as np
from typing import List

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

# Create a valid reward_history list
reward_history = [0.5, 1.2, 0.8, 1.5, 2.0, 0.9, 1.1, 1.3, 0.7, 1.4, 0.6, 1.8]

# Define ARGS dictionary with all parameters
ARGS = {
    "reward_history": reward_history,
    "use_softmax_norm": False,
    "tau": 1.0,
    "min_group_baseline": 10
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () 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
exact_div Ran
ran on a synthesized input
nineabyss/s2r/code/src/rloo_trainer.py
code served (permissive licence) · get_code("d5d26fac128716bc")
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 int, ndim 0, dtype family int, shape () 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)

# The function exact_div performs integer division and checks if it's exact
# It takes:
# - a: a number to divide
# - b: a divisor
# - custom_error_message: an optional error message string

# For valid execution, we need a and b such that a is divisible by b
# Let's use simple integers where division is exact

a = 12
b = 3
custom_error_message = 'Test error'

ARGS = {
    'a': a,
    'b': b,
    'custom_error_message': custom_error_message
}
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 int, ndim 0, dtype family int, shape () — shape () 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
generate_completions Ran
ran; our contract draft was wrong, not the code
nineabyss/s2r/sample/model_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from fanqiwan/FuseAI, is pointer only (licence: NONE) · get_code("1525d8bc0fc8d5a0")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from fanqiwan/FuseAI, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_all_parameters Ran
ran; our contract draft was wrong, not the code
nineabyss/s2r/code/src/offline_trainer.py
code served (permissive licence) · get_code("2f5119732e8dbd63")
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 chain. 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 itertools

torch.manual_seed(0)

class MockSubModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
        self.conv = nn.Conv1d(2, 5, 3)
    
    def ds_external_parameters(self):
        # Return an iterable of (name, parameter) tuples
        # simulating external parameters like those from DeepSpeed
        external_param1 = nn.Parameter(torch.randn(2, 4))
        external_param2 = nn.Parameter(torch.randn(3))
        return [("external_param_1", external_param1), ("external_param_2", external_param2)]

sub_module = MockSubModule()

ARGS = {
    "sub_module": sub_module,
    "recurse": False
}
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 chain — a chain output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a chain 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
get_instance_reward_from_reward_dist Ran
ran on a synthesized input
nineabyss/s2r/code/data_process_offline_rl.py
code served (permissive licence) · get_code("90b37672a94f87c5")
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 float, ndim 0, dtype family float, shape () 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)

def get_instance_reward_from_reward_dist(reward_dist: str) -> float:
    for i in range(len(reward_dist) - 1, -1, -1):
        if reward_dist[i] == 'R':
            return 1.0 if reward_dist[i + 1] == '+' else -1.0

ARGS = {
    "reward_dist": "test_R+"
}
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 float, ndim 0, dtype family float, shape () — shape () 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
hooks_exist Ran
ran on a synthesized input
nineabyss/s2r/code/src/offline_trainer.py
code served (permissive licence) · get_code("a989572880b87850")
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 bool, ndim 0, dtype family float, shape () 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 MockOptimizer:
    """Mock optimizer with forward_hooks attribute"""
    def __init__(self, has_parameter_offload=False):
        self.forward_hooks = []
        if has_parameter_offload:
            self.parameter_offload = self
    
    def register_forward_hook(self, hook):
        self.forward_hooks.append(hook)


class MockEngine:
    """Mock engine with optimizer attribute"""
    def __init__(self, optimizer=None):
        self.optimizer = optimizer


# Test case 1: Engine with optimizer that has parameter_offload attribute
optimizer_with_offload = MockOptimizer(has_parameter_offload=True)
engine_with_offload = MockEngine(optimizer=optimizer_with_offload)

# Test case 2: Engine with optimizer without parameter_offload and with hooks
optimizer_with_hooks = MockOptimizer(has_parameter_offload=False)
optimizer_with_hooks.register_forward_hook(lambda x: x)
engine_with_hooks = MockEngine(optimizer=optimizer_with_hooks)

# Test case 3: Engine with optimizer without hooks
optimizer_no_hooks = MockOptimizer(has_parameter_offload=False)
engine_no_hooks = MockEngine(optimizer=optimizer_no_hooks)

# Test case 4: Engine with None optimizer
engine_none_optimizer = MockEngine(optimizer=None)

# Use the first case for the main ARGS
ARGS = {
    "engine": engine_with_hooks
}
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 bool, ndim 0, dtype family float, shape () — shape () 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
iter_params Ran
ran; our contract draft was wrong, not the code
nineabyss/s2r/code/src/offline_trainer.py
code served (permissive licence) · get_code("48685a350888e505")
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 list. 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 itertools

torch.manual_seed(0)

class MockSubModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
        self.conv = nn.Conv1d(2, 5, 3)
    
    def named_parameters(self, recurse=False):
        if recurse:
            return super().named_parameters(recurse=True)
        else:
            return super().named_parameters(recurse=False)
    
    def ds_external_parameters(self):
        external_param = nn.Parameter(torch.randn(7, 2))
        yield ('external_param', external_param)

module = MockSubModule()

ARGS = {
    'module': module,
    'recurse': False
}
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 list — a list output has no array shape of its own; none is 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
iter_params Ran
ran on a synthesized input
nineabyss/s2r/code/src/rloo_utils.py
code served (permissive licence) · get_code("bb274361403163d9")
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 map. 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 itertools

torch.manual_seed(0)

class MockSubModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
        self.conv = nn.Conv1d(4, 5, 3)
    
    def ds_external_parameters(self):
        # Return an iterator of (name, param) tuples for external parameters
        external_param = nn.Parameter(torch.randn(2, 4))
        yield ("external_param_0", external_param)
        yield ("external_param_1", nn.Parameter(torch.randn(3, 5)))

sub_module = MockSubModule()

ARGS = {
    "module": sub_module,
    "recurse": False
}
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 map — a map output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a map 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
jload Ran
ran on a synthesized input
nineabyss/s2r/code/utils.py
code served (permissive licence) · get_code("17c4e4f3635d3ee1")
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 json
import tempfile
import os

# Create a temporary .json file
json_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "object"}
}

temp_json = tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False)
json.dump(json_data, temp_json)
temp_json.close()

ARGS = {
    "data_path": temp_json.name
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — 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
preprocess Ran
ran on a synthesized input
nineabyss/s2r/code/data_process_offline_rl.py
code served (permissive licence) · get_code("79fec8bb0e1104b4")
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 transformers
from unittest.mock import Mock

torch.manual_seed(0)

# Create a minimal stand-in tokenizer
class MinimalTokenizer:
    def __init__(self):
        self.model_max_length = 512
        self.pad_token_id = 0
    
    def __call__(self, text, return_tensors=None, padding=None, max_length=None, truncation=None):
        # Simulate tokenization by creating token ids
        tokens = [1, 2, 3, 4]  # Minimal token sequence
        input_ids = torch.tensor([tokens], dtype=torch.long)
        
        # Create a mock return object
        mock_result = Mock()
        mock_result.input_ids = input_ids
        return mock_result

tokenizer = MinimalTokenizer()

# Create minimal sources and targets
sources = ["Hello ", "Hi "]
targets = ["world", "there"]

ARGS = {
    "sources": sources,
    "targets": targets,
    "tokenizer": tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — 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
load_hf_lm_and_tokenizer Not yet run
unverified (harvested, no recorded run)
nineabyss/s2r/sample/model_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from YangLing0818/SuperCorrect-llm, is pointer only (licence: NONE) · get_code("ee71a94d9dd1b8e9")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from YangLing0818/SuperCorrect-llm, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

setup_chat_format Not yet run
unverified (harvested, no recorded run)
nineabyss/s2r/code/src/rloo_utils.py
code served (permissive licence) · get_code("ec228a2a8084ed7e")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 2 the same month, 4 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.

FunctionAlso present inEarliest-datedOthers named
load_hf_lm_and_tokenizer 18 other papers
5 dated earlier, 1 the same month, 12 later
2405.14365 (2024-05)
JiuZhang3.0: Efficiently Improving Mathematical Reasoning by Training Small Data Synthesis Models
2408.07471 (2024-08)
Bridging and Modeling Correlations in Pairwise Data for Direct Preference Optimization
2410.07985 (2024-10)
Omni-MATH: A Universal Olympiad Level Mathematic Benchmark For Large Language Models
and 15 more not named here
generate_completions 17 other papers
4 dated earlier, 1 the same month, 12 later
2405.14365 (2024-05)
JiuZhang3.0: Efficiently Improving Mathematical Reasoning by Training Small Data Synthesis Models
2408.07471 (2024-08)
Bridging and Modeling Correlations in Pairwise Data for Direct Preference Optimization
2410.07985 (2024-10)
Omni-MATH: A Universal Olympiad Level Mathematic Benchmark For Large Language Models
and 14 more not named here
get_all_parameters 2 other papers
1 dated earlier, 1 later
2305.18290 (2023-05)
Direct Preference Optimization: Your Language Model is Secretly a Reward Model
2509.12521 (2025-09)
Phi: Preference Hijacking in Multi-modal Large Language Models at Inference Time
iter_params 2 other papers
1 dated earlier, 1 later
2305.18290 (2023-05)
Direct Preference Optimization: Your Language Model is Secretly a Reward Model
2509.12521 (2025-09)
Phi: Preference Hijacking in Multi-modal Large Language Models at Inference Time

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

Recent studies have demonstrated the effectiveness of LLM test-time scaling. However, existing approaches to incentivize LLMs' deep thinking abilities generally require large-scale data or significant training efforts. Meanwhile, it remains unclear how to improve the thinking abilities of less powerful base models. In this work, we introduce S 2 R, an efficient framework that enhances LLM reasoning by teaching models to self-verify and self-correct during inference. Specifically, we first initialize LLMs with iterative self-verification and self-correction behaviors through supervised fine-tuning on carefully curated data. The self-verification and self-correction skills are then further strengthened by outcome-level and process-level reinforcement learning with minimized resource requirements. Our results demonstrate that, with only 3.1k behavior initialization samples, Qwen2.5-math-7B achieves an accuracy improvement from 51.0% to 81.6%, outperforming models trained on an equivalent amount of long-CoT distilled data. We also discuss the effect of different RL strategies on enhancing LLMs' deep reasoning. Extensive experiments and analysis based on three base models across both in-domain and out-of-domain benchmarks validate the effectiveness of S 2 R 1 .

For agents

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

get_harvested_code_for_paper("2502.12853")
get_code_for_paper("2502.12853")
have("2502.12853")

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

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

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

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

Connect an agent — have() is free.