-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[GraphBolt][Dataset] Contribute IGBH dataset to hetero examples. #7708
Open
BowenYao18
wants to merge
47
commits into
dmlc:master
Choose a base branch
from
BowenYao18:add-igbh-to-rgcn
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
6441133
contribute three IGB dataset (small version)
abb9f39
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 85d92c8
contribute three IGB dataset (small version)
5d2fe56
contribute three IGB dataset (small version)
543f672
format the code with ufmt
6bf10cb
added documentation
5fc930b
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 42717af
Update examples/graphbolt/rgcn/download.py
BowenYao18 06f3f29
Update examples/graphbolt/rgcn/download.py
BowenYao18 19f18a5
Update examples/graphbolt/rgcn/download.py
BowenYao18 97c1735
Update examples/graphbolt/rgcn/download.py
BowenYao18 93cb70f
added 2983 class task
b170a90
fix lint
55079b8
Update examples/graphbolt/rgcn/download.py
BowenYao18 ce65746
remove labels from yaml
8660565
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 0e0fa09
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 3322987
add doenload script
0135b4b
corrected path in processing file
BowenYao18 7a35313
modify yaml file builder
BowenYao18 217b885
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 6e0365b
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 96c96ad
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 4b680c7
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 bbf4c97
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 c9789cd
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 39c9772
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 6a9a9dc
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 c645bb7
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 2a6244e
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 befc958
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 422ccbe
add igb-het-[tiny|small]
eb62d9f
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 8e51701
resolve merge conflict
337d416
Merge branch 'master' into add-igbh-to-rgcn
BowenYao18 aaf1da1
Update examples/graphbolt/pyg/hetero/node_classification.py
BowenYao18 ebdb01f
Update examples/graphbolt/pyg/hetero/node_classification.py
BowenYao18 d50977d
Update examples/graphbolt/pyg/hetero/node_classification.py
BowenYao18 1b54977
Merge branch 'master' into add-igbh-to-rgcn
BowenYao18 071d055
remove main args
f31d354
remove script
9e445c6
add all reverse edge type
e1607ab
Merge branch 'master' into add-igbh-to-rgcn
mfbalin b043999
add igb-het-large
BowenYao18 2657ee1
fix format
BowenYao18 d11f815
fix lint
BowenYao18 de7dc90
Merge branch 'dmlc:master' into add-igbh-to-rgcn
BowenYao18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this file have that the existing examples does not have? We already have functions to measure accuracy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import numpy as np | ||
|
||
try: | ||
import torch | ||
except ImportError: | ||
torch = None | ||
|
||
|
||
### Evaluator for node property prediction | ||
class IGB_Evaluator: | ||
def __init__(self, name, num_tasks, eval_metric): | ||
self.name = name | ||
self.num_tasks = num_tasks | ||
self.eval_metric = eval_metric | ||
|
||
def _parse_and_check_input(self, input_dict): | ||
if self.eval_metric == "acc": | ||
if not "y_true" in input_dict: | ||
raise RuntimeError("Missing key of y_true") | ||
if not "y_pred" in input_dict: | ||
raise RuntimeError("Missing key of y_pred") | ||
|
||
y_true, y_pred = input_dict["y_true"], input_dict["y_pred"] | ||
|
||
""" | ||
y_true: numpy ndarray or torch tensor of shape (num_nodes num_tasks) | ||
y_pred: numpy ndarray or torch tensor of shape (num_nodes num_tasks) | ||
""" | ||
|
||
# converting to torch.Tensor to numpy on cpu | ||
if torch is not None and isinstance(y_true, torch.Tensor): | ||
y_true = y_true.detach().cpu().numpy() | ||
|
||
if torch is not None and isinstance(y_pred, torch.Tensor): | ||
y_pred = y_pred.detach().cpu().numpy() | ||
|
||
## check type | ||
if not ( | ||
isinstance(y_true, np.ndarray) | ||
and isinstance(y_true, np.ndarray) | ||
): | ||
raise RuntimeError( | ||
"Arguments to Evaluator need to be either numpy ndarray or torch tensor" | ||
) | ||
|
||
if not y_true.shape == y_pred.shape: | ||
raise RuntimeError( | ||
"Shape of y_true and y_pred must be the same" | ||
) | ||
|
||
if not y_true.ndim == 2: | ||
raise RuntimeError( | ||
"y_true and y_pred must to 2-dim arrray, {}-dim array given".format( | ||
y_true.ndim | ||
) | ||
) | ||
|
||
if not y_true.shape[1] == self.num_tasks: | ||
raise RuntimeError( | ||
"Number of tasks for {} should be {} but {} given".format( | ||
self.name, self.num_tasks, y_true.shape[1] | ||
) | ||
) | ||
|
||
return y_true, y_pred | ||
|
||
else: | ||
raise ValueError("Undefined eval metric %s " % (self.eval_metric)) | ||
|
||
def _eval_acc(self, y_true, y_pred): | ||
acc_list = [] | ||
|
||
for i in range(y_true.shape[1]): | ||
is_labeled = y_true[:, i] == y_true[:, i] | ||
correct = y_true[is_labeled, i] == y_pred[is_labeled, i] | ||
acc_list.append(float(np.sum(correct)) / len(correct)) | ||
|
||
return {"acc": sum(acc_list) / len(acc_list)} | ||
|
||
def eval(self, input_dict): | ||
if self.eval_metric == "acc": | ||
y_true, y_pred = self._parse_and_check_input(input_dict) | ||
return self._eval_acc(y_true, y_pred) | ||
else: | ||
raise ValueError("Undefined eval metric %s " % (self.eval_metric)) |
mfbalin marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the code here can be simplified to a few lines of code. Can we do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BowenYao18