class_docstr: Registered as a `SaliencyInterpreter` with name "simple-gradient".
docstr: Finds all of the TextFieldEmbedders, and registers a forward hook onto them. When forward()
  is called, embeddings_list is filled with the embedding values. This is necessary because
  our normalization scheme multiplies the gradient by the embedding value.
docstr_tok: ["Finds","all","of","the","TextFieldEmbedders",",","and","registers","a","forward","hook","onto","them",".","When","forward","(",")","is","called",",","embeddings_list","is","filled","with","the","embedding","values",".","This","is","necessary","because","our","normalization","scheme","multiplies","the","gradient","by","the","embedding","value","."]
code: def _register_hooks(self, embeddings_list: List, token_offsets: List):
      """
      Finds all of the TextFieldEmbedders, and registers a forward hook onto them. When forward()
      is called, embeddings_list is filled with the embedding values. This is necessary because
      our normalization scheme multiplies the gradient by the embedding value.
      """
  
      def forward_hook(module, inputs, output):
          embeddings_list.append(output.squeeze(0).clone().detach())
  
      def get_token_offsets(module, inputs, outputs):
          offsets = util.get_token_offsets_from_text_field_inputs(
              inputs
          )
          if offsets is not None:
              token_offsets.append(offsets)
  
      # Register the hooks
      handles = []
      embedding_layer = self.predictor.get_interpretable_layer()
      handles.append(
          embedding_layer.register_forward_hook(forward_hook)
      )
      text_field_embedder = (
          self.predictor.get_interpretable_text_field_embedder()
      )
      handles.append(
          text_field_embedder.register_forward_hook(get_token_offsets)
      )
      return handles
  
file_path: allennlp/allennlp/interpret/saliency_interpreters/simple_gradient.py
imports: import math
  from typing import List
  import numpy
  import torch
  from allennlp.common.util import JsonDict, sanitize
  from allennlp.interpret.saliency_interpreters.saliency_interpreter import SaliencyInterpreter
  from allennlp.nn import util
label_desc: Use image node_id 2 for calling the SimpleGradient obj's underlying member method code with example usage: obj._register_hooks(embeddings_list, token_offsets) and returns: handles