code: def captum_output_to_dicts(
      captum_attrs: Tuple[Tensor, ...],
      mask_type: Union[str, MaskLevelType],
      metadata: Metadata,
  ) -> Tuple[
      Optional[Dict[NodeType, Tensor]], Optional[Dict[EdgeType, Tensor]]
  ]:
      r"""Convert the output of `Captum <https://captum.ai/>`_ attribution
      methods which is a tuple of attributions to two dictionaries with node and
      edge attribution tensors. This function is used while explaining
      :class:`~torch_geometric.data.HeteroData` objects.
      See :meth:`~torch_geometric.nn.models.to_captum_model` for example usage.
  
      Args:
          captum_attrs (tuple[torch.Tensor]): The output of attribution methods.
          mask_type (str): Denotes the type of mask to be created with
              a Captum explainer. Valid inputs are :obj:`"edge"`, :obj:`"node"`,
              and :obj:`"node_and_edge"`:
  
              1. :obj:`"edge"`: :obj:`captum_attrs` contains only edge
                 attributions. The returned tuple has no node attributions, and
                 an edge attribution dictionary edge types as keys and edge mask
                 tensors of shape :obj:`[num_edges]` as values.
  
              2. :obj:`"node"`: :obj:`captum_attrs` contains only node
                 attributions. The returned tuple has a node attribution
                 dictionary with node types as keys and node mask tensors of
                 shape :obj:`[num_nodes, num_features]` as values, and no edge
                 attributions.
  
              3. :obj:`"node_and_edge"`: :obj:`captum_attrs` contains node and
                  edge attributions.
  
          metadata (Metadata): The metadata of the heterogeneous graph.
      """
      mask_type = MaskLevelType(mask_type)
      node_types = metadata[0]
      edge_types = metadata[1]
      x_attr_dict, edge_attr_dict = None, None
      captum_attrs = [
          captum_attr.squeeze(0) for captum_attr in captum_attrs
      ]
      if mask_type == MaskLevelType.node:
          assert len(node_types) == len(captum_attrs)
          x_attr_dict = dict(zip(node_types, captum_attrs))
      elif mask_type == MaskLevelType.edge:
          assert len(edge_types) == len(captum_attrs)
          edge_attr_dict = dict(zip(edge_types, captum_attrs))
      elif mask_type == MaskLevelType.node_and_edge:
          assert len(edge_types) + len(node_types) == len(captum_attrs)
          x_attr_dict = dict(
              zip(node_types, captum_attrs[: len(node_types)])
          )
          edge_attr_dict = dict(
              zip(edge_types, captum_attrs[len(node_types) :])
          )
      return x_attr_dict, edge_attr_dict
  
imports: from enum import Enum
  from typing import Dict, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch_geometric.explain.algorithm.utils import clear_masks, set_hetero_masks, set_masks
  from torch_geometric.explain.config import ModelConfig, ModelMode, ModelReturnType
  from torch_geometric.typing import EdgeType, Metadata, NodeType
label_desc: Use image node_id 3 for calling a global function with example usage: captum_output_to_dicts(captum_attrs, mask_type, metadata) and returns: x_attr_dict,  edge_attr_dict