dgl.heterograph(data_dict, num_nodes_dict=None, restrict_format='auto', index_dtype='int64')[source]

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

  • 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.

  • restrict_format ('any', 'coo', 'csr', 'csc', 'auto', optional) – Force the storage format. Default: ‘auto’ (i.e. let DGL decide what to use).
  • index_dtype ('int32', 'int64', optional) – Force the index data type. Default: ‘int64’.

Return type:



>>> 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)],
...     })