class_docstr: Transformers handler class for sequence, token classification and question answering.
docstr: Basic text preprocessing, based on the user's chocie of application mode.
  Args:
      requests (str): The Input data in the form of text is passed on to the preprocess
      function.
  Returns:
      list : The preprocess function returns a list of Tensor for the size of the word tokens.
docstr_tok: ["Basic","text","preprocessing",",","based","on","the","user","'s","chocie","of","application","mode",".","Args",":","requests","(","str",")",":","The","Input","data","in","the","form","of","text","is","passed","on","to","the","preprocess","function",".","Returns",":","list",":","The","preprocess","function","returns","a","list","of","Tensor","for","the","size","of","the","word","tokens","."]
code: def preprocess(self, requests):
      """Basic text preprocessing, based on the user's chocie of application mode.
      Args:
          requests (str): The Input data in the form of text is passed on to the preprocess
          function.
      Returns:
          list : The preprocess function returns a list of Tensor for the size of the word tokens.
      """
      input_ids_batch = None
      attention_mask_batch = None
      for idx, data in enumerate(requests):
          input_text = data.get("data")
          if input_text is None:
              input_text = data.get("body")
          if isinstance(input_text, (bytes, bytearray)):
              input_text = input_text.decode("utf-8")
          if (
              self.setup_config["captum_explanation"]
              and not self.setup_config["mode"] == "question_answering"
          ):
              input_text_target = ast.literal_eval(input_text)
              input_text = input_text_target["text"]
          max_length = self.setup_config["max_length"]
          logger.info("Received text: '%s'", input_text)
          # preprocessing text for sequence_classification, token_classification or text_generation
          if self.setup_config["mode"] in {
              "sequence_classification",
              "token_classification",
              "text_generation",
          }:
              inputs = self.tokenizer.encode_plus(
                  input_text,
                  max_length=int(max_length),
                  pad_to_max_length=True,
                  add_special_tokens=True,
                  return_tensors="pt",
              )
  
          # preprocessing text for question_answering.
          elif self.setup_config["mode"] == "question_answering":
              # TODO Reading the context from a pickeled file or other fromats that
              # fits the requirements of the task in hand. If this is done then need to
              # modify the following preprocessing accordingly.
  
              # the sample text for question_answering in the current version
              # should be formated as dictionary with question and text as keys
              # and related text as values.
              # we use this format here seperate question and text for encoding.
  
              question_context = ast.literal_eval(input_text)
              question = question_context["question"]
              context = question_context["context"]
              inputs = self.tokenizer.encode_plus(
                  question,
                  context,
                  max_length=int(max_length),
                  pad_to_max_length=True,
                  add_special_tokens=True,
                  return_tensors="pt",
              )
          input_ids = inputs["input_ids"].to(self.device)
          attention_mask = inputs["attention_mask"].to(self.device)
          # making a batch out of the recieved requests
          # attention masks are passed for cases where input tokens are padded.
          if input_ids.shape is not None:
              if input_ids_batch is None:
                  input_ids_batch = input_ids
                  attention_mask_batch = attention_mask
              else:
                  input_ids_batch = torch.cat(
                      (input_ids_batch, input_ids), 0
                  )
                  attention_mask_batch = torch.cat(
                      (attention_mask_batch, attention_mask), 0
                  )
      return (input_ids_batch, attention_mask_batch)
  
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 3 for calling the TransformersSeqClassifierHandler obj's underlying member method code with example usage: obj.preprocess(requests) and returns: input_ids_batch,  attention_mask_batch