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.
  
  LimeBase provides a generic framework to train a surrogate interpretable model.
  This differs from most other attribution methods, since the method returns a
  representation of the interpretable model (e.g. coefficients of the linear model).
  For a similar interface to other perturbation-based attribution methods, please use
  the Lime child class, which defines specific transformations for the interpretable
  model.
  
  LimeBase allows sampling points in either the interpretable space or the original
  input space to train the surrogate model. The interpretable space is a feature
  vector used to train the surrogate interpretable model; this feature space is often
  of smaller dimensionality than the original feature space in order for the surrogate
  model to be more interpretable.
  
  If sampling in the interpretable space, a transformation function must be provided
  to define how a vector sampled in the interpretable space can be transformed into
  an example in the original input space. If sampling in the original input space, a
  transformation function must be provided to define how the input can be transformed
  into its interpretable vector representation.
  
  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.
  It trains an interpretable model and returns 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 be provided as inputs only if forward_func
  returns a single value per batch (e.g. loss).
  The interpretable feature representation should still have shape
  1 x num_interp_features, corresponding to the interpretable
  representation for the full batch, and perturbations_per_eval
  must be set to 1.
  
  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.
      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. 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
      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
      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
      **kwargs (Any, optional): Any additional arguments necessary for
                  sampling and transformation functions (provided to
                  constructor).
                  Default: None
  
  Returns:
      **interpretable model representation**:
      - **interpretable model representation** (*Any*):
              A representation of the interpretable model trained. The return
              type matches the return type of train_interpretable_model_func.
              For example, this could contain coefficients of a
              linear surrogate model.
  
  Examples::
  
      >>> # SimpleClassifier takes a single input tensor of
      >>> # float features with size N x 5,
      >>> # and returns an Nx3 tensor of class probabilities.
      >>> net = SimpleClassifier()
      >>>
      >>> # We will train an interpretable model with the same
      >>> # features by simply sampling with added Gaussian noise
      >>> # to the inputs and training a model to predict the
      >>> # score of the target class.
      >>>
      >>> # For interpretable model training, we will use sklearn
      >>> # linear model in this example. We have provided wrappers
      >>> # around sklearn linear models to fit the Model interface.
      >>> # Any arguments provided to the sklearn constructor can also
      >>> # be provided to the wrapper, e.g.:
      >>> # SkLearnLinearModel("linear_model.Ridge", alpha=2.0)
      >>> from captum._utils.models.linear_model import SkLearnLinearModel
      >>>
      >>>
      >>> # Define similarity kernel (exponential kernel based on L2 norm)
      >>> def similarity_kernel(
      >>>     original_input: Tensor,
      >>>     perturbed_input: Tensor,
      >>>     perturbed_interpretable_input: Tensor,
      >>>     **kwargs)->Tensor:
      >>>         # kernel_width will be provided to attribute as a kwarg
      >>>         kernel_width = kwargs["kernel_width"]
      >>>         l2_dist = torch.norm(original_input - perturbed_input)
      >>>         return torch.exp(- (l2_dist**2) / (kernel_width**2))
      >>>
      >>>
      >>> # Define sampling function
      >>> # This function samples in original input space
      >>> def perturb_func(
      >>>     original_input: Tensor,
      >>>     **kwargs)->Tensor:
      >>>         return original_input + torch.randn_like(original_input)
      >>>
      >>> # For this example, we are setting the interpretable input to
      >>> # match the model input, so the to_interp_rep_transform
      >>> # function simply returns the input. In most cases, the interpretable
      >>> # input will be different and may have a smaller feature set, so
      >>> # an appropriate transformation function should be provided.
      >>>
      >>> def to_interp_transform(curr_sample, original_inp,
      >>>                                      **kwargs):
      >>>     return curr_sample
      >>>
      >>> # Generating random input with size 1 x 5
      >>> input = torch.randn(1, 5)
      >>> # Defining LimeBase interpreter
      >>> lime_attr = LimeBase(net,
                               SkLearnLinearModel("linear_model.Ridge"),
                               similarity_func=similarity_kernel,
                               perturb_func=perturb_func,
                               perturb_interpretable_space=False,
                               from_interp_rep_transform=None,
                               to_interp_rep_transform=to_interp_transform)
      >>> # Computes interpretable model, returning coefficients of linear
      >>> # model.
      >>> attr_coefs = lime_attr.attribute(input, target=1, kernel_width=1.1)
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",".","It","trains","an","interpretable","model","and","returns","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","be","provided","as","inputs","only","if","forward_func","returns","a","single","value","per","batch","(","e.g",".","loss",")",".","The","interpretable","feature","representation","should","still","have","shape","1","x","num_interp_features",",","corresponding","to","the","interpretable","representation","for","the","full","batch",",","and","perturbations_per_eval","must","be","set","to","1",".","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",".","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",".","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","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","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","*","*","kwargs","(","Any",",","optional",")",":","Any","additional","arguments","necessary","for","sampling","and","transformation","functions","(","provided","to","constructor",")",".","Default",":","None","Returns",":","*","*","interpretable","model","representation","*","*",":","-","*","*","interpretable","model","representation","*","*","(","*","Any","*",")",":","A","representation","of","the","interpretable","model","trained",".","The","return","type","matches","the","return","type","of","train_interpretable_model_func",".","For","example",",","this","could","contain","coefficients","of","a","linear","surrogate","model",".","Examples",":",":",">",">",">","#","SimpleClassifier","takes","a","single","input","tensor","of",">",">",">","#","float","features","with","size","N","x","5",",",">",">",">","#","and","returns","an","Nx3","tensor","of","class","probabilities",".",">",">",">","net","=","SimpleClassifier","(",")",">",">",">",">",">",">","#","We","will","train","an","interpretable","model","with","the","same",">",">",">","#","features","by","simply","sampling","with","added","Gaussian","noise",">",">",">","#","to","the","inputs","and","training","a","model","to","predict","the",">",">",">","#","score","of","the","target","class",".",">",">",">",">",">",">","#","For","interpretable","model","training",",","we","will","use","sklearn",">",">",">","#","linear","model","in","this","example",".","We","have","provided","wrappers",">",">",">","#","around","sklearn","linear","models","to","fit","the","Model","interface",".",">",">",">","#","Any","arguments","provided","to","the","sklearn","constructor","can","also",">",">",">","#","be","provided","to","the","wrapper",",","e.g",".",":",">",">",">","#","SkLearnLinearModel","(","``","linear_model.Ridge","''",",","alpha=2.0",")",">",">",">","from","captum._utils.models.linear_model","import","SkLearnLinearModel",">",">",">",">",">",">",">",">",">","#","Define","similarity","kernel","(","exponential","kernel","based","on","L2","norm",")",">",">",">","def","similarity_kernel","(",">",">",">","original_input",":","Tensor",",",">",">",">","perturbed_input",":","Tensor",",",">",">",">","perturbed_interpretable_input",":","Tensor",",",">",">",">","*","*","kwargs",")","-",">","Tensor",":",">",">",">","#","kernel_width","will","be","provided","to","attribute","as","a","kwarg",">",">",">","kernel_width","=","kwargs","[","``","kernel_width","''","]",">",">",">","l2_dist","=","torch.norm","(","original_input","-","perturbed_input",")",">",">",">","return","torch.exp","(","-","(","l2_dist","*","*","2",")","\/","(","kernel_width","*","*","2",")",")",">",">",">",">",">",">",">",">",">","#","Define","sampling","function",">",">",">","#","This","function","samples","in","original","input","space",">",">",">","def","perturb_func","(",">",">",">","original_input",":","Tensor",",",">",">",">","*","*","kwargs",")","-",">","Tensor",":",">",">",">","return","original_input","+","torch.randn_like","(","original_input",")",">",">",">",">",">",">","#","For","this","example",",","we","are","setting","the","interpretable","input","to",">",">",">","#","match","the","model","input",",","so","the","to_interp_rep_transform",">",">",">","#","function","simply","returns","the","input",".","In","most","cases",",","the","interpretable",">",">",">","#","input","will","be","different","and","may","have","a","smaller","feature","set",",","so",">",">",">","#","an","appropriate","transformation","function","should","be","provided",".",">",">",">",">",">",">","def","to_interp_transform","(","curr_sample",",","original_inp",",",">",">",">","*","*","kwargs",")",":",">",">",">","return","curr_sample",">",">",">",">",">",">","#","Generating","random","input","with","size","1","x","5",">",">",">","input","=","torch.randn","(","1",",","5",")",">",">",">","#","Defining","LimeBase","interpreter",">",">",">","lime_attr","=","LimeBase","(","net",",","SkLearnLinearModel","(","``","linear_model.Ridge","''",")",",","similarity_func=similarity_kernel",",","perturb_func=perturb_func",",","perturb_interpretable_space=False",",","from_interp_rep_transform=None",",","to_interp_rep_transform=to_interp_transform",")",">",">",">","#","Computes","interpretable","model",",","returning","coefficients","of","linear",">",">",">","#","model",".",">",">",">","attr_coefs","=","lime_attr.attribute","(","input",",","target=1",",","kernel_width=1.1",")"]
code: def attribute(
      self,
      inputs: TensorOrTupleOfTensorsGeneric,
      target: TargetType = None,
      additional_forward_args: Any = None,
      n_samples: int = 50,
      perturbations_per_eval: int = 1,
      show_progress: bool = False,
      **kwargs,
  ) -> Tensor:
      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.
      It trains an interpretable model and returns 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 be provided as inputs only if forward_func
      returns a single value per batch (e.g. loss).
      The interpretable feature representation should still have shape
      1 x num_interp_features, corresponding to the interpretable
      representation for the full batch, and perturbations_per_eval
      must be set to 1.
  
      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.
          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. 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
          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
          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
          **kwargs (Any, optional): Any additional arguments necessary for
                      sampling and transformation functions (provided to
                      constructor).
                      Default: None
  
      Returns:
          **interpretable model representation**:
          - **interpretable model representation** (*Any*):
                  A representation of the interpretable model trained. The return
                  type matches the return type of train_interpretable_model_func.
                  For example, this could contain coefficients of a
                  linear surrogate model.
  
      Examples::
  
          >>> # SimpleClassifier takes a single input tensor of
          >>> # float features with size N x 5,
          >>> # and returns an Nx3 tensor of class probabilities.
          >>> net = SimpleClassifier()
          >>>
          >>> # We will train an interpretable model with the same
          >>> # features by simply sampling with added Gaussian noise
          >>> # to the inputs and training a model to predict the
          >>> # score of the target class.
          >>>
          >>> # For interpretable model training, we will use sklearn
          >>> # linear model in this example. We have provided wrappers
          >>> # around sklearn linear models to fit the Model interface.
          >>> # Any arguments provided to the sklearn constructor can also
          >>> # be provided to the wrapper, e.g.:
          >>> # SkLearnLinearModel("linear_model.Ridge", alpha=2.0)
          >>> from captum._utils.models.linear_model import SkLearnLinearModel
          >>>
          >>>
          >>> # Define similarity kernel (exponential kernel based on L2 norm)
          >>> def similarity_kernel(
          >>>     original_input: Tensor,
          >>>     perturbed_input: Tensor,
          >>>     perturbed_interpretable_input: Tensor,
          >>>     **kwargs)->Tensor:
          >>>         # kernel_width will be provided to attribute as a kwarg
          >>>         kernel_width = kwargs["kernel_width"]
          >>>         l2_dist = torch.norm(original_input - perturbed_input)
          >>>         return torch.exp(- (l2_dist**2) / (kernel_width**2))
          >>>
          >>>
          >>> # Define sampling function
          >>> # This function samples in original input space
          >>> def perturb_func(
          >>>     original_input: Tensor,
          >>>     **kwargs)->Tensor:
          >>>         return original_input + torch.randn_like(original_input)
          >>>
          >>> # For this example, we are setting the interpretable input to
          >>> # match the model input, so the to_interp_rep_transform
          >>> # function simply returns the input. In most cases, the interpretable
          >>> # input will be different and may have a smaller feature set, so
          >>> # an appropriate transformation function should be provided.
          >>>
          >>> def to_interp_transform(curr_sample, original_inp,
          >>>                                      **kwargs):
          >>>     return curr_sample
          >>>
          >>> # Generating random input with size 1 x 5
          >>> input = torch.randn(1, 5)
          >>> # Defining LimeBase interpreter
          >>> lime_attr = LimeBase(net,
                                   SkLearnLinearModel("linear_model.Ridge"),
                                   similarity_func=similarity_kernel,
                                   perturb_func=perturb_func,
                                   perturb_interpretable_space=False,
                                   from_interp_rep_transform=None,
                                   to_interp_rep_transform=to_interp_transform)
          >>> # Computes interpretable model, returning coefficients of linear
          >>> # model.
          >>> attr_coefs = lime_attr.attribute(input, target=1, kernel_width=1.1)
      """
      with torch.no_grad():
          inp_tensor = (
              cast(Tensor, inputs)
              if isinstance(inputs, Tensor)
              else inputs[0]
          )
          device = inp_tensor.device
  
          interpretable_inps = []
          similarities = []
          outputs = []
  
          curr_model_inputs = []
          expanded_additional_args = None
          expanded_target = None
          perturb_generator = None
          if inspect.isgeneratorfunction(self.perturb_func):
              perturb_generator = self.perturb_func(inputs, **kwargs)
  
          if show_progress:
              attr_progress = progress(
                  total=math.ceil(n_samples / perturbations_per_eval),
                  desc=f"{self.get_name()} attribution",
              )
              attr_progress.update(0)
  
          batch_count = 0
          for _ in range(n_samples):
              if perturb_generator:
                  try:
                      curr_sample = next(perturb_generator)
                  except StopIteration:
                      warnings.warn(
                          "Generator completed prior to given n_samples iterations!"
                      )
                      break
              else:
                  curr_sample = self.perturb_func(inputs, **kwargs)
              batch_count += 1
              if self.perturb_interpretable_space:
                  interpretable_inps.append(curr_sample)
                  curr_model_inputs.append(
                      self.from_interp_rep_transform(  # type: ignore
                          curr_sample, inputs, **kwargs
                      )
                  )
              else:
                  curr_model_inputs.append(curr_sample)
                  interpretable_inps.append(
                      self.to_interp_rep_transform(  # type: ignore
                          curr_sample, inputs, **kwargs
                      )
                  )
              curr_sim = self.similarity_func(
                  inputs,
                  curr_model_inputs[-1],
                  interpretable_inps[-1],
                  **kwargs,
              )
              similarities.append(
                  curr_sim.flatten()
                  if isinstance(curr_sim, Tensor)
                  else torch.tensor([curr_sim], device=device)
              )
  
              if len(curr_model_inputs) == perturbations_per_eval:
                  if expanded_additional_args is None:
                      expanded_additional_args = (
                          _expand_additional_forward_args(
                              additional_forward_args,
                              len(curr_model_inputs),
                          )
                      )
                  if expanded_target is None:
                      expanded_target = _expand_target(
                          target, len(curr_model_inputs)
                      )
  
                  model_out = self._evaluate_batch(
                      curr_model_inputs,
                      expanded_target,
                      expanded_additional_args,
                      device,
                  )
  
                  if show_progress:
                      attr_progress.update()
  
                  outputs.append(model_out)
  
                  curr_model_inputs = []
  
          if len(curr_model_inputs) > 0:
              expanded_additional_args = (
                  _expand_additional_forward_args(
                      additional_forward_args, len(curr_model_inputs)
                  )
              )
              expanded_target = _expand_target(
                  target, len(curr_model_inputs)
              )
              model_out = self._evaluate_batch(
                  curr_model_inputs,
                  expanded_target,
                  expanded_additional_args,
                  device,
              )
              if show_progress:
                  attr_progress.update()
              outputs.append(model_out)
  
          if show_progress:
              attr_progress.close()
  
          combined_interp_inps = torch.cat(interpretable_inps).float()
          combined_outputs = (
              torch.cat(outputs)
              if len(outputs[0].shape) > 0
              else torch.stack(outputs)
          ).float()
          combined_sim = (
              torch.cat(similarities)
              if len(similarities[0].shape) > 0
              else torch.stack(similarities)
          ).float()
          dataset = TensorDataset(
              combined_interp_inps, combined_outputs, combined_sim
          )
          self.interpretable_model.fit(
              DataLoader(dataset, batch_size=batch_count)
          )
          return self.interpretable_model.representation()
  
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 LimeBase obj's underlying member method code with example usage: obj.attribute(inputs, target, additional_forward_args, n_samples, perturbations_per_eval, show_progress) and returns: self