code: def relation_convert_examples_to_features(
      examples,
      label2id,
      max_seq_length,
      tokenizer,
      special_tokens,
      unused_tokens=True,
  ):
      """
      Loads a data file into a list of `InputBatch`s.
      unused_tokens: whether use [unused1] [unused2] as special tokens
      """
  
      def get_special_token(w):
          if w not in special_tokens:
              if unused_tokens:
                  special_tokens[w] = "[unused%d]" % (
                      len(special_tokens) + 1
                  )
              else:
                  special_tokens[w] = ("<" + w + ">").lower()
          return special_tokens[w]
  
      num_tokens = 0
      max_tokens = 0
      num_fit_examples = 0
      num_shown_examples = 0
      features = []
      for ex_index, example in enumerate(examples):
          if ex_index % 10000 == 0:
              logger.info(
                  "Writing example %d of %d" % (ex_index, len(examples))
              )
  
          tokens = [CLS]
          SUBJECT_START = get_special_token("SUBJ_START")
          SUBJECT_END = get_special_token("SUBJ_END")
          OBJECT_START = get_special_token("OBJ_START")
          OBJECT_END = get_special_token("OBJ_END")
          SUBJECT_NER = get_special_token(
              "SUBJ=%s" % example["subj_type"]
          )
          OBJECT_NER = get_special_token("OBJ=%s" % example["obj_type"])
  
          SUBJECT_START_NER = get_special_token(
              "SUBJ_START=%s" % example["subj_type"]
          )
          SUBJECT_END_NER = get_special_token(
              "SUBJ_END=%s" % example["subj_type"]
          )
          OBJECT_START_NER = get_special_token(
              "OBJ_START=%s" % example["obj_type"]
          )
          OBJECT_END_NER = get_special_token(
              "OBJ_END=%s" % example["obj_type"]
          )
  
          for i, token in enumerate(example["token"]):
              if i == example["subj_start"]:
                  sub_idx = len(tokens)
                  tokens.append(SUBJECT_START_NER)
              if i == example["obj_start"]:
                  obj_idx = len(tokens)
                  tokens.append(OBJECT_START_NER)
              for sub_token in tokenizer.tokenize(token):
                  tokens.append(sub_token)
              if i == example["subj_end"]:
                  tokens.append(SUBJECT_END_NER)
              if i == example["obj_end"]:
                  tokens.append(OBJECT_END_NER)
          tokens.append(SEP)
  
          num_tokens += len(tokens)
          max_tokens = max(max_tokens, len(tokens))
  
          if len(tokens) > max_seq_length:
              tokens = tokens[:max_seq_length]
              if sub_idx >= max_seq_length:
                  sub_idx = 0
              if obj_idx >= max_seq_length:
                  obj_idx = 0
          else:
              num_fit_examples += 1
  
          segment_ids = [0] * len(tokens)
          input_ids = tokenizer.convert_tokens_to_ids(tokens)
          input_mask = [1] * len(input_ids)
          padding = [0] * (max_seq_length - len(input_ids))
          input_ids += padding
          input_mask += padding
          segment_ids += padding
          label_id = label2id[example["relation"]]
          assert len(input_ids) == max_seq_length
          assert len(input_mask) == max_seq_length
          assert len(segment_ids) == max_seq_length
  
          if num_shown_examples < 20:
              if (ex_index < 5) or (label_id > 0):
                  num_shown_examples += 1
                  logger.info("*** Example ***")
                  logger.info("guid: %s" % (example["id"]))
                  logger.info(
                      "tokens: %s" % " ".join([str(x) for x in tokens])
                  )
                  logger.info(
                      "input_ids: %s"
                      % " ".join([str(x) for x in input_ids])
                  )
                  logger.info(
                      "input_mask: %s"
                      % " ".join([str(x) for x in input_mask])
                  )
                  logger.info(
                      "segment_ids: %s"
                      % " ".join([str(x) for x in segment_ids])
                  )
                  logger.info(
                      "label: %s (id = %d)"
                      % (example["relation"], label_id)
                  )
                  logger.info(
                      "sub_idx, obj_idx: %d, %d" % (sub_idx, obj_idx)
                  )
  
          features.append(
              InputFeatures(
                  input_ids=input_ids,
                  input_mask=input_mask,
                  segment_ids=segment_ids,
                  label_id=label_id,
                  sub_idx=sub_idx,
                  obj_idx=obj_idx,
              )
          )
      logger.info(
          "Average #tokens: %.2f" % (num_tokens * 1.0 / len(examples))
      )
      logger.info("Max #tokens: %d" % max_tokens)
      logger.info(
          "%d (%.2f %%) examples can fit max_seq_length = %d"
          % (
              num_fit_examples,
              num_fit_examples * 100.0 / len(examples),
              max_seq_length,
          )
      )
      return features
  
imports: import argparse
  import logging
  import os
  import random
  import time
  import json
  import sys
  import numpy
  import torch
  from torch.utils.data import DataLoader, TensorDataset
  from collections import Counter
  from torch.nn import CrossEntropyLoss
  from transformers.file_utils import PYTORCH_PRETRAINED_BERT_CACHE, WEIGHTS_NAME, CONFIG_NAME
  from transformers import AutoTokenizer
  from transformers import AdamW, get_linear_schedule_with_warmup
  from models.const import *
  from models.data_structures import *
  from models.entityModels import *
  from models.entityUtils import *
  from models.relationModels import *
  from models.relationUtils import *
label_desc: Use image node_id 2 for calling a global function with example usage: relation_convert_examples_to_features(examples, label2id, max_seq_length, tokenizer, special_tokens, unused_tokens) and returns: features, special_tokens