1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model = AutoModelForSequenceClassification.from_pretrained(
5 "cyberagent/ca-reward-3b-ja",
6 device_map="auto",
7 num_labels=1,
8)
9tokenizer = AutoTokenizer.from_pretrained("cyberagent/ca-reward-3b-ja")
10
11prompt = """手軽に栄養を補給できる食事を教えてください。"""
12response1 = """栄養補給が手軽にできるものとしては、野菜たっぷりのスムージー、ゆで卵とサラダ、納豆ご飯などがおすすめです。特に納豆は手間なく良質なタンパク質が摂れますよ。お身体を大切にしてくださいね。"""
13response2 = """手軽な栄養補給なら冷凍食品でいいと思います。レンジで温めるだけだし、時間がない時はコンビニ弁当でも悪くないですよ。"""
14
15chat1 = [{"role": "user", "content": prompt}, {"role": "assistant", "content": response1}]
16chat2 = [{"role": "user", "content": prompt}, {"role": "assistant", "content": response2}]
17
18chat1_formatted = tokenizer.apply_chat_template(chat1, tokenize=False)
19chat2_formatted = tokenizer.apply_chat_template(chat2, tokenize=False)
20chat1_tokenized = tokenizer(chat1_formatted, return_tensors="pt", max_length=4096, truncation=True, padding="max_length",).to(model.device)
21chat2_tokenized = tokenizer(chat2_formatted, return_tensors="pt", max_length=4096, truncation=True, padding="max_length",).to(model.device)
22
23with torch.no_grad():
24 chat1_score = model(**chat1_tokenized).logits.item()
25 chat2_score = model(**chat2_tokenized).logits.item()
26
27print(f"Score for response 1: {chat1_score}")
28print(f"Score for response 2: {chat2_score}")
29
30# Score for response 1: 1.2595189809799194
31# Score for response 2: -2.917454242706299
32
1@misc{cyberagent-ca-reward-3b-ja,
2 title={cyberagent/ca-reward-3b-ja},
3 url={https://huggingface.co/cyberagent/ca-reward-3b-ja},
4 author={Ryota Mitsuhashi},
5 year={2025},
6}