MCPcopy Create free account
hub / github.com/GanjinZero/BioBART / preprocess_function

Function preprocess_function

downstream_src/summarization.py:413–431  ·  view source on GitHub ↗
(examples)

Source from the content-addressed store, hash-verified

411 padding = "max_length" if args.pad_to_max_length else False
412
413 def preprocess_function(examples):
414 inputs = examples[text_column]
415 targets = examples[summary_column]
416 inputs = [prefix + inp for inp in inputs]
417 model_inputs = tokenizer(inputs, max_length=args.max_source_length, padding=padding, truncation=True)
418
419 # Setup the tokenizer for targets
420 with tokenizer.as_target_tokenizer():
421 labels = tokenizer(targets, max_length=max_target_length, padding=padding, truncation=True)
422
423 # If we are padding here, replace all tokenizer.pad_token_id in the labels by -100 when we want to ignore
424 # padding in the loss.
425 if padding == "max_length" and args.ignore_pad_token_for_loss:
426 labels["input_ids"] = [
427 [(l if l != tokenizer.pad_token_id else -100) for l in label] for label in labels["input_ids"]
428 ]
429
430 model_inputs["labels"] = labels["input_ids"]
431 return model_inputs
432
433 with accelerator.main_process_first():
434 processed_datasets = raw_datasets.map(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected