File size: 977 Bytes
726d19f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
---
language:
- en
---

```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline

model_path = "reciprocate/rm-beluga-7b-hh-full"

model = AutoModelForSequenceClassification.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
# for SequenceClassification models padding side should be "right"
tokenizer.padding_side = "right"
tokenizer.truncation_side = "left"
reward_fn = pipeline("text-classification", model=model, tokenizer=tokenizer, truncation=True, batch_size=32, max_length=2048, device=0)
output = reward_fn(["### User: Complete this sentence: I'm 99 percent sure it was someone being an...\n\n### Assistant:\n I'm 99 percent sure it was someone being an idiot.</s>"])
scores = [x["score"] for x in output]
scores
```
```
>>> [0.02713249810039997]
```

```python
# optionally normalize with mean, std computed on training data
scores = (np.array(scores) - 0.6816716283619826) / 0.3198637874065531
```