MCPcopy Create free account
hub / github.com/RingBDStack/GDAP / preprocess_function

Function preprocess_function

run_seq2seq.py:513–539  ·  view source on GitHub ↗
(examples)

Source from the content-addressed store, hash-verified

511 )
512
513 def preprocess_function(examples):
514 if data_args.task.startswith("translation"):
515 inputs = [ex[source_lang] for ex in examples["translation"]]
516 targets = [ex[target_lang] for ex in examples["translation"]]
517 else:
518 inputs = examples[text_column]
519 targets = examples[summary_column]
520
521 inputs = [prefix + inp for inp in inputs] # 在每个句子前面增加 source_prefix 前缀标识
522 model_inputs = tokenizer(
523 inputs, max_length=data_args.max_source_length, padding=padding, truncation=True)
524
525 # Setup the tokenizer for targets
526 # 处理target数据
527 with tokenizer.as_target_tokenizer():
528 labels = tokenizer(
529 targets, max_length=max_target_length, padding=padding, truncation=True)
530
531 # If we are padding here, replace all tokenizer.pad_token_id in the labels by -100 when we want to ignore
532 # padding in the loss.
533 if padding == "max_length" and data_args.ignore_pad_token_for_loss:
534 labels["input_ids"] = [
535 [(l if l != tokenizer.pad_token_id else -100) for l in label] for label in labels["input_ids"] # 用-100来进行填充, -100部分不进行loss的计算
536 ]
537
538 model_inputs["labels"] = labels["input_ids"]
539 return model_inputs
540
541 if training_args.do_train:
542 train_dataset = datasets["train"]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected