MCPcopy Create free account
hub / github.com/alibaba/GraphScope / graphlearn

Method graphlearn

python/graphscope/client/session.py:1235–1319  ·  view source on GitHub ↗

Start a graph learning engine. Args: graph (:class:`graphscope.framework.graph.GraphDAGNode`): The graph to create learning instance. nodes (list, optional): list of node types that will be used for GNN training, the element of list ca

(self, graph, nodes=None, edges=None, gen_labels=None)

Source from the content-addressed store, hash-verified

1233 return self.graphlearn(graph, nodes, edges, gen_labels)
1234
1235 def graphlearn(self, graph, nodes=None, edges=None, gen_labels=None):
1236 """Start a graph learning engine.
1237
1238 Args:
1239 graph (:class:`graphscope.framework.graph.GraphDAGNode`):
1240 The graph to create learning instance.
1241 nodes (list, optional): list of node types that will be used for GNN
1242 training, the element of list can be `"node_label"` or
1243 `(node_label, features)`. If the element of the list is a tuple and
1244 contains selected feature list, it would use the selected
1245 feature list for training. Default is None which use all type of
1246 nodes and for the GNN training.
1247 edges (list, optional): list of edge types that will be used for GNN
1248 training. We use `(src_label, edge_label, dst_label)`
1249 to specify one edge type. Default is None which use all type of
1250 edges for GNN training.
1251 gen_labels (list, optional): Alias node and edge labels and extract
1252 train/validation/test dataset from original graph for supervised
1253 GNN training. The detail is explained in the examples below.
1254
1255 Examples
1256 --------
1257 >>> # Assume the input graph contains one label node `paper` and one edge label `link`.
1258 >>> features = ["weight", "name"] # use properties "weight" and "name" as features
1259 >>> lg = sess.graphlearn(
1260 graph,
1261 nodes=[("paper", features)]) # use "paper" node and features for training
1262 edges=[("paper", "links", "paper")] # use the `paper->links->papers` edge type for training
1263 gen_labels=[
1264 # split "paper" nodes into 100 pieces, and uses random 75 pieces (75%) as training dataset
1265 ("train", "paper", 100, (0, 75)),
1266 # split "paper" nodes into 100 pieces, and uses random 10 pieces (10%) as validation dataset
1267 ("val", "paper", 100, (75, 85)),
1268 # split "paper" nodes into 100 pieces, and uses random 15 pieces (15%) as test dataset
1269 ("test", "paper", 100, (85, 100)),
1270 ]
1271 )
1272 Note that the training, validation and test datasets are not overlapping. And for unsupervised learning:
1273 >>> lg = sess.graphlearn(
1274 graph,
1275 nodes=[("paper", features)]) # use "paper" node and features for training
1276 edges=[("paper", "links", "paper")] # use the `paper->links->papers` edge type for training
1277 gen_labels=[
1278 # split "paper" nodes into 100 pieces, and uses all pieces as training dataset
1279 ("train", "paper", 100, (0, 100)),
1280 ]
1281 )
1282 """
1283 if self._session_id != graph.session_id:
1284 raise RuntimeError(
1285 "Failed to create learning engine on the graph with different session: {0} vs {1}".format(
1286 self._session_id, graph.session_id
1287 )
1288 )
1289
1290 if not graph.graph_type == graph_def_pb2.ARROW_PROPERTY:
1291 raise InvalidArgumentError("The graph should be a property graph.")
1292

Callers 4

learningMethod · 0.95
graphlearnFunction · 0.80
simple_flowFunction · 0.80

Calls 9

get_gl_handleFunction · 0.90
preprocess_argsMethod · 0.80
formatMethod · 0.45
decodeMethod · 0.45
encodeMethod · 0.45
joinMethod · 0.45

Tested by 2

simple_flowFunction · 0.64