class_docstr: The GNN-Explainer model from the `"GNNExplainer: Generating
  Explanations for Graph Neural Networks"
  <https://arxiv.org/abs/1903.03894>`_ paper for identifying compact subgraph
  structures and small subsets node features that play a crucial role in a
  GNN’s node-predictions.
  .. note:: For an example, see `benchmarks/xgraph
      <https://github.com/divelab/DIG/tree/dig/benchmarks/xgraph>`_.
  Args:
      model (torch.nn.Module): The GNN module to explain.
      epochs (int, optional): The number of epochs to train.
          (default: :obj:`100`)
      lr (float, optional): The learning rate to apply.
          (default: :obj:`0.01`)
      explain_graph (bool, optional): Whether to explain graph classification model
          (default: :obj:`False`)
      indirect_graph_symmetric_weights (bool, optional): If `True`, then the explainer
          will first realize whether this graph input has indirect edges, 
          then makes its edge weights symmetric. (default: :obj:`False`)
class_docstr_tok: ["The","GNN-Explainer","model","from","the","`","``","GNNExplainer",":","Generating","Explanations","for","Graph","Neural","Networks","''","<","https",":","\/\/arxiv.org\/abs\/1903.03894",">","`","_","paper","for","identifying","compact","subgraph","structures","and","small","subsets","node","features","that","play","a","crucial","role","in","a","GNN","\u2019","s","node-predictions",".","..","note",":",":","For","an","example",",","see","`","benchmarks\/xgraph","<","https",":","\/\/github.com\/divelab\/DIG\/tree\/dig\/benchmarks\/xgraph",">","`","_",".","Args",":","model","(","torch.nn.Module",")",":","The","GNN","module","to","explain",".","epochs","(","int",",","optional",")",":","The","number","of","epochs","to","train",".","(","default",":",":","obj",":","`","100","`",")","lr","(","float",",","optional",")",":","The","learning","rate","to","apply",".","(","default",":",":","obj",":","`","0.01","`",")","explain_graph","(","bool",",","optional",")",":","Whether","to","explain","graph","classification","model","(","default",":",":","obj",":","`","False","`",")","indirect_graph_symmetric_weights","(","bool",",","optional",")",":","If","`","True","`",",","then","the","explainer","will","first","realize","whether","this","graph","input","has","indirect","edges",",","then","makes","its","edge","weights","symmetric",".","(","default",":",":","obj",":","`","False","`",")"]
code: def gnn_explainer_alg(
      self,
      x: Tensor,
      edge_index: Tensor,
      ex_label: Tensor,
      mask_features: bool = False,
      **kwargs,
  ) -> Tensor:
      # initialize a mask
      self.to(x.device)
      self.mask_features = mask_features
  
      # train to get the mask
      optimizer = torch.optim.Adam(
          [self.node_feat_mask, self.edge_mask], lr=self.lr
      )
  
      for epoch in range(1, self.epochs + 1):
          if mask_features:
              h = x * self.node_feat_mask.view(1, -1).sigmoid()
          else:
              h = x
          raw_preds = self.model(x=h, edge_index=edge_index, **kwargs)
          loss = self.__loss__(raw_preds, ex_label)
          if epoch % 20 == 0 and debug:
              print(f"Loss:{loss.item()}")
  
          optimizer.zero_grad()
          loss.backward()
          torch.nn.utils.clip_grad_value_(
              self.model.parameters(), clip_value=2.0
          )
          optimizer.step()
  
      return self.edge_mask.data
  
file_path: DIG/dig/xgraph/method/gnnexplainer.py
imports: import torch
  from torch import Tensor
  from torch_geometric.utils.loop import add_remaining_self_loops
  from dig.version import debug
  from ..models.utils import subgraph
  from .utils import symmetric_edge_mask_indirect_graph
  from torch.nn.functional import cross_entropy
  from .base_explainer import ExplainerBase
  from typing import Union
label_desc: Use image node_id 3 for calling the GNNExplainer obj's underlying member method code with example usage: obj.gnn_explainer_alg(x, edge_index, ex_label, mask_features) and returns: self