code: def truncate_or_pad(sequence, block_size, pad_token_id):
      """Adapt the source and target sequences' lengths to the block size.
      If the sequence is shorter we append padding token to the right of the sequence.
      """
      if len(sequence) > block_size:
          return sequence[:block_size]
      else:
          sequence.extend([pad_token_id] * (block_size - len(sequence)))
          return sequence
  
file_path: transformers/examples/research_projects/bertabs/utils_summarization.py
imports: import os
  from collections import deque
  import torch
  from torch.utils.data import Dataset
label_desc: Use image node_id 3 for calling a global function with example usage: truncate_or_pad(sequence, block_size, pad_token_id) and returns: sequence, sequence