grail icon indicating copy to clipboard operation
grail copied to clipboard

runtime error of _prepare_subgraphs for negative data

Open lihuiliullh opened this issue 3 years ago • 3 comments

Do you meet the following problem when you run the code?

subgraphs_neg.append(self._prepare_subgraphs(nodes_neg, r_label_neg, n_labels_neg))

Exception has occurred: AssertionError For return_array=False, there should be one and only one edge between u and v, but get 0 edges. Please use return_array=True instead

lihuiliullh avatar Nov 23 '22 23:11 lihuiliullh

Do you meet the following problem when you run the code?

subgraphs_neg.append(self._prepare_subgraphs(nodes_neg, r_label_neg, n_labels_neg))

Exception has occurred: AssertionError For return_array=False, there should be one and only one edge between u and v, but get 0 edges. Please use return_array=True instead Classmate, I am also reproducing this model, can you communicate?

liangxinyu0514 avatar Feb 08 '23 15:02 liangxinyu0514

Encounter the same error. Did you guys solve it? thank you!

TamSiuhin avatar Mar 09 '23 08:03 TamSiuhin

My python version is 3.8.10. I installed the author's requirements in a virtual environment and got similar errors.

The assertion error is due to not finding any edge between node 0 and node 1 to begin with. I found that returning an empty array would help instead of throwing this error. I changed the code in subgraph_extraction/datasets.py line 147 from

edges_btw_roots = subgraph.edge_id(0, 1) to edges_btw_roots = subgraph.edge_id(0, 1, return_array=True)

Doing this step eliminated the assertion error but the code threw another dimension mismatch error for me in managers/trainer.py file line 58 where they compute the loss:

I fixed it by making this modification:

loss = self.criterion(score_pos.squeeze(), score_neg.view(len(score_pos), -1).mean(dim=1), torch.ones(score_pos.numel()).to(device=self.params.device))

Hope it helps you all.

shoron-dutta avatar Oct 21 '24 22:10 shoron-dutta