class_docstr: TextClassifier handler class. This handler takes a text (string) and
  as input and returns the classification text based on the model vocabulary.
class_docstr_tok: ["TextClassifier","handler","class",".","This","handler","takes","a","text","(","string",")","and","as","input","and","returns","the","classification","text","based","on","the","model","vocabulary","."]
docstr: Calculates the captum insights
  
  Args:
      text_preprocess (tensor): Tensor of the Text Input
      _ (str): The Raw text data specified in the input request
      target (int): Defaults to 0, the user needs to specify the target
                    for the captum explanation.
  
  Returns:
      (dict): Returns a dictionary of the word token importances
docstr_tok: ["Calculates","the","captum","insights","Args",":","text_preprocess","(","tensor",")",":","Tensor","of","the","Text","Input","_","(","str",")",":","The","Raw","text","data","specified","in","the","input","request","target","(","int",")",":","Defaults","to","0",",","the","user","needs","to","specify","the","target","for","the","captum","explanation",".","Returns",":","(","dict",")",":","Returns","a","dictionary","of","the","word","token","importances"]
code: def get_insights(self, text_preprocess, _, target=0):
      """Calculates the captum insights
  
      Args:
          text_preprocess (tensor): Tensor of the Text Input
          _ (str): The Raw text data specified in the input request
          target (int): Defaults to 0, the user needs to specify the target
                        for the captum explanation.
  
      Returns:
          (dict): Returns a dictionary of the word token importances
      """
      text_tensor, all_tokens = text_preprocess
      token_reference = TokenReferenceBase()
      logger.info("input_text shape %s", len(text_tensor.shape))
      logger.info("get_insights target %s", target)
      offsets = torch.tensor([0]).to(self.device)
  
      all_tokens = self.get_word_token(all_tokens)
      logger.info("text_tensor tokenized shape %s", text_tensor.shape)
      reference_indices = token_reference.generate_reference(
          text_tensor.shape[0], device=self.device
      ).squeeze(0)
      logger.info("reference indices shape %s", reference_indices.shape)
  
      # all_tokens = self.get_word_token(text)
      attributions = self.lig.attribute(
          text_tensor,
          reference_indices,
          additional_forward_args=(offsets),
          return_convergence_delta=False,
          target=target,
      )
  
      logger.info("attributions shape %s", attributions.shape)
      attributions_sum = self.summarize_attributions(attributions)
      response = {}
  
      response["importances"] = attributions_sum.tolist()
      response["words"] = all_tokens
      return [response]
  
file_path: serve/ts/torch_handler/text_classifier.py
imports: import logging
  import torch
  import torch.nn.functional
  from captum.attr import TokenReferenceBase
  from torchtext.data.utils import ngrams_iterator
  from ..utils.util import map_class_to_label
  from .text_handler import TextHandler
label_desc: Use image node_id 4 for calling the TextClassifier obj's underlying member method code with example usage: obj.get_insights(text_preprocess, _, target) and returns: list