class_docstr: A `Captum <https://captum.ai>`__-based explainer for identifying compact
  subgraph structures and node features that play a crucial role in the
  predictions made by a GNN.
  
  This explainer algorithm uses :captum:`null` `Captum <https://captum.ai/>`_
  to compute attributions.
  
  Currently, the following attribution methods are supported:
  
  * :class:`captum.attr.IntegratedGradients`
  * :class:`captum.attr.Saliency`
  * :class:`captum.attr.InputXGradient`
  * :class:`captum.attr.Deconvolution`
  * :class:`captum.attr.ShapleyValueSampling`
  * :class:`captum.attr.GuidedBackprop`
  
  Args:
      attribution_method (Attribution or str): The Captum attribution method
          to use. Can be a string or a :class:`captum.attr` method.
      **kwargs: Additional arguments for the Captum attribution method.
class_docstr_tok: ["A","`","Captum","<","https",":","\/\/captum.ai",">","`","__-based","explainer","for","identifying","compact","subgraph","structures","and","node","features","that","play","a","crucial","role","in","the","predictions","made","by","a","GNN",".","This","explainer","algorithm","uses",":","captum",":","`","null","`","`","Captum","<","https",":","\/\/captum.ai\/",">","`","_","to","compute","attributions",".","Currently",",","the","following","attribution","methods","are","supported",":","*",":","class",":","`","captum.attr.IntegratedGradients","`","*",":","class",":","`","captum.attr.Saliency","`","*",":","class",":","`","captum.attr.InputXGradient","`","*",":","class",":","`","captum.attr.Deconvolution","`","*",":","class",":","`","captum.attr.ShapleyValueSampling","`","*",":","class",":","`","captum.attr.GuidedBackprop","`","Args",":","attribution_method","(","Attribution","or","str",")",":","The","Captum","attribution","method","to","use",".","Can","be","a","string","or","a",":","class",":","`","captum.attr","`","method",".","*","*","kwargs",":","Additional","arguments","for","the","Captum","attribution","method","."]
code: def forward(
      self,
      model: torch.nn.Module,
      x: Union[Tensor, Dict[NodeType, Tensor]],
      edge_index: Union[Tensor, Dict[EdgeType, Tensor]],
      *,
      target: Tensor,
      index: Optional[Union[int, Tensor]] = None,
      **kwargs,
  ) -> Union[Explanation, HeteroExplanation]:
      mask_type = self._get_mask_type()
  
      inputs, add_forward_args = to_captum_input(
          x,
          edge_index,
          mask_type,
          *kwargs.values(),
      )
  
      if isinstance(x, dict):  # Heterogeneous GNN:
          metadata = (list(x.keys()), list(edge_index.keys()))
          captum_model = CaptumHeteroModel(
              model,
              mask_type,
              index,
              metadata,
              self.model_config,
          )
      else:  # Homogeneous GNN:
          metadata = None
          captum_model = CaptumModel(
              model,
              mask_type,
              index,
              self.model_config,
          )
  
      self.attribution_method_instance = self.attribution_method_class(
          captum_model
      )
  
      # In Captum, the target is the class index for which the attribution is
      # computed. Within CaptumModel, we transform the binary classification
      # into a multi-class classification task.
      if self.model_config.mode == ModelMode.regression:
          target = None
      elif index is not None:
          target = target[index]
  
      attributions = self.attribution_method_instance.attribute(
          inputs=inputs,
          target=target,
          additional_forward_args=add_forward_args,
          **self.kwargs,
      )
  
      node_mask, edge_mask = convert_captum_output(
          attributions,
          mask_type,
          metadata,
      )
  
      if not isinstance(x, dict):
          return Explanation(node_mask=node_mask, edge_mask=edge_mask)
  
      explanation = HeteroExplanation()
      explanation.set_value_dict("node_mask", node_mask)
      explanation.set_value_dict("edge_mask", edge_mask)
      return explanation
  
file_path: pytorch_geometric/torch_geometric/explain/algorithm/captum_explainer.py
imports: import inspect
  import logging
  import warnings
  from typing import Any, Dict, Optional, Union
  import torch
  from torch import Tensor
  from torch_geometric.explain import Explanation, HeteroExplanation
  from torch_geometric.explain.algorithm import ExplainerAlgorithm
  from torch_geometric.explain.algorithm.captum import CaptumHeteroModel, CaptumModel, MaskLevelType, convert_captum_output, to_captum_input
  from torch_geometric.explain.config import MaskType, ModelMode, ModelReturnType
  from torch_geometric.typing import EdgeType, NodeType
label_desc: Use image node_id 6 for calling the CaptumExplainer obj's underlying member method code with example usage: obj.forward(model, x, edge_index) and returns: explanation, Explanation