aashish1904 commited on
Commit
f27d4be
1 Parent(s): 4300954

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +57 -0
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ pipeline_tag: text-generation
5
+ base_model: math-shepherd-mistral-7b-prm
6
+ library_name: transformers
7
+
8
+ ---
9
+
10
+ [![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
11
+
12
+
13
+ # QuantFactory/math-shepherd-mistral-7b-prm-GGUF
14
+ This is quantized version of [peiyi9979/math-shepherd-mistral-7b-prm](https://huggingface.co/peiyi9979/math-shepherd-mistral-7b-prm) created using llama.cpp
15
+
16
+ # Original Model Card
17
+ Process reward model (mistral-7b) used in [Math-Shepherd](https://arxiv.org/pdf/2312.08935.pdf).
18
+
19
+ `Input`: question + step-by-step solutions with a special step tag `ки`, e.g.,
20
+ ```
21
+ Janet\u2019s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes .... ? Step 1: Janet's ducks lay 16 eggs per day. ки\nStep 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left. ки\nStep 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left. ки\nStep 4: She sells the remainder at the farmers' market daily for $2 per fresh duck egg, so she makes 9 * $2 = $18 every day at the farmers' market. The answer is: 18 ки
22
+ ```
23
+ `Output`: the logits. You need to post-process it to achieve the score of each step.
24
+
25
+
26
+ ```python
27
+ from transformers import AutoTokenizer
28
+ from transformers import AutoModelForCausalLM
29
+ import torch
30
+
31
+ good_token = '+'
32
+ bad_token = '-'
33
+ step_tag = 'ки'
34
+
35
+ tokenizer = AutoTokenizer.from_pretrained('peiyi9979/math-shepherd-mistral-7b-prm')
36
+ candidate_tokens = tokenizer.encode(f"{good_token} {bad_token}")[1:] # [648, 387]
37
+ step_tag_id = tokenizer.encode(f"{step_tag}")[-1] # 12902
38
+ model = AutoModelForCausalLM.from_pretrained('peiyi9979/math-shepherd-mistral-7b-prm').eval()
39
+
40
+ question = """Janet\u2019s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?"""
41
+ output1 = """Step 1: Janet's ducks lay 16 eggs per day. ки\nStep 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left. ки\nStep 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left. ки\nStep 4: She sells the remainder at the farmers' market daily for $2 per fresh duck egg, so she makes 9 * $2 = $18 every day at the farmers' market. The answer is: 18 ки""" # 18 is right
42
+ output2 = """Step 1: Janet's ducks lay 16 eggs per day. ки\nStep 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left. ки\nStep 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left. ки\nStep 4: She sells the remainder at the farmers' market daily for $2 per fresh duck egg, so she makes 9 * $2 = $17 every day at the farmers' market. The answer is: 17 ки""" # 17 is wrong
43
+
44
+ for output in [output1, output2]:
45
+ input_for_prm = f"{question} {output}"
46
+ input_id = torch.tensor([tokenizer.encode(input_for_prm)])
47
+
48
+ with torch.no_grad():
49
+ logits = model(input_id).logits[:,:,candidate_tokens]
50
+ scores = logits.softmax(dim=-1)[:,:,0]
51
+ step_scores = scores[input_id == step_tag_id]
52
+ print(step_scores)
53
+
54
+ # tensor([0.9955, 0.9958, 0.9983, 0.9957])
55
+ # tensor([0.9955, 0.9958, 0.9983, 0.0240])
56
+
57
+ ```