Skip to content
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

If train_test_split_edges is replaced by randomlinksplit #17

Open
qbitsofalchemy opened this issue Oct 18, 2023 · 1 comment
Open

If train_test_split_edges is replaced by randomlinksplit #17

qbitsofalchemy opened this issue Oct 18, 2023 · 1 comment

Comments

@qbitsofalchemy
Copy link

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?

@btarun13
Copy link

btarun13 commented Jan 21, 2025

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants