code: def collate(data, tokenizer, block_size, device):
      """Collate formats the data passed to the data loader.
  
      In particular we tokenize the data batch after batch to avoid keeping them
      all in memory. We output the data as a namedtuple to fit the original BertAbs's
      API.
      """
      data = [
          x for x in data if not len(x[1]) == 0
      ]  # remove empty_files
      names = [name for name, _, _ in data]
      summaries = [
          " ".join(summary_list) for _, _, summary_list in data
      ]
  
      encoded_text = [
          encode_for_summarization(story, summary, tokenizer)
          for _, story, summary in data
      ]
      encoded_stories = torch.tensor(
          [
              truncate_or_pad(story, block_size, tokenizer.pad_token_id)
              for story, _ in encoded_text
          ]
      )
      encoder_token_type_ids = compute_token_type_ids(
          encoded_stories, tokenizer.cls_token_id
      )
      encoder_mask = build_mask(encoded_stories, tokenizer.pad_token_id)
  
      batch = Batch(
          document_names=names,
          batch_size=len(encoded_stories),
          src=encoded_stories.to(device),
          segs=encoder_token_type_ids.to(device),
          mask_src=encoder_mask.to(device),
          tgt_str=summaries,
      )
  
      return batch
  
imports: import argparse
  import logging
  import os
  import sys
  from collections import namedtuple
  import torch
  from torch.utils.data import DataLoader, SequentialSampler
  from tqdm import tqdm
  from modeling_bertabs import BertAbs, build_predictor
  from transformers import BertTokenizer
  from .utils_summarization import CNNDMDataset, build_mask, compute_token_type_ids, encode_for_summarization, truncate_or_pad
label_desc: Use image node_id 8 for calling a global function with example usage: collate(data, tokenizer, block_size, device) and returns: batch