How can I define the range of negative sampling in the LinkNeighborLoader? #9142
-
Hi. Although I think that there would be a duplicated question, I have a question about the negative sampling in the train_loader = LinkNeighborLoader(kf_train_data, edge_label_index=kf_train_data.edge_label_index, edge_label=kf_train_data.edge_label,
batch_size=32, shuffle=True, neg_sampling_ratio=1.0, num_neighbors=[2,2], disjoint=True, neg_sampling="binary") I guess that the unknown edges in the
When I have a node list and want to sample the random negative edges avoiding the duplicated edges with true positive print(node_list)
print(len(node_list))
# array([ 0, 1, 3, ..., 101089, 101090, 101091])
# 19392 Currently, I created random edges from the node list before entering the loader, but since I have modified the dataset it is difficult to sample new negative samples during the epoch. random_neg_edges = torch.stack([torch.tensor(random.sample(list(node_list), len(GraphList.edge_label))),
torch.tensor(random.sample(list(node_list), len(GraphList.edge_label)))], 0)
GraphList.edge_index = torch.cat([GraphList.edge_index, random_neg_edges], dim=1)
GraphList.edge_label = torch.cat([GraphList.edge_label, torch.zeros(len(GraphList.edge_label)).int()]) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Sorry, I don't understand the question yet. Why is If you want to sample on your own, you can also take a look at |
Beta Was this translation helpful? Give feedback.
We currently lack a good interface to customize negative sampling. What you can try is passing a custom
NegativeSampling
class to your loader, which modifiessample
to only sample blue nodes.