Issue with adding negative sampling with "RandomLinkSplit" for a heterogeneous graph #5446
Unanswered
HamidHadipour
asked this question in
Q&A
Replies: 1 comment 2 replies
-
We can only add negative edges in case you want to perform classification, in which case |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi community,
I am new to Pyg, I followed the example code in https://github.com/pyg-team/pytorch_geometric/blob/master/examples/hetero/hetero_link_pred.py and I need to do link prediction on a heterogeneous graph which is technically a bi-partite graph.
My task is link prediction and I have the dataset of connections or (label = 1) so, I need to do negative sampling. But as time as I add a ratio except "0.0" for the "negative sampling ration" property I get "Assertion error"
torch-geometric==2.1.0
Here is the data definition:
`
data = HeteroData()
data['chem'].num_nodes = len(cp_mapping)
data['protein'].num_nodes = len(cp_mapping_p)
data['chem', 'CPI', 'protein'].edge_index = edge_index
data['chem', 'CPI', 'protein'].edge_label = edge_label
data['chem'].x = torch.eye(data['chem'].num_nodes)
del data['chem'].num_nodes
data['protein'].x = torch.eye(data['protein'].num_nodes)
del data['protein'].num_nodes
`
Here is the result:
HeteroData( chem={ x=[1206, 1206] }, protein={ x=[152, 152] }, (chem, CPI, protein)={ edge_index=[2, 20000], edge_label=[20000] } )
Here is how I use RandomLinkSplit:
`
data = T.ToUndirected()(data)
del data['protein', 'rev_CPI', 'chem'].edge_label
train_data, val_data, test_data = T.RandomLinkSplit(
num_val=0.2,
num_test=0.2,
neg_sampling_ratio=1.0,
edge_types=[('chem', 'CPI', 'protein')],
rev_edge_types=[('protein', 'rev_CPI', 'chem')]
)(data)
`
Would you please take a look and correct me, or suggest me a better way?
@rusty1s
Beta Was this translation helpful? Give feedback.
All reactions