code: def tensorize_example(self, example, is_training):
      # Keep info to store
      doc_key = example["doc_key"]
      self.stored_info["example"][doc_key] = example
      self.stored_info["subtoken_maps"][doc_key] = example.get(
          "subtoken_map", None
      )
      # self.stored_info['gold'][doc_key] = example['clusters']
  
      is_training = torch.tensor(is_training, dtype=torch.bool)
  
      # Sentences/segments
      input_sentence = copy.deepcopy(example["sentence"])  # Segments
      target_sentence = copy.deepcopy(example["target_sentence"])
  
      cluster_category = copy.deepcopy(example["cluster_category"])
      mention_indice = copy.deepcopy(example["mention_indice"])
  
      sentence_map = torch.tensor(
          example["sentence_map"], dtype=torch.long
      )
  
      input_ids = torch.tensor(
          self.tz.convert_tokens_to_ids(input_sentence),
          dtype=torch.long,
      )
      target_ids = torch.tensor(
          self.tz.convert_tokens_to_ids(target_sentence),
          dtype=torch.long,
      )
      input_len, target_len = input_ids.size(0), target_ids.size(0)
  
      input_mask = torch.tensor([1] * input_len, dtype=torch.long)
      target_mask = torch.tensor([1] * target_len, dtype=torch.long)
  
      action_labels = self.get_action_labels(target_ids)
      mention_indice = torch.tensor(mention_indice, dtype=torch.long)
      cluster_category = torch.tensor(
          cluster_category, dtype=torch.long
      )
  
      linearized_indices = torch.arange(target_len)
  
      is_l = target_ids == self.mention_start_id
      is_r = target_ids == self.mention_end_id
  
      # (num_l)
      l_pos = linearized_indices[is_l]
      # (target_len, num_l)
      distance_to_previous_l = linearized_indices.unsqueeze(
          1
      ) - l_pos.unsqueeze(0)
      # (target_len, num_l)
      is_after_l = distance_to_previous_l > 0
      # (target_len, num_l)
      lr_pair_flag = (
          mention_indice.unsqueeze(1)
          == l_pos.unsqueeze(
              0
          )  # paired brackets are true, otherwise false
      ) & is_after_l  # keeping right after left only
  
      # (num_r)
      r_pos = linearized_indices[is_r]
      # (target_len, num_r)
      distance_to_previous_r = linearized_indices.unsqueeze(
          1
      ) - r_pos.unsqueeze(0)
      # (target_len, num_r)
      is_after_r = distance_to_previous_r > 0
      # (target_len, 1) == (1, num_r) -> (target_len, num_r)
      rr_pair_flag = (
          cluster_category.unsqueeze(1)
          == cluster_category[is_r].unsqueeze(
              0
          )  # right brackets from the same cluster are true, otherwise false
      ) & is_after_r  # keeping right after right only
  
      # One segment per example
      example_tensor = {
          "input_ids": input_ids,
          "input_mask": input_mask,
          "target_ids": target_ids,
          "target_mask": target_mask,
          "action_labels": action_labels,
          "mention_indice": mention_indice,
          "cluster_category": cluster_category,
          "lr_pair_flag": lr_pair_flag,
          "rr_pair_flag": rr_pair_flag,
          "is_training": is_training,
      }
      return doc_key, example_tensor
  
imports: import sys
  import os
  import numpy
  import random
  from transformers import T5Tokenizer
  import os
  from os.path import join
  import json
  import pickle
  import logging
  import torch
  import copy
  import torch
  from torch.utils.data import Dataset, DataLoader
  import torch.nn.functional
  import util
label_desc: Use image node_id 3 for calling the Tensorizer obj's underlying member method code with example usage: obj.tensorize_example(example, is_training) and returns: doc_key,  example_tensor