zhao1iang commited on
Commit
9f25ea2
1 Parent(s): 351cd70

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -5
README.md CHANGED
@@ -99,14 +99,32 @@ def special_encode(input, tokenizer):
99
  res_id.append(sep_id)
100
 
101
  return res_id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  if __name__ == '__main__':
103
  text = "小王要将150千克含药量20%的农药稀释成含药量5%的药水.需要加水多少千克?"
104
  text_token_ids = torch.tensor(special_encode(
105
  text, tokenizer)).to(model.device).reshape(1, -1)
106
  response = model.generate(text_token_ids, do_sample=False, max_length=512)
107
- response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True).split(
108
- "[BOT]")[-1].split("[SEP]")[0].strip()
109
- print(response_text)
 
110
  """输出结果:
111
  首先,我们需要计算出150千克含药量20%的农药中含有多少千克的药。\n\n150千克 * 20% = 30千克\n\n然后,我们需要计算出要得到含药量5%的药水,需要多少千克的药水。\n\n30千克 / 5% = 600千克\n\n最后,我们需要计算出需要加多少千克的水。\n\n600千克 - 150千克 = 450千克\n\n所以答案是,小王需要加450千克的水。
112
  """
@@ -141,13 +159,25 @@ def special_encode(input, tokenizer):
141
  res_id.append(sep_id)
142
 
143
  return res_id
 
 
 
 
 
 
 
 
 
 
 
 
144
  if __name__ == '__main__':
145
  text="Janet’s 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?"
146
  text_token_ids = torch.tensor(special_encode(
147
  text, tokenizer)).to(model.device).reshape(1, -1)
148
  response = model.generate(text_token_ids, do_sample=False, max_length=512)
149
- response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True).split(
150
- "[BOT]")[-1].split("[SEP]")[0].strip()
151
  print(response_text)
152
  """Skywork-13B-Math Response:
153
  First, we need to find out how many eggs Janet has left after eating for breakfast and baking for her friends. \n\nShe has 16 eggs per day, eats 3 for breakfast and uses 4 for baking. So, 16 - 3 - 4 = 9 eggs are left for selling at the farmers' market.\n\nSince she sells each egg for $2, she makes 9 * 2 = $<<9*2=18>>18 every day at the farmers' market.\n\nSo, the answer is $18.
@@ -155,6 +185,7 @@ if __name__ == '__main__':
155
  ```
156
 
157
 
 
158
  # 量化部署(Quantization)
159
 
160
  ## 8bit量化(Int8 Quantization)
 
99
  res_id.append(sep_id)
100
 
101
  return res_id
102
+
103
+ def special_encode(input, tokenizer):
104
+ raw_str = "[USER]%s[SEP][BOT]" % input.strip().replace("\r", "")
105
+ eos_id = tokenizer.eos_token_id
106
+ bos_id = tokenizer.bos_token_id
107
+ sep_id = tokenizer.encode("[SEP]")[-1]
108
+ res_id = [eos_id, bos_id]
109
+ arr = raw_str.split("[SEP]")
110
+ for elem_idx in range(len(arr)):
111
+ elem = arr[elem_idx]
112
+ elem_id = tokenizer.encode(elem)[1:]
113
+ res_id += elem_id
114
+ if elem_idx < len(arr) - 1:
115
+ res_id.append(sep_id)
116
+
117
+ return res_id
118
+
119
  if __name__ == '__main__':
120
  text = "小王要将150千克含药量20%的农药稀释成含药量5%的药水.需要加水多少千克?"
121
  text_token_ids = torch.tensor(special_encode(
122
  text, tokenizer)).to(model.device).reshape(1, -1)
123
  response = model.generate(text_token_ids, do_sample=False, max_length=512)
124
+ response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True)
125
+
126
+ response_text = extract_res(response_text)
127
+ print(response_text)
128
  """输出结果:
129
  首先,我们需要计算出150千克含药量20%的农药中含有多少千克的药。\n\n150千克 * 20% = 30千克\n\n然后,我们需要计算出要得到含药量5%的药水,需要多少千克的药水。\n\n30千克 / 5% = 600千克\n\n最后,我们需要计算出需要加多少千克的水。\n\n600千克 - 150千克 = 450千克\n\n所以答案是,小王需要加450千克的水。
130
  """
 
159
  res_id.append(sep_id)
160
 
161
  return res_id
162
+
163
+ def extract_res(response):
164
+ if "[BOT]" in response:
165
+ response = response.split("[BOT]")[1]
166
+ if "<s>" in response:
167
+ response = response.split("<s>")[-1]
168
+ if "</s>" in response:
169
+ response = response.split("</s>")[0]
170
+ if "[SEP]" in response:
171
+ response = response.split("[SEP]")[0]
172
+ return response
173
+
174
  if __name__ == '__main__':
175
  text="Janet’s 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?"
176
  text_token_ids = torch.tensor(special_encode(
177
  text, tokenizer)).to(model.device).reshape(1, -1)
178
  response = model.generate(text_token_ids, do_sample=False, max_length=512)
179
+ response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True)
180
+ response_text = extract_res(response_text)
181
  print(response_text)
182
  """Skywork-13B-Math Response:
183
  First, we need to find out how many eggs Janet has left after eating for breakfast and baking for her friends. \n\nShe has 16 eggs per day, eats 3 for breakfast and uses 4 for baking. So, 16 - 3 - 4 = 9 eggs are left for selling at the farmers' market.\n\nSince she sells each egg for $2, she makes 9 * 2 = $<<9*2=18>>18 every day at the farmers' market.\n\nSo, the answer is $18.
 
185
  ```
186
 
187
 
188
+
189
  # 量化部署(Quantization)
190
 
191
  ## 8bit量化(Int8 Quantization)