class_docstr: Interprets the prediction using SmoothGrad (https://arxiv.org/abs/1706.03825)
  
  Registered as a `SaliencyInterpreter` with name "smooth-gradient".
class_docstr_tok: ["Interprets","the","prediction","using","SmoothGrad","(","https",":","\/\/arxiv.org\/abs\/1706.03825",")","Registered","as","a","`","SaliencyInterpreter","`","with","name","``","smooth-gradient","''","."]
code: def _smooth_grads(
      self, instance: Instance
  ) -> Dict[str, numpy.ndarray]:
      total_gradients: Dict[str, Any] = {}
      for _ in range(self.num_samples):
          handle = self._register_forward_hook(self.stdev)
          try:
              grads = self.predictor.get_gradients([instance])[0]
          finally:
              handle.remove()
  
          # Sum gradients
          if total_gradients == {}:
              total_gradients = grads
          else:
              for key in grads.keys():
                  total_gradients[key] += grads[key]
  
      # Average the gradients
      for key in total_gradients.keys():
          total_gradients[key] /= self.num_samples
  
      return total_gradients
  
file_path: allennlp/allennlp/interpret/saliency_interpreters/smooth_gradient.py
imports: import math
  from typing import 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.predictors import Predictor
label_desc: Use image node_id 4 for calling the SmoothGradient obj's underlying member method code with example usage: obj._smooth_grads(instance) and returns: total_gradients