class_docstr: Lime is an interpretability method that trains an interpretable surrogate model
  by sampling points around a specified input example and using model evaluations
  at these points to train a simpler interpretable 'surrogate' model, such as a
  linear model.
  
  Lime provides a more specific implementation than LimeBase in order to expose
  a consistent API with other perturbation-based algorithms. For more general
  use of the LIME framework, consider using the LimeBase class directly and
  defining custom sampling and transformation to / from interpretable
  representation functions.
  
  Lime assumes that the interpretable representation is a binary vector,
  corresponding to some elements in the input being set to their baseline value
  if the corresponding binary interpretable feature value is 0 or being set
  to the original input value if the corresponding binary interpretable
  feature value is 1. Input values can be grouped to correspond to the same
  binary interpretable feature using a feature mask provided when calling
  attribute, similar to other perturbation-based attribution methods.
  
  One example of this setting is when applying Lime to an image classifier.
  Pixels in an image can be grouped into super-pixels or segments, which
  correspond to interpretable features, provided as a feature_mask when
  calling attribute. Sampled binary vectors convey whether a super-pixel
  is on (retains the original input values) or off (set to the corresponding
  baseline value, e.g. black image). An interpretable linear model is trained
  with input being the binary vectors and outputs as the corresponding scores
  of the image classifier with the appropriate super-pixels masked based on the
  binary vector. Coefficients of the trained surrogate
  linear model convey the importance of each super-pixel.
  
  More details regarding LIME can be found in the original paper:
  https://arxiv.org/abs/1602.04938
docstr: This method attributes the output of the model with given target index
  (in case it is provided, otherwise it assumes that output is a
  scalar) to the inputs of the model using the approach described above,
  training an interpretable model and returning a representation of the
  interpretable model.
  
  It is recommended to only provide a single example as input (tensors
  with first dimension or batch size = 1). This is because LIME is generally
  used for sample-based interpretability, training a separate interpretable
  model to explain a model's prediction on each individual example.
  
  A batch of inputs can also be provided as inputs, similar to
  other perturbation-based attribution methods. In this case, if forward_fn
  returns a scalar per example, attributions will be computed for each
  example independently, with a separate interpretable model trained for each
  example. Note that provided similarity and perturbation functions will be
  provided each example separately (first dimension = 1) in this case.
  If forward_fn returns a scalar per batch (e.g. loss), attributions will
  still be computed using a single interpretable model for the full batch.
  In this case, similarity and perturbation functions will be provided the
  same original input containing the full batch.
  
  The number of interpretable features is determined from the provided
  feature mask, or if none is provided, from the default feature mask,
  which considers each scalar input as a separate feature. It is
  generally recommended to provide a feature mask which groups features
  into a small number of interpretable features / components (e.g.
  superpixels in images).
  
  Args:
  
      inputs (Tensor or tuple[Tensor, ...]): Input for which LIME
                  is computed. If forward_func takes a single
                  tensor as input, a single input tensor should be provided.
                  If forward_func takes multiple tensors as input, a tuple
                  of the input tensors should be provided. It is assumed
                  that for all given input tensors, dimension 0 corresponds
                  to the number of examples, and if multiple input tensors
                  are provided, the examples must be aligned appropriately.
      baselines (scalar, Tensor, tuple of scalar, or Tensor, optional):
                  Baselines define reference value which replaces each
                  feature when the corresponding interpretable feature
                  is set to 0.
                  Baselines can be provided as:
  
                  - a single tensor, if inputs is a single tensor, with
                    exactly the same dimensions as inputs or the first
                    dimension is one and the remaining dimensions match
                    with inputs.
  
                  - a single scalar, if inputs is a single tensor, which will
                    be broadcasted for each input value in input tensor.
  
                  - a tuple of tensors or scalars, the baseline corresponding
                    to each tensor in the inputs' tuple can be:
  
                    - either a tensor with matching dimensions to
                      corresponding tensor in the inputs' tuple
                      or the first dimension is one and the remaining
                      dimensions match with the corresponding
                      input tensor.
  
                    - or a scalar, corresponding to a tensor in the
                      inputs' tuple. This scalar value is broadcasted
                      for corresponding input tensor.
  
                  In the cases when `baselines` is not provided, we internally
                  use zero scalar corresponding to each input tensor.
                  Default: None
      target (int, tuple, Tensor, or list, optional): Output indices for
                  which surrogate model is trained
                  (for classification cases,
                  this is usually the target class).
                  If the network returns a scalar value per example,
                  no target index is necessary.
                  For general 2D outputs, targets can be either:
  
                  - a single integer or a tensor containing a single
                    integer, which is applied to all input examples
  
                  - a list of integers or a 1D tensor, with length matching
                    the number of examples in inputs (dim 0). Each integer
                    is applied as the target for the corresponding example.
  
                  For outputs with > 2 dimensions, targets can be either:
  
                  - A single tuple, which contains #output_dims - 1
                    elements. This target index is applied to all examples.
  
                  - A list of tuples with length equal to the number of
                    examples in inputs (dim 0), and each tuple containing
                    #output_dims - 1 elements. Each tuple is applied as the
                    target for the corresponding example.
  
                  Default: None
      additional_forward_args (Any, optional): If the forward function
                  requires additional arguments other than the inputs for
                  which attributions should not be computed, this argument
                  can be provided. It must be either a single additional
                  argument of a Tensor or arbitrary (non-tuple) type or a
                  tuple containing multiple additional arguments including
                  tensors or any arbitrary python types. These arguments
                  are provided to forward_func in order following the
                  arguments in inputs.
                  For a tensor, the first dimension of the tensor must
                  correspond to the number of examples. It will be
                  repeated for each of `n_steps` along the integrated
                  path. For all other types, the given argument is used
                  for all forward evaluations.
                  Note that attributions are not computed with respect
                  to these arguments.
                  Default: None
      feature_mask (Tensor or tuple[Tensor, ...], optional):
                  feature_mask defines a mask for the input, grouping
                  features which correspond to the same
                  interpretable feature. feature_mask
                  should contain the same number of tensors as inputs.
                  Each tensor should
                  be the same size as the corresponding input or
                  broadcastable to match the input tensor. Values across
                  all tensors should be integers in the range 0 to
                  num_interp_features - 1, and indices corresponding to the
                  same feature should have the same value.
                  Note that features are grouped across tensors
                  (unlike feature ablation and occlusion), so
                  if the same index is used in different tensors, those
                  features are still grouped and added simultaneously.
                  If None, then a feature mask is constructed which assigns
                  each scalar within a tensor as a separate feature.
                  Default: None
      n_samples (int, optional): The number of samples of the original
                  model used to train the surrogate interpretable model.
                  Default: `50` if `n_samples` is not provided.
      perturbations_per_eval (int, optional): Allows multiple samples
                  to be processed simultaneously in one call to forward_fn.
                  Each forward pass will contain a maximum of
                  perturbations_per_eval * #examples samples.
                  For DataParallel models, each batch is split among the
                  available devices, so evaluations on each available
                  device contain at most
                  (perturbations_per_eval * #examples) / num_devices
                  samples.
                  If the forward function returns a single scalar per batch,
                  perturbations_per_eval must be set to 1.
                  Default: 1
      return_input_shape (bool, optional): Determines whether the returned
                  tensor(s) only contain the coefficients for each interp-
                  retable feature from the trained surrogate model, or
                  whether the returned attributions match the input shape.
                  When return_input_shape is True, the return type of attribute
                  matches the input shape, with each element containing the
                  coefficient of the corresponding interpretale feature.
                  All elements with the same value in the feature mask
                  will contain the same coefficient in the returned
                  attributions. If return_input_shape is False, a 1D
                  tensor is returned, containing only the coefficients
                  of the trained interpreatable models, with length
                  num_interp_features.
      show_progress (bool, optional): Displays the progress of computation.
                  It will try to use tqdm if available for advanced features
                  (e.g. time estimation). Otherwise, it will fallback to
                  a simple output of progress.
                  Default: False
  
  Returns:
      *Tensor* or *tuple[Tensor, ...]* of **attributions**:
      - **attributions** (*Tensor* or *tuple[Tensor, ...]*):
                  The attributions with respect to each input feature.
                  If return_input_shape = True, attributions will be
                  the same size as the provided inputs, with each value
                  providing the coefficient of the corresponding
                  interpretale feature.
                  If return_input_shape is False, a 1D
                  tensor is returned, containing only the coefficients
                  of the trained interpreatable models, with length
                  num_interp_features.
  Examples::
  
      >>> # SimpleClassifier takes a single input tensor of size Nx4x4,
      >>> # and returns an Nx3 tensor of class probabilities.
      >>> net = SimpleClassifier()
  
      >>> # Generating random input with size 1 x 4 x 4
      >>> input = torch.randn(1, 4, 4)
  
      >>> # Defining Lime interpreter
      >>> lime = Lime(net)
      >>> # Computes attribution, with each of the 4 x 4 = 16
      >>> # features as a separate interpretable feature
      >>> attr = lime.attribute(input, target=1, n_samples=200)
  
      >>> # Alternatively, we can group each 2x2 square of the inputs
      >>> # as one 'interpretable' feature and perturb them together.
      >>> # This can be done by creating a feature mask as follows, which
      >>> # defines the feature groups, e.g.:
      >>> # +---+---+---+---+
      >>> # | 0 | 0 | 1 | 1 |
      >>> # +---+---+---+---+
      >>> # | 0 | 0 | 1 | 1 |
      >>> # +---+---+---+---+
      >>> # | 2 | 2 | 3 | 3 |
      >>> # +---+---+---+---+
      >>> # | 2 | 2 | 3 | 3 |
      >>> # +---+---+---+---+
      >>> # With this mask, all inputs with the same value are set to their
      >>> # baseline value, when the corresponding binary interpretable
      >>> # feature is set to 0.
      >>> # The attributions can be calculated as follows:
      >>> # feature mask has dimensions 1 x 4 x 4
      >>> feature_mask = torch.tensor([[[0,0,1,1],[0,0,1,1],
      >>>                             [2,2,3,3],[2,2,3,3]]])
  
      >>> # Computes interpretable model and returning attributions
      >>> # matching input shape.
      >>> attr = lime.attribute(input, target=1, feature_mask=feature_mask)
docstr_tok: ["This","method","attributes","the","output","of","the","model","with","given","target","index","(","in","case","it","is","provided",",","otherwise","it","assumes","that","output","is","a","scalar",")","to","the","inputs","of","the","model","using","the","approach","described","above",",","training","an","interpretable","model","and","returning","a","representation","of","the","interpretable","model",".","It","is","recommended","to","only","provide","a","single","example","as","input","(","tensors","with","first","dimension","or","batch","size","=","1",")",".","This","is","because","LIME","is","generally","used","for","sample-based","interpretability",",","training","a","separate","interpretable","model","to","explain","a","model","'s","prediction","on","each","individual","example",".","A","batch","of","inputs","can","also","be","provided","as","inputs",",","similar","to","other","perturbation-based","attribution","methods",".","In","this","case",",","if","forward_fn","returns","a","scalar","per","example",",","attributions","will","be","computed","for","each","example","independently",",","with","a","separate","interpretable","model","trained","for","each","example",".","Note","that","provided","similarity","and","perturbation","functions","will","be","provided","each","example","separately","(","first","dimension","=","1",")","in","this","case",".","If","forward_fn","returns","a","scalar","per","batch","(","e.g",".","loss",")",",","attributions","will","still","be","computed","using","a","single","interpretable","model","for","the","full","batch",".","In","this","case",",","similarity","and","perturbation","functions","will","be","provided","the","same","original","input","containing","the","full","batch",".","The","number","of","interpretable","features","is","determined","from","the","provided","feature","mask",",","or","if","none","is","provided",",","from","the","default","feature","mask",",","which","considers","each","scalar","input","as","a","separate","feature",".","It","is","generally","recommended","to","provide","a","feature","mask","which","groups","features","into","a","small","number","of","interpretable","features","\/","components","(","e.g",".","superpixels","in","images",")",".","Args",":","inputs","(","Tensor","or","tuple","[","Tensor",",","...","]",")",":","Input","for","which","LIME","is","computed",".","If","forward_func","takes","a","single","tensor","as","input",",","a","single","input","tensor","should","be","provided",".","If","forward_func","takes","multiple","tensors","as","input",",","a","tuple","of","the","input","tensors","should","be","provided",".","It","is","assumed","that","for","all","given","input","tensors",",","dimension","0","corresponds","to","the","number","of","examples",",","and","if","multiple","input","tensors","are","provided",",","the","examples","must","be","aligned","appropriately",".","baselines","(","scalar",",","Tensor",",","tuple","of","scalar",",","or","Tensor",",","optional",")",":","Baselines","define","reference","value","which","replaces","each","feature","when","the","corresponding","interpretable","feature","is","set","to","0",".","Baselines","can","be","provided","as",":","-","a","single","tensor",",","if","inputs","is","a","single","tensor",",","with","exactly","the","same","dimensions","as","inputs","or","the","first","dimension","is","one","and","the","remaining","dimensions","match","with","inputs",".","-","a","single","scalar",",","if","inputs","is","a","single","tensor",",","which","will","be","broadcasted","for","each","input","value","in","input","tensor",".","-","a","tuple","of","tensors","or","scalars",",","the","baseline","corresponding","to","each","tensor","in","the","inputs","'","tuple","can","be",":","-","either","a","tensor","with","matching","dimensions","to","corresponding","tensor","in","the","inputs","'","tuple","or","the","first","dimension","is","one","and","the","remaining","dimensions","match","with","the","corresponding","input","tensor",".","-","or","a","scalar",",","corresponding","to","a","tensor","in","the","inputs","'","tuple",".","This","scalar","value","is","broadcasted","for","corresponding","input","tensor",".","In","the","cases","when","`","baselines","`","is","not","provided",",","we","internally","use","zero","scalar","corresponding","to","each","input","tensor",".","Default",":","None","target","(","int",",","tuple",",","Tensor",",","or","list",",","optional",")",":","Output","indices","for","which","surrogate","model","is","trained","(","for","classification","cases",",","this","is","usually","the","target","class",")",".","If","the","network","returns","a","scalar","value","per","example",",","no","target","index","is","necessary",".","For","general","2D","outputs",",","targets","can","be","either",":","-","a","single","integer","or","a","tensor","containing","a","single","integer",",","which","is","applied","to","all","input","examples","-","a","list","of","integers","or","a","1D","tensor",",","with","length","matching","the","number","of","examples","in","inputs","(","dim","0",")",".","Each","integer","is","applied","as","the","target","for","the","corresponding","example",".","For","outputs","with",">","2","dimensions",",","targets","can","be","either",":","-","A","single","tuple",",","which","contains","#","output_dims","-","1","elements",".","This","target","index","is","applied","to","all","examples",".","-","A","list","of","tuples","with","length","equal","to","the","number","of","examples","in","inputs","(","dim","0",")",",","and","each","tuple","containing","#","output_dims","-","1","elements",".","Each","tuple","is","applied","as","the","target","for","the","corresponding","example",".","Default",":","None","additional_forward_args","(","Any",",","optional",")",":","If","the","forward","function","requires","additional","arguments","other","than","the","inputs","for","which","attributions","should","not","be","computed",",","this","argument","can","be","provided",".","It","must","be","either","a","single","additional","argument","of","a","Tensor","or","arbitrary","(","non-tuple",")","type","or","a","tuple","containing","multiple","additional","arguments","including","tensors","or","any","arbitrary","python","types",".","These","arguments","are","provided","to","forward_func","in","order","following","the","arguments","in","inputs",".","For","a","tensor",",","the","first","dimension","of","the","tensor","must","correspond","to","the","number","of","examples",".","It","will","be","repeated","for","each","of","`","n_steps","`","along","the","integrated","path",".","For","all","other","types",",","the","given","argument","is","used","for","all","forward","evaluations",".","Note","that","attributions","are","not","computed","with","respect","to","these","arguments",".","Default",":","None","feature_mask","(","Tensor","or","tuple","[","Tensor",",","...","]",",","optional",")",":","feature_mask","defines","a","mask","for","the","input",",","grouping","features","which","correspond","to","the","same","interpretable","feature",".","feature_mask","should","contain","the","same","number","of","tensors","as","inputs",".","Each","tensor","should","be","the","same","size","as","the","corresponding","input","or","broadcastable","to","match","the","input","tensor",".","Values","across","all","tensors","should","be","integers","in","the","range","0","to","num_interp_features","-","1",",","and","indices","corresponding","to","the","same","feature","should","have","the","same","value",".","Note","that","features","are","grouped","across","tensors","(","unlike","feature","ablation","and","occlusion",")",",","so","if","the","same","index","is","used","in","different","tensors",",","those","features","are","still","grouped","and","added","simultaneously",".","If","None",",","then","a","feature","mask","is","constructed","which","assigns","each","scalar","within","a","tensor","as","a","separate","feature",".","Default",":","None","n_samples","(","int",",","optional",")",":","The","number","of","samples","of","the","original","model","used","to","train","the","surrogate","interpretable","model",".","Default",":","`","50","`","if","`","n_samples","`","is","not","provided",".","perturbations_per_eval","(","int",",","optional",")",":","Allows","multiple","samples","to","be","processed","simultaneously","in","one","call","to","forward_fn",".","Each","forward","pass","will","contain","a","maximum","of","perturbations_per_eval","*","#","examples","samples",".","For","DataParallel","models",",","each","batch","is","split","among","the","available","devices",",","so","evaluations","on","each","available","device","contain","at","most","(","perturbations_per_eval","*","#","examples",")","\/","num_devices","samples",".","If","the","forward","function","returns","a","single","scalar","per","batch",",","perturbations_per_eval","must","be","set","to","1",".","Default",":","1","return_input_shape","(","bool",",","optional",")",":","Determines","whether","the","returned","tensor","(","s",")","only","contain","the","coefficients","for","each","interp-","retable","feature","from","the","trained","surrogate","model",",","or","whether","the","returned","attributions","match","the","input","shape",".","When","return_input_shape","is","True",",","the","return","type","of","attribute","matches","the","input","shape",",","with","each","element","containing","the","coefficient","of","the","corresponding","interpretale","feature",".","All","elements","with","the","same","value","in","the","feature","mask","will","contain","the","same","coefficient","in","the","returned","attributions",".","If","return_input_shape","is","False",",","a","1D","tensor","is","returned",",","containing","only","the","coefficients","of","the","trained","interpreatable","models",",","with","length","num_interp_features",".","show_progress","(","bool",",","optional",")",":","Displays","the","progress","of","computation",".","It","will","try","to","use","tqdm","if","available","for","advanced","features","(","e.g",".","time","estimation",")",".","Otherwise",",","it","will","fallback","to","a","simple","output","of","progress",".","Default",":","False","Returns",":","*","Tensor","*","or","*","tuple","[","Tensor",",","...","]","*","of","*","*","attributions","*","*",":","-","*","*","attributions","*","*","(","*","Tensor","*","or","*","tuple","[","Tensor",",","...","]","*",")",":","The","attributions","with","respect","to","each","input","feature",".","If","return_input_shape","=","True",",","attributions","will","be","the","same","size","as","the","provided","inputs",",","with","each","value","providing","the","coefficient","of","the","corresponding","interpretale","feature",".","If","return_input_shape","is","False",",","a","1D","tensor","is","returned",",","containing","only","the","coefficients","of","the","trained","interpreatable","models",",","with","length","num_interp_features",".","Examples",":",":",">",">",">","#","SimpleClassifier","takes","a","single","input","tensor","of","size","Nx4x4",",",">",">",">","#","and","returns","an","Nx3","tensor","of","class","probabilities",".",">",">",">","net","=","SimpleClassifier","(",")",">",">",">","#","Generating","random","input","with","size","1","x","4","x","4",">",">",">","input","=","torch.randn","(","1",",","4",",","4",")",">",">",">","#","Defining","Lime","interpreter",">",">",">","lime","=","Lime","(","net",")",">",">",">","#","Computes","attribution",",","with","each","of","the","4","x","4","=","16",">",">",">","#","features","as","a","separate","interpretable","feature",">",">",">","attr","=","lime.attribute","(","input",",","target=1",",","n_samples=200",")",">",">",">","#","Alternatively",",","we","can","group","each","2x2","square","of","the","inputs",">",">",">","#","as","one","'interpretable","'","feature","and","perturb","them","together",".",">",">",">","#","This","can","be","done","by","creating","a","feature","mask","as","follows",",","which",">",">",">","#","defines","the","feature","groups",",","e.g",".",":",">",">",">","#","+","--","-+","--","-+","--","-+","--","-+",">",">",">","#","|","0","|","0","|","1","|","1","|",">",">",">","#","+","--","-+","--","-+","--","-+","--","-+",">",">",">","#","|","0","|","0","|","1","|","1","|",">",">",">","#","+","--","-+","--","-+","--","-+","--","-+",">",">",">","#","|","2","|","2","|","3","|","3","|",">",">",">","#","+","--","-+","--","-+","--","-+","--","-+",">",">",">","#","|","2","|","2","|","3","|","3","|",">",">",">","#","+","--","-+","--","-+","--","-+","--","-+",">",">",">","#","With","this","mask",",","all","inputs","with","the","same","value","are","set","to","their",">",">",">","#","baseline","value",",","when","the","corresponding","binary","interpretable",">",">",">","#","feature","is","set","to","0",".",">",">",">","#","The","attributions","can","be","calculated","as","follows",":",">",">",">","#","feature","mask","has","dimensions","1","x","4","x","4",">",">",">","feature_mask","=","torch.tensor","(","[","[","[","0,0,1,1","]",",","[","0,0,1,1","]",",",">",">",">","[","2,2,3,3","]",",","[","2,2,3,3","]","]","]",")",">",">",">","#","Computes","interpretable","model","and","returning","attributions",">",">",">","#","matching","input","shape",".",">",">",">","attr","=","lime.attribute","(","input",",","target=1",",","feature_mask=feature_mask",")"]
code: def attribute(  # type: ignore
      self,
      inputs: TensorOrTupleOfTensorsGeneric,
      baselines: BaselineType = None,
      target: TargetType = None,
      additional_forward_args: Any = None,
      feature_mask: Union[None, Tensor, Tuple[Tensor, ...]] = None,
      n_samples: int = 25,
      perturbations_per_eval: int = 1,
      return_input_shape: bool = True,
      show_progress: bool = False,
  ) -> TensorOrTupleOfTensorsGeneric:
      r"""
      This method attributes the output of the model with given target index
      (in case it is provided, otherwise it assumes that output is a
      scalar) to the inputs of the model using the approach described above,
      training an interpretable model and returning a representation of the
      interpretable model.
  
      It is recommended to only provide a single example as input (tensors
      with first dimension or batch size = 1). This is because LIME is generally
      used for sample-based interpretability, training a separate interpretable
      model to explain a model's prediction on each individual example.
  
      A batch of inputs can also be provided as inputs, similar to
      other perturbation-based attribution methods. In this case, if forward_fn
      returns a scalar per example, attributions will be computed for each
      example independently, with a separate interpretable model trained for each
      example. Note that provided similarity and perturbation functions will be
      provided each example separately (first dimension = 1) in this case.
      If forward_fn returns a scalar per batch (e.g. loss), attributions will
      still be computed using a single interpretable model for the full batch.
      In this case, similarity and perturbation functions will be provided the
      same original input containing the full batch.
  
      The number of interpretable features is determined from the provided
      feature mask, or if none is provided, from the default feature mask,
      which considers each scalar input as a separate feature. It is
      generally recommended to provide a feature mask which groups features
      into a small number of interpretable features / components (e.g.
      superpixels in images).
  
      Args:
  
          inputs (Tensor or tuple[Tensor, ...]): Input for which LIME
                      is computed. If forward_func takes a single
                      tensor as input, a single input tensor should be provided.
                      If forward_func takes multiple tensors as input, a tuple
                      of the input tensors should be provided. It is assumed
                      that for all given input tensors, dimension 0 corresponds
                      to the number of examples, and if multiple input tensors
                      are provided, the examples must be aligned appropriately.
          baselines (scalar, Tensor, tuple of scalar, or Tensor, optional):
                      Baselines define reference value which replaces each
                      feature when the corresponding interpretable feature
                      is set to 0.
                      Baselines can be provided as:
  
                      - a single tensor, if inputs is a single tensor, with
                        exactly the same dimensions as inputs or the first
                        dimension is one and the remaining dimensions match
                        with inputs.
  
                      - a single scalar, if inputs is a single tensor, which will
                        be broadcasted for each input value in input tensor.
  
                      - a tuple of tensors or scalars, the baseline corresponding
                        to each tensor in the inputs' tuple can be:
  
                        - either a tensor with matching dimensions to
                          corresponding tensor in the inputs' tuple
                          or the first dimension is one and the remaining
                          dimensions match with the corresponding
                          input tensor.
  
                        - or a scalar, corresponding to a tensor in the
                          inputs' tuple. This scalar value is broadcasted
                          for corresponding input tensor.
  
                      In the cases when `baselines` is not provided, we internally
                      use zero scalar corresponding to each input tensor.
                      Default: None
          target (int, tuple, Tensor, or list, optional): Output indices for
                      which surrogate model is trained
                      (for classification cases,
                      this is usually the target class).
                      If the network returns a scalar value per example,
                      no target index is necessary.
                      For general 2D outputs, targets can be either:
  
                      - a single integer or a tensor containing a single
                        integer, which is applied to all input examples
  
                      - a list of integers or a 1D tensor, with length matching
                        the number of examples in inputs (dim 0). Each integer
                        is applied as the target for the corresponding example.
  
                      For outputs with > 2 dimensions, targets can be either:
  
                      - A single tuple, which contains #output_dims - 1
                        elements. This target index is applied to all examples.
  
                      - A list of tuples with length equal to the number of
                        examples in inputs (dim 0), and each tuple containing
                        #output_dims - 1 elements. Each tuple is applied as the
                        target for the corresponding example.
  
                      Default: None
          additional_forward_args (Any, optional): If the forward function
                      requires additional arguments other than the inputs for
                      which attributions should not be computed, this argument
                      can be provided. It must be either a single additional
                      argument of a Tensor or arbitrary (non-tuple) type or a
                      tuple containing multiple additional arguments including
                      tensors or any arbitrary python types. These arguments
                      are provided to forward_func in order following the
                      arguments in inputs.
                      For a tensor, the first dimension of the tensor must
                      correspond to the number of examples. It will be
                      repeated for each of `n_steps` along the integrated
                      path. For all other types, the given argument is used
                      for all forward evaluations.
                      Note that attributions are not computed with respect
                      to these arguments.
                      Default: None
          feature_mask (Tensor or tuple[Tensor, ...], optional):
                      feature_mask defines a mask for the input, grouping
                      features which correspond to the same
                      interpretable feature. feature_mask
                      should contain the same number of tensors as inputs.
                      Each tensor should
                      be the same size as the corresponding input or
                      broadcastable to match the input tensor. Values across
                      all tensors should be integers in the range 0 to
                      num_interp_features - 1, and indices corresponding to the
                      same feature should have the same value.
                      Note that features are grouped across tensors
                      (unlike feature ablation and occlusion), so
                      if the same index is used in different tensors, those
                      features are still grouped and added simultaneously.
                      If None, then a feature mask is constructed which assigns
                      each scalar within a tensor as a separate feature.
                      Default: None
          n_samples (int, optional): The number of samples of the original
                      model used to train the surrogate interpretable model.
                      Default: `50` if `n_samples` is not provided.
          perturbations_per_eval (int, optional): Allows multiple samples
                      to be processed simultaneously in one call to forward_fn.
                      Each forward pass will contain a maximum of
                      perturbations_per_eval * #examples samples.
                      For DataParallel models, each batch is split among the
                      available devices, so evaluations on each available
                      device contain at most
                      (perturbations_per_eval * #examples) / num_devices
                      samples.
                      If the forward function returns a single scalar per batch,
                      perturbations_per_eval must be set to 1.
                      Default: 1
          return_input_shape (bool, optional): Determines whether the returned
                      tensor(s) only contain the coefficients for each interp-
                      retable feature from the trained surrogate model, or
                      whether the returned attributions match the input shape.
                      When return_input_shape is True, the return type of attribute
                      matches the input shape, with each element containing the
                      coefficient of the corresponding interpretale feature.
                      All elements with the same value in the feature mask
                      will contain the same coefficient in the returned
                      attributions. If return_input_shape is False, a 1D
                      tensor is returned, containing only the coefficients
                      of the trained interpreatable models, with length
                      num_interp_features.
          show_progress (bool, optional): Displays the progress of computation.
                      It will try to use tqdm if available for advanced features
                      (e.g. time estimation). Otherwise, it will fallback to
                      a simple output of progress.
                      Default: False
  
      Returns:
          *Tensor* or *tuple[Tensor, ...]* of **attributions**:
          - **attributions** (*Tensor* or *tuple[Tensor, ...]*):
                      The attributions with respect to each input feature.
                      If return_input_shape = True, attributions will be
                      the same size as the provided inputs, with each value
                      providing the coefficient of the corresponding
                      interpretale feature.
                      If return_input_shape is False, a 1D
                      tensor is returned, containing only the coefficients
                      of the trained interpreatable models, with length
                      num_interp_features.
      Examples::
  
          >>> # SimpleClassifier takes a single input tensor of size Nx4x4,
          >>> # and returns an Nx3 tensor of class probabilities.
          >>> net = SimpleClassifier()
  
          >>> # Generating random input with size 1 x 4 x 4
          >>> input = torch.randn(1, 4, 4)
  
          >>> # Defining Lime interpreter
          >>> lime = Lime(net)
          >>> # Computes attribution, with each of the 4 x 4 = 16
          >>> # features as a separate interpretable feature
          >>> attr = lime.attribute(input, target=1, n_samples=200)
  
          >>> # Alternatively, we can group each 2x2 square of the inputs
          >>> # as one 'interpretable' feature and perturb them together.
          >>> # This can be done by creating a feature mask as follows, which
          >>> # defines the feature groups, e.g.:
          >>> # +---+---+---+---+
          >>> # | 0 | 0 | 1 | 1 |
          >>> # +---+---+---+---+
          >>> # | 0 | 0 | 1 | 1 |
          >>> # +---+---+---+---+
          >>> # | 2 | 2 | 3 | 3 |
          >>> # +---+---+---+---+
          >>> # | 2 | 2 | 3 | 3 |
          >>> # +---+---+---+---+
          >>> # With this mask, all inputs with the same value are set to their
          >>> # baseline value, when the corresponding binary interpretable
          >>> # feature is set to 0.
          >>> # The attributions can be calculated as follows:
          >>> # feature mask has dimensions 1 x 4 x 4
          >>> feature_mask = torch.tensor([[[0,0,1,1],[0,0,1,1],
          >>>                             [2,2,3,3],[2,2,3,3]]])
  
          >>> # Computes interpretable model and returning attributions
          >>> # matching input shape.
          >>> attr = lime.attribute(input, target=1, feature_mask=feature_mask)
      """
      return self._attribute_kwargs(
          inputs=inputs,
          baselines=baselines,
          target=target,
          additional_forward_args=additional_forward_args,
          feature_mask=feature_mask,
          n_samples=n_samples,
          perturbations_per_eval=perturbations_per_eval,
          return_input_shape=return_input_shape,
          show_progress=show_progress,
      )
  
imports: import inspect
  import math
  import typing
  import warnings
  from typing import Any, Callable, cast, List, Optional, Tuple, Union
  import torch
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _flatten_tensor_or_tuple, _format_output, _format_tensor_into_tuples, _get_max_feature_index, _is_tuple, _reduce_list, _run_forward
  from captum._utils.models.linear_model import SkLearnLasso
  from captum._utils.models.model import Model
  from captum._utils.progress import progress
  from captum._utils.typing import BaselineType, Literal, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._utils.attribution import PerturbationAttribution
  from captum.attr._utils.batching import _batch_example_iterator
  from captum.attr._utils.common import _construct_default_feature_mask, _format_input_baseline
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import CosineSimilarity
  from torch.utils.data import DataLoader, TensorDataset
label_desc: Use image node_id 2 for calling the Lime obj's underlying member method code with example usage: obj.attribute(inputs, baselines, target, additional_forward_args, feature_mask, n_samples, perturbations_per_eval, return_input_shape, show_progress) and returns: self