MCPcopy Create free account
hub / github.com/Ljyustc/SocraticLM / preprocess_function_eval

Function preprocess_function_eval

codes/main.py:221–274  ·  view source on GitHub ↗
(examples)

Source from the content-addressed store, hash-verified

219 max_target_length = data_args.max_target_length
220
221 def preprocess_function_eval(examples):
222 inputs, targets = [], []
223 for i in range(len(examples[prompt_column])):
224 if examples[prompt_column][i] and examples[response_column][i]:
225 query = examples[prompt_column][i]
226 history = (
227 examples[history_column][i] if history_column is not None else None
228 )
229 if 'gsm8k' in data_args.test_file or 'mawps' in data_args.test_file:
230 pre_prompt = "Please analyze and solve the following problem step by step: "
231 # prompt = tokenizer.build_single_message("user", "", message=prefix + pre_prompt + query)
232 # prompt = [tokenizer.get_command("<|user|>")] + tokenizer.encode(
233 # text=prefix + pre_prompt + query,
234 # add_special_tokens=False,
235 # truncation=True,
236 # max_length=data_args.max_source_length,
237 # )
238 prompt = tokenizer.build_single_message('user', "", prefix + pre_prompt + query)
239 prompt += [tokenizer.get_command("<|assistant|>")]
240 else:
241 prompt = tokenizer.build_prompt(query, history)
242 inputs.append(prompt)
243 targets.append(examples[response_column][i])
244
245 if 'gsm8k' in data_args.test_file or 'mawps' in data_args.test_file:
246 model_inputs = tokenizer.batch_encode_plus(
247 inputs,
248 is_split_into_words=True,
249 padding=True,
250 truncation=True,
251 max_length=data_args.max_source_length
252 )
253 # pass
254 else:
255 inputs = [prefix + inp for inp in inputs]
256 model_inputs = tokenizer(
257 inputs,
258 max_length=data_args.max_source_length,
259 truncation=True,
260 padding=True,
261 )
262
263 labels = tokenizer(
264 text_target=targets, max_length=max_target_length, truncation=True
265 )
266
267 if data_args.ignore_pad_token_for_loss:
268 labels["input_ids"] = [
269 [(l if l != tokenizer.pad_token_id else -100) for l in label]
270 for label in labels["input_ids"]
271 ]
272 model_inputs["labels"] = labels["input_ids"]
273
274 return model_inputs
275
276 def preprocess_function_train(examples):
277 max_seq_length = data_args.max_source_length + data_args.max_target_length + 1

Callers

nothing calls this directly

Calls 3

build_single_messageMethod · 0.80
get_commandMethod · 0.80
build_promptMethod · 0.80

Tested by

no test coverage detected