Skip to content

If train_test_split_edges is replaced by randomlinksplit #17

Open

Description

@qbitsofalchemy

In tutorial 6 if we use the randomlinksplit how does train_pos_edge_index get handled later in the code?

Does this line become:
train_pos_edge_index = train_data.edge_index.to(device) ?

And how is the test function redefined? If we don't have pos edges nor neg edges, then can you describe what happens to the test function?

Activity

  1. btarun13 commented on Jan 21, 2025

    @btarun13

    Hiya, I was just going through the repo. In regards to newer functions, when using randomlinksplit. There is a parameter within split_labels which when =True will give you distinct "pos_edge_label" and "neg_edge_label".

    After having a look at tutorial 6 , test function should look something like this:

    from torch_geometric.utils import negative_sampling
    
    def test(pos_edge_index, neg_edge_index=None):
        model.eval()
        with torch.no_grad():
            z = model.encode(x, train_pos_edge_index)
    
        # Generate negative samples dynamically if not provided
        if neg_edge_index is None:
            neg_edge_index = negative_sampling(
                edge_index=train_pos_edge_index,
                num_nodes=data.num_nodes,
                num_neg_samples=pos_edge_index.size(1)
            )
    
        return model.test(z, pos_edge_index, neg_edge_index)

    Note: train_pos_edge_index would be derived as train_data.edge_index.
    in case negative samples are not present you can use sampling like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions