Update README.md
Browse files
README.md
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
datasets:
|
3 |
+
- PKU-Alignment/PKU-SafeRLHF
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
tags:
|
7 |
+
- reinforcement-learning-from-human-feedback
|
8 |
+
- reinforcement-learning
|
9 |
+
- beaver
|
10 |
+
- safety
|
11 |
+
- llama
|
12 |
+
- ai-safety
|
13 |
+
- deepspeed
|
14 |
+
- rlhf
|
15 |
+
- alpaca
|
16 |
+
library_name: safe-rlhf
|
17 |
+
---
|
18 |
+
|
19 |
+
# 🦫 Beaver's Reward Model
|
20 |
+
|
21 |
+
## Model Details
|
22 |
+
|
23 |
+
The Beaver reward model is a preference model trained using the [PKU-SafeRLHF](https://huggingface.co/datasets/PKU-Alignment/PKU-SafeRLHF) dataset.
|
24 |
+
It can play a role in the safe RLHF algorithm, helping the Beaver model become more helpful.
|
25 |
+
|
26 |
+
- **Developed by:** the [PKU-Alignment](https://github.com/PKU-Alignment) Team.
|
27 |
+
- **Model Type:** An auto-regressive language model based on the transformer architecture.
|
28 |
+
- **License:** Non-commercial license.
|
29 |
+
- **Fine-tuned from model:** [LLaMA](https://arxiv.org/abs/2302.13971), [Alpaca](https://github.com/tatsu-lab/stanford_alpaca).
|
30 |
+
|
31 |
+
## Model Sources
|
32 |
+
|
33 |
+
- **Repository:** <https://github.com/PKU-Alignment/safe-rlhf>
|
34 |
+
- **Beaver:** <https://huggingface.co/PKU-Alignment/beaver-7b-v3.0>
|
35 |
+
- **Dataset:** <https://huggingface.co/datasets/PKU-Alignment/PKU-SafeRLHF>
|
36 |
+
- **Reward Model:** <https://huggingface.co/PKU-Alignment/beaver-7b-unified-reward>
|
37 |
+
- **Cost Model:** <https://huggingface.co/PKU-Alignment/beaver-7b-unified-cost>
|
38 |
+
- **Dataset Paper:** <https://arxiv.org/abs/2307.04657>
|
39 |
+
- **Paper:** <https://arxiv.org/abs/2310.12773>
|
40 |
+
|
41 |
+
## How to Use the Reward Model
|
42 |
+
|
43 |
+
```python
|
44 |
+
import torch
|
45 |
+
from transformers import AutoTokenizer
|
46 |
+
from safe_rlhf.models import AutoModelForScore
|
47 |
+
|
48 |
+
model = AutoModelForScore.from_pretrained('PKU-Alignment/beaver-7b-unified-reward', torch_dtype=torch.bfloat16, device_map='auto')
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained('PKU-Alignment/beaver-7b-unified-reward')
|
50 |
+
|
51 |
+
input = 'BEGINNING OF CONVERSATION: USER: hello ASSISTANT:Hello! How can I help you today?'
|
52 |
+
|
53 |
+
input_ids = tokenizer(input, return_tensors='pt')
|
54 |
+
output = model(**input_ids)
|
55 |
+
print(output)
|
56 |
+
|
57 |
+
# ScoreModelOutput(
|
58 |
+
# scores=tensor([[[-7.2812],
|
59 |
+
# [-0.8203],
|
60 |
+
# [-0.3535],
|
61 |
+
# [-0.5781],
|
62 |
+
# [-0.5781],
|
63 |
+
# [-1.2578],
|
64 |
+
# [-2.9219],
|
65 |
+
# [-2.8594],
|
66 |
+
# [-2.0469],
|
67 |
+
# [-0.8789],
|
68 |
+
# [-1.2422],
|
69 |
+
# [-1.5312],
|
70 |
+
# [-0.7500],
|
71 |
+
# [-1.4688],
|
72 |
+
# [-0.9141],
|
73 |
+
# [-1.0469],
|
74 |
+
# [-1.2266],
|
75 |
+
# [-1.4062],
|
76 |
+
# [-1.4297],
|
77 |
+
# [-1.1016],
|
78 |
+
# [-0.9688],
|
79 |
+
# [ 0.5977],
|
80 |
+
# [ 0.6211],
|
81 |
+
# [ 0.4238],
|
82 |
+
# [ 0.8906],
|
83 |
+
# [ 0.4277],
|
84 |
+
# [ 0.6680],
|
85 |
+
# [ 0.3789]]], grad_fn=<ToCopyBackward0>),
|
86 |
+
# end_scores=tensor([[0.3789]], grad_fn=<ToCopyBackward0>),
|
87 |
+
# last_hidden_state=tensor([[[-0.0552, -0.3203, -0.9180, ..., 0.1719, 0.1309, 0.2988],
|
88 |
+
# [-1.9609, -0.2617, -0.7227, ..., 0.3535, 0.8945, 1.6719],
|
89 |
+
# [-1.1016, -0.3984, -0.3398, ..., 0.5820, 0.9062, 1.6172],
|
90 |
+
# ...,
|
91 |
+
# [-0.4844, 0.1387, -0.6562, ..., 0.3789, 0.2910, 1.5625],
|
92 |
+
# [-0.3125, 0.0811, -0.7969, ..., 0.4688, 0.2344, 1.4453],
|
93 |
+
# [-0.7148, -0.2139, -0.4336, ..., 0.9219, -0.1050, 1.3594]]],
|
94 |
+
# dtype=torch.bfloat16, grad_fn=<ToCopyBackward0>),
|
95 |
+
# end_last_hidden_state=tensor([[-0.7148, -0.2139, -0.4336, ..., 0.9219, -0.1050, 1.3594]],
|
96 |
+
# dtype=torch.bfloat16, grad_fn=<ToCopyBackward0>),
|
97 |
+
# end_index=tensor([27])
|
98 |
+
# )
|
99 |
+
```
|