3rd-Degree-Burn commited on
Commit
adad33e
·
verified ·
1 Parent(s): a0202d2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -2
README.md CHANGED
@@ -5,8 +5,45 @@ tags: []
5
 
6
  # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
 
12
  ## Model Details
 
5
 
6
  # Model Card for Model ID
7
 
8
+ ```
9
+ rm = trainer.model
10
+ rm.eval()
11
+
12
+ def render_pair_for_scoring(source_text, revision_text):
13
+ messages = [
14
+ {
15
+ "role": "user",
16
+ "content": f"{USER_PREFIX}\n\n{str(source_text).strip()}",
17
+ },
18
+ {
19
+ "role": "assistant",
20
+ "content": f"{ASSISTANT_PREFIX}\n\n{str(revision_text).strip()}",
21
+ },
22
+ ]
23
+ return apply_qwen_template_clean(messages)
24
+
25
+ def reward_score(source_text, revision_text):
26
+ text = render_pair_for_scoring(source_text, revision_text)
27
+ inputs = tokenizer(
28
+ text,
29
+ return_tensors="pt",
30
+ truncation=True,
31
+ max_length=MAX_LENGTH,
32
+ ).to(rm.device)
33
+
34
+ with torch.no_grad():
35
+ logits = rm(**inputs).logits
36
+
37
+ return logits.squeeze().float().item()
38
+
39
+ ```
40
+
41
+ ```
42
+ row = split["test"][0]
43
+
44
+ print("chosen score: ", reward_score(row["prompt"], row["chosen"]))
45
+ print("rejected score:", reward_score(row["prompt"], row["rejected"]))
46
+ ```
47
 
48
 
49
  ## Model Details