class LabelPropagation(num_layers: int, alpha: float)[source]

Bases: MessagePassing

The label propagation operator from the “Learning from Labeled and Unlabeled Data with Label Propagation” paper

\[\mathbf{Y}^{\prime} = \alpha \cdot \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2} \mathbf{Y} + (1 - \alpha) \mathbf{Y},\]

where unlabeled data is inferred by labeled data via propagation.


For an example of using the LabelPropagation, see examples/

  • num_layers (int) – The number of propagations.

  • alpha (float) – The \(\alpha\) coefficient.

forward(y: Tensor, edge_index: Union[Tensor, SparseTensor], mask: Optional[Tensor] = None, edge_weight: Optional[Tensor] = None, post_step: Optional[Callable[[Tensor], Tensor]] = None) Tensor[source]
  • y (torch.Tensor) – The ground-truth label information \(\mathbf{Y}\).

  • edge_index (torch.Tensor or SparseTensor) – The edge connectivity.

  • mask (torch.Tensor, optional) – A mask or index tensor denoting which nodes are used for label propagation. (default: None)

  • edge_weight (torch.Tensor, optional) – The edge weights. (default: None)

  • post_step (callable, optional) – A post step function specified to apply after label propagation. If no post step function is specified, the output will be clamped between 0 and 1. (default: None)


Resets all learnable parameters of the module.