torch_geometric.explain.algorithm.GraphMaskExplainer

class GraphMaskExplainer(num_layers: int, epochs: int = 100, lr: float = 0.01, penalty_scaling: int = 5, lambda_optimizer_lr: int = 0.01, init_lambda: int = 0.55, allowance: int = 0.03, allow_multiple_explanations: bool = False, log: bool = True, **kwargs)[source]

Bases: ExplainerAlgorithm

来自“Interpreting Graph Neural Networks for NLP With Differentiable Edge Masking”论文的GraphMask-Explainer模型,用于识别在GNN预测中起关键作用的分层紧凑子图结构和节点特征。

注意

有关使用 GraphMaskExplainer 的示例, 请参见 examples/explain/graphmask_explainer.py

一个实际运行的实时示例,以部署的应用程序形式存在的GraphMaskExplainer,可以访问这里

Parameters:
  • num_layers (int) – 使用的层数。

  • epochs (int, optional) – The number of epochs to train. (default: 100)

  • lr (float, optional) – The learning rate to apply. (default: 0.01)

  • penalty_scaling (int, optional) – 惩罚项的缩放值。值必须在0到10之间。(默认值:5

  • lambda_optimizer_lr (float, optional) – 用于优化拉格朗日乘数的学习率。(默认值: 1e-2)

  • init_lambda (float, optional) – 拉格朗日乘数。值必须在 01 之间。(默认值:0.55

  • allowance (float, optional) – 一个介于 01 之间的浮点值,表示容忍级别。(默认值:0.03

  • log (bool, 可选) – 如果设置为 False,将不会记录任何学习进度。(默认值:True

  • **kwargs (optional) – Additional hyper-parameters to override default settings in coeffs.

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:

Explanation

supports() bool[source]

Checks if the explainer supports the user-defined settings provided in self.explainer_config, self.model_config.

Return type:

bool 翻译后的内容: bool 在这个例子中,`bool` 是一个Python函数名称,根据翻译规则1,不需要翻译。因此,翻译后的内容保持不变。

reset_parameters(input_dims: List[int], h_dim: List[int])[source]

重置模块的所有可学习参数。