Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Replace with your model path
5model_path = "TIGER-Lab/general-verifier"
6
7# Load tokenizer and model
8tokenizer = AutoTokenizer.from_pretrained(model_path)
9model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16).cuda()
10
11# Example inputs
12question = "Factor the following quadratic: $3 x^3+\frac{69 x^2}{2}-36 x-810$"
13ground_truth = "\\frac{3(2x-9)(x+6)(x+10)}{2}"
14student_answer = "\\frac{3}{2}(x+6)(2x-9)(x+10)"
15
16# Create prompt
17prompt = (
18 f"User: ### Question: {question}\n\n"
19 f"### Ground Truth Answer: {ground_truth}\n\n"
20 f"### Student Answer: {student_answer}\n\n"
21 "For the above question, please verify if the student's answer is equivalent to the ground truth answer.\n"
22 "Do not solve the question by yourself; just check if the student's answer is equivalent to the ground truth answer.\n"
23 "If the student's answer is correct, output \"Final Decision: Yes\". If the student's answer is incorrect, output \"Final Decision: No\". Assistant:"
24)
25
26# Tokenize and generate
27inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
28outputs = model.generate(
29 **inputs,
30 max_new_tokens=1024,
31 temperature=0.0,
32 do_sample=False
33)
34
35# Decode and print output
36print(tokenizer.decode(outputs[0], skip_special_tokens=True))