SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.11737 · ICLR · 2025

TO KUR: TOKEN-LEVEL UNCERTAINTY ESTIMATION FOR LARGE LANGUAGE MODEL REASONING

Huan Zhang, Hao Wang, Dimitris Metaxas, Ligong Han, Haoxian Chen, Kai Xu, Haizhou Shi, Yibin Wang, Hengyi Wang, Xiaoxiao He, Tunyu Zhang, Zhuowei Li

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 10 have no contract verdict; 0 failures of our instrument; 2 no recorded run), measured 2026-11-24; 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.11737.json · badge: /api/ran/2505.11737.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
Wang-ML-Lab/TokUR canonical (classifier label)
classifier basis not recorded on the link
10 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_basis_vectors Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/convert_to_tfb.py
code served (permissive licence) · get_code("2af250d17e1c0d8e")
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

torch.manual_seed(0)

# Construct model_tensors dict with q_proj and v_proj weights
# These should be 2D tensors for SVD computation
model_tensors = {
    'layer.0.self_attn.q_proj.weight': torch.randn(4, 8),  # output_dim x input_dim
    'layer.0.self_attn.v_proj.weight': torch.randn(4, 8),  # output_dim x input_dim
    'layer.0.mlp.fc1.weight': torch.randn(16, 8),  # This will be skipped (not target module)
}

rank = 2
bayes_noise = 'right'

ARGS = {
    'model_tensors': model_tensors,
    'rank': rank,
    'bayes_noise': bayes_noise,
}
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 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 Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/eval/eval_detect_multi_seed.py
code served (permissive licence) · get_code("c4658e75b36730c8")
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 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 re

def strip_string(s):
    """Strip whitespace and common formatting from string"""
    return s.strip()

def extract_answer(string, category):
    """Extract answer from string for given category"""
    # Simple mock implementation
    if category == 'math':
        # Look for patterns like "answer: ..." or "= ..."
        match = re.search(r'(?:answer|=)\s*([^,\.]*)', string, re.IGNORECASE)
        if match:
            return match.group(1)
    return string

ARGS = {
    'string': 'The answer to the problem is 42. Please verify this calculation.'
}
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 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
extract_unc Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/eval/eval_detect_multi_seed.py
code served (permissive licence) · get_code("612763a12b59e7c2")
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

class UncertaintyMetrics:
    def __init__(self, aleatoric_uncertainty, total_uncertainty, epistemic_uncertainty):
        self.aleatoric_uncertainty = aleatoric_uncertainty
        self.total_uncertainty = total_uncertainty
        self.epistemic_uncertainty = epistemic_uncertainty

class LogprobMetrics:
    def __init__(self, logprob):
        self.logprob = logprob

class OutputObject:
    def __init__(self, uncertainties, logprobs):
        self.uncertainties = uncertainties
        self.logprobs = logprobs

# Create uncertainty list with 3 entries
unc_list = [
    {'key1': UncertaintyMetrics(aleatoric_uncertainty=0.1, total_uncertainty=0.3, epistemic_uncertainty=0.2)},
    {'key2': UncertaintyMetrics(aleatoric_uncertainty=0.15, total_uncertainty=0.35, epistemic_uncertainty=0.25)},
    {'key3': UncertaintyMetrics(aleatoric_uncertainty=0.12, total_uncertainty=0.32, epistemic_uncertainty=0.22)},
]

# Create logprob list with 3 entries
ll_list = [
    {'key1': LogprobMetrics(logprob=-1.5)},
    {'key2': LogprobMetrics(logprob=-1.2)},
    {'key3': LogprobMetrics(logprob=-1.8)},
]

# Create the output object
output = OutputObject(uncertainties=unc_list, logprobs=ll_list)

ARGS = {
    'output': output
}
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 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
filter_processed_samples Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/run/greedy_responses_unc.py
code served (permissive licence) · get_code("36c23319e690d2aa")
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 MinimalDataset. 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 os
import tempfile
import json
import shutil

# Create a temporary directory for output
temp_output_dir = tempfile.mkdtemp()

# Create a minimal dataset-like object that supports .filter() and len()
class MinimalDataset:
    def __init__(self, samples):
        self.samples = samples
    
    def __len__(self):
        return len(self.samples)
    
    def __getitem__(self, idx):
        return self.samples[idx]
    
    def filter(self, fn):
        filtered_samples = [s for s in self.samples if fn(s)]
        return MinimalDataset(filtered_samples)

# Create sample data with different ID formats
dataset_samples = [
    {'unique_id': 'question_1', 'text': 'What is AI?'},
    {'unique_id': 'question_2', 'text': 'How does ML work?'},
    {'metadata': {'source_index': 'question_3'}, 'text': 'What is deep learning?'},
    {'unique_id': 'question_4', 'text': 'Explain transformers'},
]

dataset = MinimalDataset(dataset_samples)

# Create some pre-existing processed results in output_dir
os.makedirs(temp_output_dir, exist_ok=True)

# Add a valid processed file
processed_file_1 = os.path.join(temp_output_dir, 'question_1.json')
with open(processed_file_1, 'w') as f:
    json.dump({'outputs': ['result1'], 'error': False}, f)

# Add another valid processed file
processed_file_2 = os.path.join(temp_output_dir, 'question_2.json')
with open(processed_file_2, 'w') as f:
    json.dump({'outputs': ['result2'], 'error': False}, f)

# Add an error file (should be skipped)
error_file = os.path.join(temp_output_dir, 'question_5_error.json')
with open(error_file, 'w') as f:
    json.dump({'error': True}, f)

output_dir = temp_output_dir

ARGS = {
    'dataset': dataset,
    'output_dir': output_dir,
}
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 MinimalDataset — a MinimalDataset output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MinimalDataset output the recorded ndim 1 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_processed_question_ids Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/run/greedy_responses_unc.py
code served (permissive licence) · get_code("d854607e3f87f444")
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 set. 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 os
import json
import tempfile
import shutil

# Create a temporary directory for testing
temp_dir = tempfile.mkdtemp()

# Create some test JSON files with valid structure
test_file_1 = os.path.join(temp_dir, 'question_001.json')
with open(test_file_1, 'w', encoding='utf-8') as f:
    json.dump({'outputs': ['result1'], 'error': False}, f)

test_file_2 = os.path.join(temp_dir, 'question_002.json')
with open(test_file_2, 'w', encoding='utf-8') as f:
    json.dump({'outputs': ['result2', 'result3'], 'error': False}, f)

# Create an error file that should be skipped
error_file = os.path.join(temp_dir, 'question_003_error.json')
with open(error_file, 'w', encoding='utf-8') as f:
    json.dump({'error': True}, f)

# Create a file with empty outputs that should not be counted
empty_outputs_file = os.path.join(temp_dir, 'question_004.json')
with open(empty_outputs_file, 'w', encoding='utf-8') as f:
    json.dump({'outputs': [], 'error': False}, f)

# Create a file with error flag set to True
error_flag_file = os.path.join(temp_dir, 'question_005.json')
with open(error_flag_file, 'w', encoding='utf-8') as f:
    json.dump({'outputs': ['some_output'], 'error': True}, f)

ARGS = {
    'output_dir': temp_dir
}
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 set — a set output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a set 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_question_id_from_sample Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/run/greedy_responses_unc.py
code served (permissive licence) · get_code("177d16620203d11d")
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 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

torch.manual_seed(0)

# Sample with 'unique_id' field
sample_with_unique_id = {
    'unique_id': 'path/to/file.json'
}

# Sample with 'metadata' containing 'source_index'
sample_with_metadata = {
    'metadata': {
        'source_index': 'another/path/file.json'
    }
}

# Sample with neither field
sample_with_neither = {
    'text': 'some data'
}

# Test with the first sample type
ARGS = {
    'sample': sample_with_unique_id
}
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 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
get_top_p_acc Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/eval/eval_detect_multi_seed.py
code served (permissive licence) · get_code("c4cbd297e9b1b00a")
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 float64, 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 pandas as pd
import numpy as np

# Create a small DataFrame with the required columns
np.random.seed(0)
n_samples = 20

data = {
    'label': np.random.randint(0, 2, n_samples),  # binary labels (0 or 1)
    'score': np.random.rand(n_samples)  # random scores to sort by
}
df = pd.DataFrame(data)

# Define arguments for the function
ARGS = {
    'df': df,
    'p': 0.5,  # top 50% of samples
    'col': 'score'  # column to sort by
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
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
get_unc_scores Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/eval/eval_scaling_test_multi_gpu.py
code served (permissive licence) · get_code("00af6a278e20a2ae")
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)

# Build a response object that matches the function's expectations
# The function accesses:
# - response['uncertainties'] (dict-like)
# - response['logprobs']['nll'] (scalar or tensor)
# - response['logprobs']['ll'] (scalar or tensor)

response = {
    'uncertainties': {
        'entropy': 0.5,
        'variation_ratio': 0.3,
        'prediction_confidence': 0.9
    },
    'logprobs': {
        'nll': -2.1,
        'll': 2.1
    }
}

ARGS = {
    'response': response
}
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
load_safetensors Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/convert_to_tfb.py
code served (permissive licence) · get_code("33e06dc7143176a6")
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 tuple. 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 os
import tempfile
import torch
import safetensors.torch

# Create a temporary directory with safetensors files
temp_dir = tempfile.mkdtemp()

# Create some small test tensors
torch.manual_seed(0)
tensor1 = torch.randn(2, 4)
tensor2 = torch.randn(3, 5)

# Save them as safetensors files
safetensors.torch.save_file({"weight1": tensor1}, os.path.join(temp_dir, "model_00001.safetensors"))
safetensors.torch.save_file({"weight2": tensor2}, os.path.join(temp_dir, "model_00002.safetensors"))

ARGS = {
    "path": temp_dir
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
safetensors, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple 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
softmax Ran
ran on a synthesized input
Wang-ML-Lab/TokUR/eval/eval_scaling_test_multi_gpu.py
code served (permissive licence) · get_code("1124b1f7a07898d8")
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 ndarray, 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 numpy as np

# The softmax function takes a single parameter 'x' which should be array-like
# The function converts it to a numpy array, computes exponentials with max subtraction
# for numerical stability, and normalizes along the last axis

# Create a small test input with shape (2, 4) - batch of 2, feature dimension of 4
x_input = np.array([
    [1.0, 2.0, 3.0, 4.0],
    [0.5, 1.5, 2.5, 3.5]
])

ARGS = {
    "x": x_input
}
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 ndarray, 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: none by the harness; any seed is in the setup block
pop_last_state_from_cache Not yet run
unverified (harvested, no recorded run)
Wang-ML-Lab/TokUR/bayesian_transformer/bayesian_transformer/model.py
code served (permissive licence) · get_code("731db31dd6f9bc61")
How it ran

no invocation recorded.

pop_last_state_from_cache Not yet run
unverified (harvested, no recorded run)
Wang-ML-Lab/TokUR/bayesian_transformer/bayesian_transformer/vllm_models/tfb_llama.py
code served (permissive licence) · get_code("2a9ea7d5d0294b1c")
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 11 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 11 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

While Large Language Models (LLMs) have demonstrated impressive capabilities, their output quality remains inconsistent across various application scenarios, making it difficult to identify trustworthy responses, especially in complex tasks requiring multi-step reasoning. In this paper, we propose a Token-level Uncertainty estimation framework for Reasoning (TokUR) that enables LLMs to self-assess and self-improve their responses in mathematical reasoning. Specifically, we introduce low-rank random weight perturbation during LLM decoding to generate predictive distributions for token-level uncertainty estimation, and we aggregate these uncertainty quantities to capture the semantic uncertainty of generated responses. Experiments on mathematical reasoning datasets of varying difficulty demonstrate that TokUR exhibits a strong correlation with answer correctness and model robustness, and the uncertainty signals produced by TokUR can be leveraged to enhance the model's reasoning performance at test time. These results highlight the effectiveness of TokUR as a principled and scalable approach for improving the reliability and interpretability of LLMs in challenging reasoning tasks. The source code is avaliable at https://github.com/Wang-ML-Lab/TokUR.

For agents

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

get_harvested_code_for_paper("2505.11737")
get_code_for_paper("2505.11737")
have("2505.11737")

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

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

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

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

Connect an agent — have() is free.