class_docstr: Decorate a perturbation-based attribution algorthm to make it work with dataloaders.
  The decorated instance will calculate attribution in the
  same way as configured in the original attribution instance, but it will provide a
  new "attribute" function which accepts a pytorch "dataloader" instance as the input
  instead of a single batched "tensor" and supports customizing a "reduce" function to
  determine how the forward return of each iteration of the dataloader should be
  aggregated to single metric tensor to attribute. This would
  be specially useful to attribute against some corpus-wise metrics,
  e.g., Precision & Recall.
class_docstr_tok: ["Decorate","a","perturbation-based","attribution","algorthm","to","make","it","work","with","dataloaders",".","The","decorated","instance","will","calculate","attribution","in","the","same","way","as","configured","in","the","original","attribution","instance",",","but","it","will","provide","a","new","``","attribute","''","function","which","accepts","a","pytorch","``","dataloader","''","instance","as","the","input","instead","of","a","single","batched","``","tensor","''","and","supports","customizing","a","``","reduce","''","function","to","determine","how","the","forward","return","of","each","iteration","of","the","dataloader","should","be","aggregated","to","single","metric","tensor","to","attribute",".","This","would","be","specially","useful","to","attribute","against","some","corpus-wise","metrics",",","e.g.",",","Precision","&","Recall","."]
docstr: Args:
      attr_method (Attribution): An instance of any attribution algorithm
                  of type `Attribution`. E.g. Integrated Gradients,
                  Conductance or Saliency.
docstr_tok: ["Args",":","attr_method","(","Attribution",")",":","An","instance","of","any","attribution","algorithm","of","type","`","Attribution","`",".","E.g",".","Integrated","Gradients",",","Conductance","or","Saliency","."]
code: def __init__(self, attr_method: Attribution) -> None:
      r"""
      Args:
          attr_method (Attribution): An instance of any attribution algorithm
                      of type `Attribution`. E.g. Integrated Gradients,
                      Conductance or Saliency.
      """
  
      assert (
          type(attr_method) in SUPPORTED_METHODS
      ), f"DataloaderAttribution does not support {type(attr_method)}"
  
      super().__init__(attr_method.forward_func)
  
      # shallow copy is enough to avoid modifying original instance
      self.attr_method = copy(attr_method)
  
      self.attr_method.forward_func = self._forward_with_dataloader
  
file_path: captum/captum/attr/_core/dataloader_attr.py
imports: from collections import defaultdict
  from copy import copy
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import torch
  from captum._utils.common import _format_baseline, _format_feature_mask, _format_output, _format_tensor_into_tuples, _get_max_feature_index, _run_forward
  from captum._utils.typing import BaselineType
  from captum.attr._core.feature_ablation import FeatureAblation
  from captum.attr._utils.attribution import Attribution
  from torch import Tensor
label_desc: Use image node_id 1 to create a new DataLoaderAttribution object from inherited base classes: Attribution with example: obj = DataLoaderAttribution(attr_method)