pgl.heter_graph_wrapper module: Heterogenous Graph data holders for Paddle GNN.¶
This package provides interface to help building static computational graph for PaddlePaddle.
-
class
pgl.heter_graph_wrapper.
HeterGraphWrapper
(name, edge_types, node_feat={}, edge_feat={}, **kwargs)[source]¶ Bases:
object
Implement a heterogeneous graph wrapper that creates a graph data holders that attributes and features in the heterogeneous graph. And we provide interface
to_feed
to help convertingGraph
data intofeed_dict
.- Parameters
name – The heterogeneous graph data prefix
node_feat – A dict of list of tuples that decribe the details of node feature tenosr. Each tuple mush be (name, shape, dtype) and the first dimension of the shape must be set unknown (-1 or None) or we can easily use
HeterGraph.node_feat_info()
to get the node_feat settings.edge_feat – A dict of list of tuples that decribe the details of edge feature tenosr. Each tuple mush be (name, shape, dtype) and the first dimension of the shape must be set unknown (-1 or None) or we can easily use
HeterGraph.edge_feat_info()
to get the edge_feat settings.
Examples
import paddle.fluid as fluid import numpy as np from pgl import heter_graph from pgl import heter_graph_wrapper num_nodes = 4 node_types = [(0, 'user'), (1, 'item'), (2, 'item'), (3, 'user')] edges = { 'edges_type1': [(0,1), (3,2)], 'edges_type2': [(1,2), (3,1)], } node_feat = {'feature': np.random.randn(4, 16)} edges_feat = { 'edges_type1': {'h': np.random.randn(2, 16)}, 'edges_type2': {'h': np.random.randn(2, 16)}, } g = heter_graph.HeterGraph( num_nodes=num_nodes, edges=edges, node_types=node_types, node_feat=node_feat, edge_feat=edges_feat) gw = heter_graph_wrapper.HeterGraphWrapper( name='heter_graph', edge_types = g.edge_types_info(), node_feat=g.node_feat_info(), edge_feat=g.edge_feat_info())
-
to_feed
(heterGraph, edge_types_list='__ALL__')[source]¶ Convert the graph into feed_dict.
This function helps to convert graph data into feed dict for
fluid.Excecutor
to run the model.- Parameters
heterGraph – the
HeterGraph
data objectedge_types_list – the edge types list to be fed
- Returns
A dictinary contains data holder names and its coresponding data.