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

Function preprocess_function_train_problem_solving

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

Source from the content-addressed store, hash-verified

325 return model_inputs
326
327 def preprocess_function_train_problem_solving(examples):
328 max_seq_length = data_args.max_source_length + data_args.max_target_length + 1
329
330 model_inputs = {
331 "input_ids": [],
332 "labels": [],
333 }
334 for i in range(len(examples[prompt_column])):
335 if examples[prompt_column][i] and examples[response_column][i]:
336 query, answer = examples[prompt_column][i], examples[response_column][i]
337
338 history = (
339 examples[history_column][i] if history_column is not None else None
340 )
341 # pre_prompt = "Please analyze and solve the following problem step by step: "
342 # prompt = " Let's think step by step."
343 # prompt = tokenizer.build_single_message("user", "", message=prefix + query + prompt)
344 # prompt = [tokenizer.get_command("<|user|>")] + tokenizer.encode(
345 # text=prefix + query,
346 # add_special_tokens=False,
347 # truncation=True,
348 # max_length=data_args.max_source_length,
349 # )
350 prompt = tokenizer.build_single_message("user", "", prefix + query)
351 prompt += [tokenizer.get_command("<|assistant|>")]
352 # prompt = tokenizer.build_prompt(query, history)
353 a_ids = prompt
354 b_ids = tokenizer.encode(
355 text=answer,
356 add_special_tokens=False,
357 truncation=True,
358 max_length=data_args.max_target_length,
359 )
360
361 # a_ids = tokenizer.encode(
362 # text=prompt,
363 # add_special_tokens=True,
364 # truncation=True,
365 # max_length=data_args.max_source_length,
366 # )
367 # b_ids = tokenizer.encode(
368 # text=answer,
369 # add_special_tokens=False,
370 # truncation=True,
371 # max_length=data_args.max_target_length,
372 # )
373
374 context_length = len(a_ids)
375 input_ids = a_ids + b_ids + [tokenizer.eos_token_id]
376 labels = (
377 [tokenizer.pad_token_id] * context_length
378 + b_ids
379 + [tokenizer.eos_token_id]
380 )
381
382 pad_len = max_seq_length - len(input_ids)
383 input_ids = input_ids + [tokenizer.pad_token_id] * pad_len
384 labels = labels + [tokenizer.pad_token_id] * pad_len

Callers

nothing calls this directly

Calls 3

build_single_messageMethod · 0.80
get_commandMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected