class_docstr: Registered as an `InfluenceInterpreter` with name "simple-influence".
  
  This goes through every example in the train set to calculate the influence score. It uses
  [LiSSA (Linear time Stochastic Second-Order Algorithm)](https://api.semanticscholar.org/CorpusID:10569090)
  to approximate the inverse of the Hessian used for the influence score calculation.
  
  # Parameters
  
  lissa_batch_size : `int`, optional (default = `8`)
      The batch size to use for LiSSA.
      According to [Koh, P.W., & Liang, P. (2017)](https://api.semanticscholar.org/CorpusID:13193974),
      it is better to use batched samples for approximation for better stability.
  
  damping : `float`, optional (default = `3e-3`)
      This is a hyperparameter for LiSSA.
      A damping termed added in case the approximated Hessian (during LiSSA) has
      negative eigenvalues.
  
  num_samples : `int`, optional (default = `1`)
      This is a hyperparameter for LiSSA that we
      determine how many rounds of the recursion process we would like to run for approxmation.
  
  recursion_depth : `Union[float, int]`, optional (default = `0.25`)
      This is a hyperparameter for LiSSA that
      determines the recursion depth we would like to go through.
      If a `float`, it means X% of the training examples.
      If an `int`, it means recurse for X times.
  
  scale : `float`, optional, (default = `1e4`)
      This is a hyperparameter for LiSSA to tune such that the Taylor expansion converges.
      It is applied to scale down the loss during LiSSA to ensure that `H <= I`,
      where `H` is the Hessian and `I` is the identity matrix.
  
      See footnote 2 of [Koh, P.W., & Liang, P. (2017)](https://api.semanticscholar.org/CorpusID:13193974).
  
  !!! Note
      We choose the same default values for the LiSSA hyperparameters as
      [Han, Xiaochuang et al. (2020)](https://api.semanticscholar.org/CorpusID:218628619).
class_docstr_tok: ["Registered","as","an","`","InfluenceInterpreter","`","with","name","``","simple-influence","''",".","This","goes","through","every","example","in","the","train","set","to","calculate","the","influence","score",".","It","uses","[","LiSSA","(","Linear","time","Stochastic","Second-Order","Algorithm",")","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:10569090",")","to","approximate","the","inverse","of","the","Hessian","used","for","the","influence","score","calculation",".","#","Parameters","lissa_batch_size",":","`","int","`",",","optional","(","default","=","`","8","`",")","The","batch","size","to","use","for","LiSSA",".","According","to","[","Koh",",","P.W.",",","&","Liang",",","P.","(","2017",")","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:13193974",")",",","it","is","better","to","use","batched","samples","for","approximation","for","better","stability",".","damping",":","`","float","`",",","optional","(","default","=","`","3e-3","`",")","This","is","a","hyperparameter","for","LiSSA",".","A","damping","termed","added","in","case","the","approximated","Hessian","(","during","LiSSA",")","has","negative","eigenvalues",".","num_samples",":","`","int","`",",","optional","(","default","=","`","1","`",")","This","is","a","hyperparameter","for","LiSSA","that","we","determine","how","many","rounds","of","the","recursion","process","we","would","like","to","run","for","approxmation",".","recursion_depth",":","`","Union","[","float",",","int","]","`",",","optional","(","default","=","`","0.25","`",")","This","is","a","hyperparameter","for","LiSSA","that","determines","the","recursion","depth","we","would","like","to","go","through",".","If","a","`","float","`",",","it","means","X","%","of","the","training","examples",".","If","an","`","int","`",",","it","means","recurse","for","X","times",".","scale",":","`","float","`",",","optional",",","(","default","=","`","1e4","`",")","This","is","a","hyperparameter","for","LiSSA","to","tune","such","that","the","Taylor","expansion","converges",".","It","is","applied","to","scale","down","the","loss","during","LiSSA","to","ensure","that","`","H","<","=","I","`",",","where","`","H","`","is","the","Hessian","and","`","I","`","is","the","identity","matrix",".","See","footnote","2","of","[","Koh",",","P.W.",",","&","Liang",",","P.","(","2017",")","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:13193974",")",".","!","!","!","Note","We","choose","the","same","default","values","for","the","LiSSA","hyperparameters","as","[","Han",",","Xiaochuang","et","al",".","(","2020",")","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:218628619",")","."]
code: def _calculate_influence_scores(
      self,
      test_instance: Instance,
      test_loss: float,
      test_grads: Sequence[torch.Tensor],
  ) -> List[float]:
      # Approximate the inverse of Hessian-Vector Product through LiSSA
      inv_hvp = get_inverse_hvp_lissa(
          test_grads,
          self.model,
          self.used_params,
          self._lissa_dataloader,
          self._damping,
          self._num_samples,
          self._scale,
      )
      return [
          # dL_test * d theta as in 2.2 of [https://arxiv.org/pdf/2005.06676.pdf]
          # TODO (epwalsh): should we divide `x.grads` by `self._scale`?
          torch.dot(inv_hvp, _flatten_tensors(x.grads)).item()
          for x in Tqdm.tqdm(
              self.train_instances, desc="scoring train instances"
          )
      ]
  
file_path: allennlp/allennlp/interpret/influence_interpreters/simple_influence.py
imports: import logging
  from typing import List, Optional, Tuple, Union, Sequence
  import numpy
  import torch
  import torch.autograd
  from allennlp.common import Lazy
  from allennlp.common.tqdm import Tqdm
  from allennlp.data import DatasetReader, DatasetReaderInput, Instance
  from allennlp.data.data_loaders import DataLoader, SimpleDataLoader
  from allennlp.interpret.influence_interpreters.influence_interpreter import InfluenceInterpreter
  from allennlp.models.model import Model
label_desc: Use image node_id 2 for calling the SimpleInfluence obj's underlying member method code with example usage: obj._calculate_influence_scores(test_instance, test_loss, test_grads) and returns: unknown