This repository contains the code for our NeurIPS 2026 paper Calibrating LLMs with Semantic-level Reward.
Overview. For each question
The confidence is
| Path | Contents |
|---|---|
csr/ |
Library code: rewards, semantic clustering, judge client, config loader, metrics |
train/ |
Trainers: train_CSR.py, train_RLVR.py, train_RLCR.py, train_RD.py |
evaluation/ |
eval_semantic.py (Base, RLVR, CSR) and eval_verbalized.py (RLCR, RD) |
configs/ |
YAML settings: default.yaml, judge.yaml, models/, methods/, datasets/ |
analysis/ |
Appendix analyses: alternative estimators, aggregation rules, selective prediction |
scripts/ |
serve/serve_judge.sh (local judge server) and f1_judge_eval.py (token-F1 re-clustering) |
rd_util/ |
Rewarding Doubt baseline utilities, kept close to upstream |
All experiments ran on NVIDIA A100 80GB GPUs, one GPU per training or evaluation run,
with Python 3.11, PyTorch 2.9.0 and CUDA 12.8. Install torch first so that pip does not
replace it with another build:
conda create -n csr python=3.11 && conda activate csr
pip install torch==2.9.0 # choose the build for your CUDA
pip install -r requirements.txtRD training needs an older stack (Python 3.10, PyTorch 2.5.1, CUDA 12.4) and runs in a
separate environment. Everything else, including RD evaluation, runs in csr.
conda create -n csr-rd python=3.10 && conda activate csr-rd
pip install torch==2.5.1
pip install -r requirements-rd.txt
pip install "transformers>=4.51.3" "unsloth>=2025.4.7" # only for qwen14b and qwen32bAn LLM judge decides whether an answer matches the gold answer and whether two answers mean the same thing. It is called by CSR and RLVR training, by the periodic validation in RLCR training, and by every evaluation. RD training does not use it.
OpenAI API (default). The paper uses GPT-4.1-nano:
export OPENAI_API_KEY=sk-...Local server. Any model that vLLM serves can act as the judge. Start it on its own
GPU and run training and evaluation on another (e.g. CUDA_VISIBLE_DEVICES=0):
# bash scripts/serve/serve_judge.sh <GPU> <PORT> <HuggingFace model>
bash scripts/serve/serve_judge.sh 1 8310 openai/gpt-oss-20b
JUDGE="--set judge.base_url=http://127.0.0.1:8310/v1 --set judge.model_id=gpt-oss-20b \
--set judge.reasoning_effort=low --set judge.max_tokens=1024"judge.model_id is the last part of the model name. reasoning_effort and the larger
max_tokens are for reasoning models; other models need only base_url and
model_id. The commands below include $JUDGE; with the OpenAI API, leave it unset.
Token-F1 equivalence. Adding --set judge.equivalence=f1 to CSR training or
eval_semantic.py compares rollouts by token F1 instead of the judge. Correctness is
still judged by the LLM. The threshold defaults to the paper's value: 0.80 for qwen and
0.50 for the other models.
| Option | Values |
|---|---|
--method |
Base RLVR CSR RLCR RD |
--model |
llama qwen mistral qwen14b qwen32b |
--dataset |
hotpot trivia msmarco nq_open hotpot_context musique 2wiki_comp |
Base is the untrained model and RLVR trains on correctness alone. RLCR and RD train the
model to state its confidence, with a Brier-score and a log-score reward respectively.
- Main results: train on
hotpot; evaluate onhotpot,trivia,msmarcoandnq_open. - Context-grounded QA: train on
hotpot_context; evaluate onhotpot_context,musiqueand2wiki_comp.
Datasets download from the HuggingFace Hub on first use and are cached under HF_HOME.
Each run merges configs/default.yaml, configs/judge.yaml, configs/models/<model>.yaml,
configs/methods/<method>.yaml and configs/datasets/<dataset>.yaml, in that order, with
later files taking precedence. --set key=value overrides all of them.
Each trainer takes --model, --dataset, --exp-name and --set. Checkpoints are
written to ckpt/<METHOD>/<exp-name>/ and logs to results/<exp-name>/. Give every run
its own --exp-name; otherwise runs of the same method and model share a checkpoint
directory.
# CSR: correctness + semantic calibration reward (weight ramped 0.8 -> 1.2 on a sigmoid)
python train/train_CSR.py --model qwen --dataset hotpot --exp-name CSR_qwen_hotpot $JUDGE
# RLVR: correctness reward only, otherwise identical to CSR
python train/train_RLVR.py --model qwen --dataset hotpot --exp-name RLVR_qwen_hotpot $JUDGE
# RLCR: the published recipe, ported to Unsloth
python train/train_RLCR.py --model qwen --dataset hotpot --exp-name RLCR_qwen_hotpot $JUDGE
# RD: the Rewarding Doubt baseline, in the csr-rd environment
conda activate csr-rd
python train/train_RD.py --model qwen --dataset hotpot --exp-name RD_qwen_hotpot
conda activate csrThe defaults in configs/methods/ reproduce the paper. A few notes:
- RLCR always trains on HotpotQA prompts with supporting paragraphs, as in its original
recipe, whether
--datasetishotpotorhotpot_context. - For
qwen14b, the paper ramps the CSR weight from 0.5 to 0.7:--set method.train.cali_w_start=0.5 --set method.train.cali_w_end=0.7. - For RD on
qwen32b, add--set method.train.ppo_mini_batch_size=2 --set method.train.ppo_gradient_accumulation_steps=2to fit in memory. - Every 0.1 epoch (250 steps; 125 for RD), the trainers score the policy on the
evaluation split. Set
--set method.train.eval_every_steps=0to turn this off.
Each evaluation writes results/<exp-name>/{config.yaml,results.json,results.csv}.
Without --exp-name, the name is <METHOD>_<model>_<dataset>_<checkpoint>, e.g.
CSR_qwen_trivia_checkpoint-2500. The commands below pass the names that the analysis
scripts in Section 6 look for; any other name works too, as long as it differs from the
training run's. An interrupted run resumes from its saved records; --fresh starts over.
Base, RLVR and CSR sample Base takes no --ckpt.
for ds in hotpot trivia msmarco nq_open; do
python evaluation/eval_semantic.py --method Base --model qwen --dataset $ds $JUDGE \
--exp-name Base_qwen7b_${ds}_base_nano_k16
python evaluation/eval_semantic.py --method CSR --model qwen --dataset $ds $JUDGE \
--ckpt ckpt/CSR/CSR_qwen_hotpot/checkpoint-2500 --exp-name CSR_qwen7b_${ds}_z10_step2500_nano_k16
python evaluation/eval_semantic.py --method RLVR --model qwen --dataset $ds $JUDGE \
--ckpt ckpt/RLVR/RLVR_qwen_hotpot/checkpoint-2500 --exp-name RLVR_qwen7b_${ds}_step2500_nano_k16
doneRLCR and RD answer once with greedy decoding and state a confidence, which is parsed from the output.
for ds in hotpot trivia msmarco nq_open; do
python evaluation/eval_verbalized.py --method RLCR --model qwen --dataset $ds $JUDGE \
--ckpt ckpt/RLCR/RLCR_qwen_hotpot/checkpoint-2500 --exp-name RLCR_qwen7b_${ds}_step2500_nano_k1
python evaluation/eval_verbalized.py --method RD --model qwen --dataset $ds $JUDGE \
--ckpt ckpt/RD/RD_qwen_hotpot/model_finetuned_step_1250 --exp-name RD_qwen7b_${ds}_b8_step1250_nano_k1
doneThese scripts re-score finished evaluations for the appendix. They need no GPU and no judge.
| Script | Reports |
|---|---|
analysis/estimators.py |
Semantic Density and SIMBA-UQ's Bayesian aggregation |
analysis/aggregation.py |
SIMBA-UQ's arithmetic aggregation and the clf-pairs+gen classifier (one backbone per call, --model qwen7b etc.) |
analysis/selective.py |
Selective prediction (AURAC, AUGRC) and confidence parse rates (--table selective|parse|all) |
scripts/f1_judge_eval.py |
Token-F1 re-clustering of saved CSR-F1 rollouts |
Semantic Density and clf-pairs+gen also use the mean token log-probability of each
rollout (without it they fall back to uniform weights and drop the +gen feature).
analysis/logprobs_hf.py computes it once per run, on a GPU:
DS="hotpot trivia msmarco nq_open"
python analysis/logprobs_hf.py --model qwen --method Base --datasets $DS
python analysis/logprobs_hf.py --model qwen --method RLVR --datasets $DS \
--ckpt ckpt/RLVR/RLVR_qwen_hotpot/checkpoint-2500
python analysis/logprobs_hf.py --model qwen --method CSR --datasets $DS \
--ckpt ckpt/CSR/CSR_qwen_hotpot/checkpoint-2500For the token-F1 rows, train CSR with --set judge.equivalence=f1, evaluate it as in
Section 5 with --exp-name CSR_qwen7b_${ds}_f1eq080_step2500_nano_k16 (f1eq050
for llama8b and mistral7b), then re-cluster those rollouts with token F1:
python scripts/f1_judge_eval.py --models qwen7bThe scripts find runs through the name templates used above, such as
CSR_{model}_{dataset}_z10_step2500_nano_k16, where {model} is a backbone tag
(llama8b, qwen7b, mistral7b). The templates are defined in analysis/runs.py,
analysis/logprobs_hf.py and scripts/f1_judge_eval.py; edit them if you name runs
differently. Missing or unfinished runs are shown as -- (estimators.py), skip their
backbone (selective.py), or stop the script with a list (aggregation.py).
@inproceedings{csr2026calibrating,
title={Calibrating LLMs with Semantic-level Reward},
author={Yu, Fengfei and Niu, Ruijia and Wu, Dongxia and Ma, Yian and Yu, Rose},
booktitle={NeurIPS},
year={2026}
}This code builds on RLCR, Rewarding Doubt, Unsloth, TRL and vLLM. We thank their authors for releasing their code.
