class_docstr: Interprets the prediction using Integrated Gradients (https://arxiv.org/abs/1703.01365)
  
  Registered as a `SaliencyInterpreter` with name "integrated-gradient".
class_docstr_tok: ["Interprets","the","prediction","using","Integrated","Gradients","(","https",":","\/\/arxiv.org\/abs\/1703.01365",")","Registered","as","a","`","SaliencyInterpreter","`","with","name","``","integrated-gradient","''","."]
docstr: Register a forward hook on the embedding layer which scales the embeddings by alpha. Used
  for one term in the Integrated Gradients sum.
  
  We store the embedding output into the embeddings_list when alpha is zero.  This is used
  later to element-wise multiply the input by the averaged gradients.
docstr_tok: ["Register","a","forward","hook","on","the","embedding","layer","which","scales","the","embeddings","by","alpha",".","Used","for","one","term","in","the","Integrated","Gradients","sum",".","We","store","the","embedding","output","into","the","embeddings_list","when","alpha","is","zero",".","This","is","used","later","to","element-wise","multiply","the","input","by","the","averaged","gradients","."]
code: def _register_hooks(
      self, alpha: int, embeddings_list: List, token_offsets: List
  ):
      """
      Register a forward hook on the embedding layer which scales the embeddings by alpha. Used
      for one term in the Integrated Gradients sum.
  
      We store the embedding output into the embeddings_list when alpha is zero.  This is used
      later to element-wise multiply the input by the averaged gradients.
      """
  
      def forward_hook(module, inputs, output):
          # Save the input for later use. Only do so on first call.
          if alpha == 0:
              embeddings_list.append(output.squeeze(0).clone().detach())
  
          # Scale the embedding by alpha
          output.mul_(alpha)
  
      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/integrated_gradient.py
imports: import math
  from typing import List, Dict, Any
  import numpy
  import torch
  from allennlp.common.util import JsonDict, sanitize
  from allennlp.data import Instance
  from allennlp.interpret.saliency_interpreters.saliency_interpreter import SaliencyInterpreter
  from allennlp.nn import util
label_desc: Use image node_id 2 for calling the IntegratedGradient obj's underlying member method code with example usage: obj._register_hooks(alpha, embeddings_list, token_offsets) and returns: handles