lievan xzuyn commited on
Commit
66439a9
1 Parent(s): 5ab7ef3

Fix example usage code (#4)

Browse files

- Fix example usage code (6396a8e86c6263a9a940610013414cd8b47bb690)


Co-authored-by: xzuyn <xzuyn@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +12 -8
README.md CHANGED
@@ -34,22 +34,26 @@ Eurus-RM-7B is trained on a mixture of [UltraInteract](https://huggingface.co/da
34
  from transformers import AutoTokenizer, AutoModel
35
  import torch
36
 
 
37
  def test(model_path):
38
- dataset = [ # cases in webgpt; we use the same template as Mistral-Instruct-v0.2
39
- {"chosen":"[INST] Sural relates to which part of the body? [\INST] The sural region is the muscular swelling of the back of the leg below the knee, formed chiefly by the bellies of the gastrocnemius and soleus muscles [1,2].","rejected":"[INST] Sural relates to which part of the body? [\INST] The Sural nerve runs down the side of the leg near the small saphenous vein, then passes forward below the lateral malleolus and continues on the outside of the foot as the lateral dorsal cutaneous nerve, which then communicates with the intermediate dorsal cutaneous nerve, which branches off to the side of the foot. [1]"}
 
 
 
40
  ]
41
 
42
-
43
  tokenizer = AutoTokenizer.from_pretrained(model_path)
44
  model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
45
 
46
  with torch.no_grad():
47
  for example in dataset:
48
- inputs = tokenizer(example["chosen"], return_tensors="pt")
49
- chosen_reward = model(**inputs).item()
50
- inputs = tokenizer(example["rejected"], return_tensors="pt")
51
- rejected_reward = model(**inputs).item()
52
- print(chosen_reward - rejected_reward)
 
53
 
54
  test("openbmb/Eurus-RM-7b")
55
  # Output: 47.4404296875
 
34
  from transformers import AutoTokenizer, AutoModel
35
  import torch
36
 
37
+
38
  def test(model_path):
39
+ dataset = [ # cases in webgpt; we use the same template as Mistral-Instruct-v0.2
40
+ {
41
+ "chosen": "[INST] Sural relates to which part of the body? [\INST] The sural region is the muscular swelling of the back of the leg below the knee, formed chiefly by the bellies of the gastrocnemius and soleus muscles [1,2].",
42
+ "rejected": "[INST] Sural relates to which part of the body? [\INST] The Sural nerve runs down the side of the leg near the small saphenous vein, then passes forward below the lateral malleolus and continues on the outside of the foot as the lateral dorsal cutaneous nerve, which then communicates with the intermediate dorsal cutaneous nerve, which branches off to the side of the foot. [1]",
43
+ }
44
  ]
45
 
 
46
  tokenizer = AutoTokenizer.from_pretrained(model_path)
47
  model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
48
 
49
  with torch.no_grad():
50
  for example in dataset:
51
+ inputs = tokenizer(example["chosen"], return_tensors="pt")
52
+ chosen_reward = model(**inputs).item()
53
+ inputs = tokenizer(example["rejected"], return_tensors="pt")
54
+ rejected_reward = model(**inputs).item()
55
+ print(chosen_reward - rejected_reward)
56
+
57
 
58
  test("openbmb/Eurus-RM-7b")
59
  # Output: 47.4404296875