The model is trained from
Qwen/Qwen2.5-Math-7B-Instruct on the
SHARP corpus. A
<extra_0> marker is appended to every step,
and a two-way classification head predicts, at each marker, whether the step is correct.
This is the
Step variant: it is supervised with step-level labels, where every reasoning step of the
solution carries its own correct / hallucinated label.
The companion
Span variant, supervised with span-level hallucination annotations, is
Qwen2.5-7B-SHARP-Span.
1import torch
2import torch.nn.functional as F
3from transformers import AutoModel, AutoTokenizer
4
5
6def build_prompt(question, steps):
7 body = "\n\n".join(f"{step.strip()}<extra_0>" for step in steps)
8 return f"Question: {question}\n\nSolution:\n{body}"
9
10
11def make_step_rewards(logits, token_masks):
12 probabilities = F.softmax(logits, dim=-1)
13 probabilities = probabilities * token_masks.unsqueeze(-1) # bs, seq_len, num_labels
14
15 all_scores_res = []
16 for i in range(probabilities.size(0)):
17 sample = probabilities[i] # seq_len, num_labels
18 positive_probs = sample[sample != 0].view(-1, 2)[:, 1] # valid_tokens, num_labels
19 all_scores_res.append(positive_probs.cpu().tolist())
20 return all_scores_res
21
22
23model_name = "ZaandaTeika/Qwen2.5-7B-SHARP-Step"
24
25tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
26model = AutoModel.from_pretrained(
27 model_name,
28 device_map="auto",
29 torch_dtype=torch.bfloat16,
30 trust_remote_code=True,
31).eval()
32
33data = {
34 "question": "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?",
35 "steps": [
36 "In April, Natalia sold 48 clips.",
37 "In May she sold half as many, so she sold 48 / 2 = 24 clips.",
38 "Altogether she sold 48 + 24 = 72 clips. The answer is \\boxed{72}.",
39 ],
40}
41
42prompt = build_prompt(data["question"], data["steps"])
43input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
44
45with torch.no_grad():
46 outputs = model(input_ids=input_ids)
47
48step_sep_id = tokenizer.encode("<extra_0>", add_special_tokens=False)[0]
49token_masks = input_ids == step_sep_id
50step_reward = make_step_rewards(outputs[0], token_masks)
51print(step_reward) # one score per step
This checkpoint is a fine-tuned derivative of
Qwen/Qwen2.5-Math-7B-Instruct,
released under the
Apache 2.0 license.
The weights were modified: the language modelling head was replaced with a two-way
process reward head, and the model was further trained on span-derived step-level
supervision.
Training data comes from the
SHARP
corpus, whose reasoning traces and hallucination annotations are licensed under
CC BY 4.0. SHARP builds on GSM8K and MATH (both MIT); see the dataset card for the
full source attribution.
This checkpoint is released under the
Apache 2.0 license, following its
base model.