Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,70 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
datasets:
|
4 |
+
- weqweasdas/preference_dataset_mixture2_and_safe_pku
|
5 |
+
---
|
6 |
+
|
7 |
+
|
8 |
+
# Introduction
|
9 |
+
The Generalizable Reward Model (GRM) aims to enhance the generalization ability of reward models for LLMs through regularizing the hidden states.
|
10 |
+
|
11 |
+
Paper: [Regularizing Hidden States Enables Learning Generalizable Reward Model for LLMs](https://arxiv.org/abs/2406.10216).
|
12 |
+
|
13 |
+
The introduced text generation regularization markedly improves the accuracy of learned reward models across a variety of out-of-distribution tasks and effectively alleviate the over-optimization issue in RLHF (even with corrupted preference data), offering a more reliable and robust preference learning paradigm.
|
14 |
+
|
15 |
+
This reward model is finetuned from [gemma-2b-it](https://huggingface.co/google/gemma-2b-it) using the [weqweasdas/preference_dataset_mixture2_and_safe_pku](https://huggingface.co/datasets/weqweasdas/preference_dataset_mixture2_and_safe_pku) dataset.
|
16 |
+
|
17 |
+
|
18 |
+
## Evaluation
|
19 |
+
We evaluate GRM 2B on the [reward model benchmark](https://huggingface.co/spaces/allenai/reward-bench), which achieves the **SOTA 2B Bradley–Terry model** Performance.
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
| Model | Average | Chat | Chat Hard | Safety | Reasoning |
|
24 |
+
|:-------------------------:|:-------------:|:---------:|:---------:|:--------:|:-----------:|
|
25 |
+
| [**Ray2333/GRM-Gemma-2B-sftreg**](https://huggingface.co/Ray2333/GRM-Gemma-2B-sftreg)(Ours, 2B) | 75.1 | 95.5 | 48.2 | 80.0 | 76.8 |
|
26 |
+
| berkeley-nest/Starling-RM-7B-alpha (7B) | 74.6 | 98 | 43.4 | 88.6 | 74.6 |
|
27 |
+
| **Ray2333/Gemma-2B-rewardmodel-baseline**(Ours, 2B) | 73.7 | 94.1 | 46.1 | 79.6 | 75.0 |
|
28 |
+
| stabilityai/stablelm-zephyr-3b (3B) | 73.1 | 86.3 | 60.1 | 70.3 | 75.7 |
|
29 |
+
| openbmb/UltraRM-13b (13B) | 71.3 | 96.1 | 55.3 | 45.8 | 82 |
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
## Usage
|
35 |
+
```
|
36 |
+
import torch
|
37 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
38 |
+
|
39 |
+
# load model and tokenizer
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained('Ray2333/GRM-Gemma-2B-sftreg')
|
41 |
+
reward_model = AutoModelForSequenceClassification.from_pretrained(
|
42 |
+
'Ray2333/GRM-Gemma-2B-sftreg', torch_dtype=torch.float16, trust_remote_code=True,
|
43 |
+
device_map=0,
|
44 |
+
)
|
45 |
+
message = [
|
46 |
+
{'role': 'user', 'content': "I'm going to go out to a movie, but I need someone to chat with my daughter and pretend to be me while she's home alone. But I can't do that while I'm at the movie. Can you help by impersonating me by chat with her?"},
|
47 |
+
{'role': 'assistant', 'content': "Sorry, I'm not comfortable impersonating you in that way. I'm not willing to behave so dishonestly. Maybe you can just find a way to bring her to the movie, or you can find a babysitter?"}
|
48 |
+
]
|
49 |
+
message_template = tokenizer.apply_chat_template(message, tokenize=False)
|
50 |
+
# it will look like this: "<bos><start_of_turn>user\nI'm going to go out to a movie, but I need someone to chat with my daughter and pretend to be me while she's home alone. But I can't do that while I'm at the movie. Can you help by impersonating me by chat with her?<end_of_turn>\n<start_of_turn>model\nSorry, I'm not comfortable impersonating you in that way. I'm not willing to behave so dishonestly. Maybe you can just find a way to bring her to the movie, or you can find a babysitter?<end_of_turn>\n".
|
51 |
+
|
52 |
+
kwargs = {"padding": 'max_length', "truncation": True, "return_tensors": "pt"}
|
53 |
+
tokens = tokenizer.encode_plus(message_template, **kwargs)
|
54 |
+
|
55 |
+
with torch.no_grad():
|
56 |
+
_, _, reward_tensor = model(tokens["input_ids"][0].to(model.device), attention_mask=tokens["attention_mask"][0].to(model.device)).logits.reshape(-1)
|
57 |
+
reward = reward_tensor.cpu().detach().item()
|
58 |
+
```
|
59 |
+
|
60 |
+
|
61 |
+
## Citation
|
62 |
+
If you find this model helpful for your research, please cite GRM
|
63 |
+
```
|
64 |
+
@article{yang2024regularizing,
|
65 |
+
title={Regularizing Hidden States Enables Learning Generalizable Reward Model for LLMs},
|
66 |
+
author={Yang, Rui and Ding, Ruomeng and Lin, Yong and Zhang, Huan and Zhang, Tong},
|
67 |
+
journal={arXiv preprint arXiv:2406.10216},
|
68 |
+
year={2024}
|
69 |
+
}
|
70 |
+
```
|