Views
No views yet
[0.3, 0.74, 0.46, 0.47,-0.33] recommended by Nemotron-4.1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model_name = "LxzGordon/URM-LLaMa-3-8B"
5model = AutoModelForSequenceClassification.from_pretrained(
6 model_name,
7 device_map='auto',
8 trust_remote_code=True,
9)
10tokenizer = AutoTokenizer.from_pretrained(model_name)
11
12prompt = "when were the first Olympic Games held?"
13response1 = "April 1896"
14response2 = "April 1892"
15
16resp1 = [{"role": "user", "content": prompt}, {"role": "assistant", "content": response1}]
17resp2 = [{"role": "user", "content": prompt}, {"role": "assistant", "content": response2}]
18
19# Format and tokenize the conversations
20resp1 = tokenizer.apply_chat_template(resp1, tokenize=False)
21resp2 = tokenizer.apply_chat_template(resp2, tokenize=False)
22resp1 = tokenizer(resp1, return_tensors="pt").to(model.device)
23resp2 = tokenizer(resp2, return_tensors="pt").to(model.device)
24
25with torch.no_grad():
26 score1 = model(resp1['input_ids'],attention_mask=resp1['attention_mask']).logits[0][0].item()
27 score2 = model(resp2['input_ids'],attention_mask=resp2['attention_mask']).logits[0][0].item()
28print(score1,score2)
29
30# Response 1 score: 3.669522523880005, Response 2 score: 2.5036821365356445@article{lou2024uncertainty,
title={Uncertainty-aware Reward Model: Teaching Reward Models to Know What is Unknown},
author={Lou, Xingzhou and Yan, Dong and Shen, Wei and Yan, Yuzi and Xie, Jian and Zhang, Junge},
journal={arXiv preprint arXiv:2410.00847},
year={2024}
}