class_docstr: Loads a HuggingFace ``transformers`` model and tokenizer.
docstr: Get gradient of loss with respect to input tokens.
  
  Args:
      text_input (str): input string
  Returns:
      Dict of ids, tokens, and gradient as numpy array.
code: def get_grad(self, text_input):
      """Get gradient of loss with respect to input tokens.
  
      Args:
          text_input (str): input string
      Returns:
          Dict of ids, tokens, and gradient as numpy array.
      """
      if isinstance(
          self.model, textattack.models.helpers.T5ForTextToText
      ):
          raise NotImplementedError(
              "`get_grads` for T5FotTextToText has not been implemented yet."
          )
  
      self.model.train()
      embedding_layer = self.model.get_input_embeddings()
      original_state = embedding_layer.weight.requires_grad
      embedding_layer.weight.requires_grad = True
  
      emb_grads = []
  
      def grad_hook(module, grad_in, grad_out):
          emb_grads.append(grad_out[0])
  
      emb_hook = embedding_layer.register_backward_hook(grad_hook)
  
      self.model.zero_grad()
      model_device = next(self.model.parameters()).device
      input_dict = self.tokenizer(
          [text_input],
          add_special_tokens=True,
          return_tensors="pt",
          padding="max_length",
          truncation=True,
      )
      input_dict.to(model_device)
      predictions = self.model(**input_dict).logits
  
      try:
          labels = predictions.argmax(dim=1)
          loss = self.model(**input_dict, labels=labels)[0]
      except TypeError:
          raise TypeError(
              f"{type(self.model)} class does not take in `labels` to calculate loss. "
              "One cause for this might be if you instantiatedyour model using `transformer.AutoModel` "
              "(instead of `transformers.AutoModelForSequenceClassification`)."
          )
  
      loss.backward()
  
      # grad w.r.t to word embeddings
      grad = emb_grads[0][0].cpu().numpy()
  
      embedding_layer.weight.requires_grad = original_state
      emb_hook.remove()
      self.model.eval()
  
      output = {"ids": input_dict["input_ids"], "gradient": grad}
  
      return output
  
file_path: TextAttack/textattack/models/wrappers/huggingface_model_wrapper.py
imports: import torch
  import transformers
  import textattack
  from textattack.models.helpers import T5ForTextToText
  from textattack.models.tokenizers import T5Tokenizer
  from .pytorch_model_wrapper import PyTorchModelWrapper
label_desc: Use image node_id 3 for calling the HuggingFaceModelWrapper obj's underlying member method code with example usage: obj.get_grad(text_input) and returns: output