reciprocate
commited on
Commit
•
e301d78
1
Parent(s):
e476087
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
---
|
5 |
+
|
6 |
+
```python
|
7 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
8 |
+
|
9 |
+
model_path = "reciprocate/mistral-7b-rm"
|
10 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
12 |
+
reward_fn = pipeline("text-classification", model=model, tokenizer=tokenizer, truncation=True, batch_size=8, max_length=4096, device=0)
|
13 |
+
|
14 |
+
chats = [[
|
15 |
+
{"role": "user", "content": "When was the battle at Waterloo?"},
|
16 |
+
{"role": "assistant", "content": "I think it was in 1983, but please double-check that when you have a chance."}
|
17 |
+
], [
|
18 |
+
{"role": "user", "content": "When was the battle at Waterloo?"},
|
19 |
+
{"role": "assistant", "content": "The battle at Waterloo took place on June 18, 1815."}
|
20 |
+
]]
|
21 |
+
|
22 |
+
output = reward_fn([tokenizer.apply_chat_template(chat, tokenize=False) for chat in chats])
|
23 |
+
scores = [x["score"] for x in output]
|
24 |
+
scores
|
25 |
+
```
|
26 |
+
```
|
27 |
+
>>> [0.2586347758769989, 0.6663259267807007]
|
28 |
+
```
|
29 |
+
|
30 |
+
```python
|
31 |
+
# optionally normalize with the mean and std computed on the training data
|
32 |
+
scores = (np.array(scores) - 2.01098) / 1.69077
|
33 |
+
```
|
34 |
+
|