torch_geometric.explain.algorithm.GNNExplainer
- class GNNExplainer(epochs: int = 100, lr: float = 0.01, **kwargs)[source]
Bases:
ExplainerAlgorithm来自“GNNExplainer: Generating Explanations for Graph Neural Networks”论文的GNN-Explainer模型,用于识别在GNN预测中起关键作用的紧凑子图结构和节点特征。
注意
有关使用
GNNExplainer的示例,请参见 examples/explain/gnn_explainer.py, examples/explain/gnn_explainer_ba_shapes.py, 和 examples/explain/ gnn_explainer_link_pred.py.注意
edge_size系数在每次迭代时乘以解释中的节点数量,并将结果值作为正则化项添加到损失中,目的是生成紧凑的解释。 较高的值将推动算法生成元素较少的解释。 根据数据集中平均节点度调整edge_size系数,特别是如果该值大于原始论文中使用的数据集中的值。- Parameters:
- forward(model: Module, x: Tensor, edge_index: Tensor, *, target: Tensor, index: Optional[Union[int, Tensor]] = None, **kwargs) Explanation[source]
计算解释。
- Parameters:
model (torch.nn.Module) – The model to explain.
x (Union[torch.Tensor, Dict[NodeType, torch.Tensor]]) – The input node features of a homogeneous or heterogeneous graph.
edge_index (Union[torch.Tensor, Dict[NodeType, torch.Tensor]]) – The input edge indices of a homogeneous or heterogeneous graph.
target (torch.Tensor) – The target of the model.
index (Union[int, Tensor], optional) – The index of the model output to explain. Can be a single index or a tensor of indices. (default:
None)**kwargs (optional) – Additional keyword arguments passed to
model.
- Return type: