code: def select_field_with_padding(data, key1, key2=None, pad_idx=-1):
      max_len = 0
      selected_list = []
      padding_mask = []
      for example in data:
          if key2 is None:
              selected_list.append(example[key1])
              max_len = max(max_len, len(example[key1]))
          else:
              selected_list.append(example[key1][key2])
              max_len = max(max_len, len(example[key1][key2]))
      for i, entry in enumerate(selected_list):
          # pad to max len
          pad_list = [1 for _ in range(len(entry))] + [
              0 for _ in range(max_len - len(entry))
          ]
          selected_list[i] += [
              pad_idx for _ in range(max_len - len(entry))
          ]
          assert len(pad_list) == max_len
          assert len(selected_list[i]) == max_len
          padding_mask.append(pad_list)
      return selected_list, padding_mask
  
file_path: BLINK/elq/biencoder/data_process.py
imports: import os
  import json
  import logging
  import torch
  from tqdm import tqdm, trange
  from torch.utils.data import DataLoader, TensorDataset
  from pytorch_transformers.tokenization_bert import BertTokenizer
  from blink.biencoder.zeshel_utils import world_to_id
  from elq.common.params import ENT_START_TAG, ENT_END_TAG, ENT_TITLE_TAG
label_desc: Use image node_id 1 for calling a global function with example usage: select_field_with_padding(data, key1, key2, pad_idx) and returns: selected_list,  padding_mask