code: def construct_input_ref(text, tokenizer, device, mode):
      """For a given text, this function creates token id, reference id and
      attention mask based on encode which is faster for captum insights
      Args:
          text (str): The text specified in the input request
          tokenizer (AutoTokenizer Class Object): To word tokenize the input text
          device (cpu or gpu): Type of the Environment the server runs on.
      Returns:
          input_id(Tensor): It attributes to the tensor of the input tokenized words
          ref_input_ids(Tensor): Ref Input IDs are used as baseline for the attributions
          attention mask() :  The attention mask is a binary tensor indicating the position
           of the padded indices so that the model does not attend to them.
      """
      if mode == "question_answering":
          question_context = ast.literal_eval(text)
          question = question_context["question"]
          context = question_context["context"]
          text_ids = tokenizer.encode(
              question, context, add_special_tokens=False
          )
  
      text_ids = tokenizer.encode(text, add_special_tokens=False)
      # construct input token ids
      logger.info("text_ids %s", text_ids)
      logger.info(
          "[tokenizer.cls_token_id] %s", [tokenizer.cls_token_id]
      )
      input_ids = (
          [tokenizer.cls_token_id] + text_ids + [tokenizer.sep_token_id]
      )
      logger.info("input_ids %s", input_ids)
  
      input_ids = torch.tensor([input_ids], device=device)
      # construct reference token ids
      ref_input_ids = (
          [tokenizer.cls_token_id]
          + [tokenizer.pad_token_id] * len(text_ids)
          + [tokenizer.sep_token_id]
      )
      ref_input_ids = torch.tensor([ref_input_ids], device=device)
      # construct attention mask
      attention_mask = torch.ones_like(input_ids)
      return input_ids, ref_input_ids, attention_mask
  
imports: import ast
  import json
  import logging
  import os
  from abc import ABC
  import torch
  import transformers
  from captum.attr import LayerIntegratedGradients
  from transformers import AutoModelForCausalLM, AutoModelForQuestionAnswering, AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoTokenizer, GPT2TokenizerFast
  from ts.torch_handler.base_handler import BaseHandler
label_desc: Use image node_id 1 for calling a global function with example usage: construct_input_ref(text, tokenizer, device, mode) and returns: input_ids,  ref_input_ids,  attention_mask