Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the document of learning.Graph #1277

Merged
merged 13 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Session Functions
graphscope.get_option
graphscope.g
graphscope.gremlin
graphscope.learning
graphscope.graphlearn
52 changes: 44 additions & 8 deletions python/graphscope/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,13 +1168,49 @@ def graphlearn(self, graph, nodes=None, edges=None, gen_labels=None):
"""Start a graph learning engine.

Args:
nodes (list): The node types that will be used for gnn training.
edges (list): The edge types that will be used for gnn training.
gen_labels (list): Extra node and edge labels on original graph for gnn training.

Returns:
:class:`graphscope.learning.GraphDAGNode`:
An instance of learning graph that could be feed to the learning engine, evaluated in eager node.
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 can be `node_label` or
`(node_label, features)`. If the element of list is a tuple and
contains selected feature list, it would use the selected
feature list for training. if nodes is None, use all type of
nodes and features for the gnn training.
edges (list, optional): list of edge types that will be used for gnn
training. we use `(src_label, edge_label, dst_label)`
to specify one edge type. if edges is None, use all type of
edges for gnn training.
gen_labels (list, optional): Alias node and edge labels and extract
train/validation/test dataset from original graph for supervised
gnn training. The detail is explained in the examples below.

Examples
--------
>>> # assumes the input graph contains one label node `paper` and one edge label `link`.
acezen marked this conversation as resolved.
Show resolved Hide resolved
>>> features = ["weight", "name"] # use properties "weight" and "name" as features
>>> lg = sess.learing(
acezen marked this conversation as resolved.
Show resolved Hide resolved
graph,
nodes=[("paper", features)]) # use "paper" node and features for training
edges=[("paper", "links", "paper")] # use the `paper->links->papers` edge type for training
gen_labels=[
# cuts "paper" nodes into 100 pieces, and uses random 75 pieces(75%) as training dataset
acezen marked this conversation as resolved.
Show resolved Hide resolved
("train", "paper", 100, (0, 75)),
# cuts "paper" nodes into 100 pieces, and uses random 10 pieces(10%) as validation dataset
("val", "paper", 100, (75, 85)),
# cuts "paper" nodes into 100 pieces, and uses random 15 pieces(15%) as test dataset
("test", "paper", 100, (85, 100)),
]
)
Notes that the train, validation and test dataset are not overlapping. And for unsupervised learning
>>> lg = sess.learing(
acezen marked this conversation as resolved.
Show resolved Hide resolved
graph,
nodes=[("paper", features)]) # use "paper" node and features for training
edges=[("paper", "links", "paper")] # use the `paper->links->papers` edge type for training
gen_labels=[
# cuts "paper" nodes into 100 pieces, and uses all pieces as training dataset
("train", "paper", 100, (0, 100)),
]
)
"""
if self._session_id != graph.session_id:
raise RuntimeError(
Expand Down Expand Up @@ -1458,7 +1494,7 @@ def gremlin(graph, engine_params=None):
def graphlearn(graph, nodes=None, edges=None, gen_labels=None):
"""Create a graph learning engine.

See params detail in :meth:`graphscope.Session.learning`
See params detail in :meth:`graphscope.Session.graphlearn`

Returns:
:class:`graphscope.learning.GraphDAGNode`:
Expand Down
8 changes: 1 addition & 7 deletions python/graphscope/learning/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ class GraphDAGNode(DAGNode):

def __init__(self, session, graph, nodes=None, edges=None, gen_labels=None):
"""
Args:
session (:class:`Session`): instance of GraphScope session.
graph (:class:`graphscope.framework.graph.GraphDAGNode`):
Source property graph.
nodes (list): The node types that will be used for gnn training.
edges (list): The edge types that will be used for gnn training.
gen_labels (list): Extra node and edge labels on original graph for gnn training.
See params detail in :meth:`graphscope.Session.graphlearn`
"""
self._session = session
self._graph = graph
Expand Down