gammagl.layers.conv.HeteroConv

class HeteroConv(convs: dict, aggr: str | None = 'sum')[source]

A generic wrapper for computing graph convolution on heterogeneous graphs. This layer will pass messages from source nodes to target nodes based on the bipartite GNN layer given for a specific edge type. If multiple relations point to the same destination, their results will be aggregated according to aggr.

>>> hetero_conv = HeteroConv({
    ('paper', 'cites', 'paper'): GCNConv(64, 16),
    ('author', 'writes', 'paper'): SAGEConv((128, 64), 64),
    ('paper', 'written_by', 'author'): GATConv((64, 128), 64),
}, aggr='sum')
>>> out_dict = hetero_conv(x_dict, edge_index_dict)
>>> print(list(out_dict.keys()))
['paper', 'author']
Parameters:
  • convs (dict[tuple[str, str, str], nn.module]) – A dictionary holding a bipartite MessagePassing layer for each individual edge type.

  • aggr (str, optional) – The aggregation scheme to use for grouping node embeddings generated by different relations. ("sum", "mean", "min", "max", None). (default: "sum")

reset_parameters()[source]
forward(x_dict, edge_index_dict, *args_dict, **kwargs_dict)[source]
Parameters:
  • x_dict (dict[str, tensor]) – A dictionary holding node feature information for each individual node type.

  • edge_index_dict (dict[tuple[str, str, str], tensor]) – A dictionary holding graph connectivity information for each individual edge type.

  • *args_dict (optional) – Additional forward arguments of invididual gammagl.layers.conv.MessagePassing layers.

  • **kwargs_dict (optional) – Additional forward arguments of individual gammagl.layers.conv.MessagePassing layers. For example, if a specific GNN layer at edge type edge_type expects edge attributes edge_attr as a forward argument, then you can pass them to forward() via edge_attr_dict = { edge_type: edge_attr }.