class_docstr: A perturbation based approach to computing attribution, involving
  replacing each input feature with a given baseline / reference, and
  computing the difference in output. By default, each scalar value within
  each input tensor is taken as a feature and replaced independently. Passing
  a feature mask, allows grouping features to be ablated together. This can
  be used in cases such as images, where an entire segment or region
  can be ablated, measuring the importance of the segment (feature group).
  Each input scalar in the group will be given the same attribution value
  equal to the change in target as a result of ablating the entire feature
  group.
  
  The forward function can either return a scalar per example or a tensor
  of a fixed sized tensor (or scalar value) for the full batch, i.e. the
  output does not grow as the batch size increase. If the output is fixed
  we consider this model to be an "aggregation" of the inputs. In the fixed
  sized output mode we require `perturbations_per_eval == 1` and the
  `feature_mask` to be either `None` or for all of them to have 1 as their
  first dimension (i.e. a feature mask requires to be applied to all inputs).
class_docstr_tok: ["A","perturbation","based","approach","to","computing","attribution",",","involving","replacing","each","input","feature","with","a","given","baseline","\/","reference",",","and","computing","the","difference","in","output",".","By","default",",","each","scalar","value","within","each","input","tensor","is","taken","as","a","feature","and","replaced","independently",".","Passing","a","feature","mask",",","allows","grouping","features","to","be","ablated","together",".","This","can","be","used","in","cases","such","as","images",",","where","an","entire","segment","or","region","can","be","ablated",",","measuring","the","importance","of","the","segment","(","feature","group",")",".","Each","input","scalar","in","the","group","will","be","given","the","same","attribution","value","equal","to","the","change","in","target","as","a","result","of","ablating","the","entire","feature","group",".","The","forward","function","can","either","return","a","scalar","per","example","or","a","tensor","of","a","fixed","sized","tensor","(","or","scalar","value",")","for","the","full","batch",",","i.e",".","the","output","does","not","grow","as","the","batch","size","increase",".","If","the","output","is","fixed","we","consider","this","model","to","be","an","``","aggregation","''","of","the","inputs",".","In","the","fixed","sized","output","mode","we","require","`","perturbations_per_eval","==","1","`","and","the","`","feature_mask","`","to","be","either","`","None","`","or","for","all","of","them","to","have","1","as","their","first","dimension","(","i.e",".","a","feature","mask","requires","to","be","applied","to","all","inputs",")","."]
docstr: Args:
  
      forward_func (Callable): The forward function of the model or
                  any modification of it.
docstr_tok: ["Args",":","forward_func","(","Callable",")",":","The","forward","function","of","the","model","or","any","modification","of","it","."]
code: def __init__(self, forward_func: Callable) -> None:
      r"""
      Args:
  
          forward_func (Callable): The forward function of the model or
                      any modification of it.
      """
      PerturbationAttribution.__init__(self, forward_func)
      self.use_weights = False
  
      # only used when perturbations_per_eval > 1, where the 1st dim of forward_func's
      # output must grow as the input batch size. If forward's output is aggregated,
      # we cannot expand the input to include more perturbations in one call.
      # If it's False, we will force the validation by comparing the outpus of
      # the original input and the modified input whose batch size expanded based on
      # perturbations_per_eval. Set the flag to True if the output of the modified
      # input grow as expected. Once it turns to True, we will assume the model's
      # behavior stays consistent and no longer check again
      self._is_output_shape_valid = False
  
file_path: captum/captum/attr/_core/feature_ablation.py
imports: import math
  from typing import Any, Callable, cast, Tuple, Union
  import torch
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_feature_mask, _format_output, _is_tuple, _run_forward
  from captum._utils.progress import progress
  from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._utils.attribution import PerturbationAttribution
  from captum.attr._utils.common import _format_input_baseline
  from captum.log import log_usage
  from torch import dtype, Tensor
label_desc: Use image node_id 1 to create a new FeatureAblation object from inherited base classes: PerturbationAttribution with example: obj = FeatureAblation(forward_func)