dgl.heterograph

dgl.heterograph(data_dict, num_nodes_dict=None)[source]

Create a heterogeneous graph from a dictionary between edge types and edge lists.

Parameters:
  • data_dict (dict) –

    The dictionary between edge types and edge list data.

    The edge types are specified as a triplet of (source node type name, edge type name, destination node type name).

    The edge list data can be anything acceptable by dgl.graph() or dgl.bipartite(), or objects returned by the two functions themselves.

  • num_nodes_dict (dict[str, int]) –

    The number of nodes for each node type.

    By default DGL infers the number of nodes for each node type from data_dict by taking the maximum node ID plus one for each node type.

Returns:

Return type:

DGLHeteroGraph

Examples

>>> g = dgl.heterograph({
...     ('user', 'follows', 'user'): [(0, 1), (1, 2)],
...     ('user', 'plays', 'game'): [(0, 0), (1, 0), (1, 1), (2, 1)],
...     ('developer', 'develops', 'game'): [(0, 0), (1, 1)],
...     })