Link prediction for homogeneous nodes and heterogeneous links

Hi everyone.

If i have a graph with homogeneous nodes but heterogeneous links (3 types), which model from this tutorial (5.3 Link Prediction — DGL 0.6.1 documentation) should I implement?

Could I adapt the previous heterograph code to something like the following?:

model = Model(10, 20, 5, hetero_graph.etypes)
node_feats = hetero_graph.ndata['feature']
node_features = {'node': node_feats}
opt = torch.optim.Adam(model.parameters())
for epoch in range(10):
    negative_graph = construct_negative_graph(hetero_graph, k, ('node', 'ralation_name', 'node'))
    pos_score, neg_score = model(hetero_graph, negative_graph, node_features, ('node', 'ralation_name', 'node'))
    loss = compute_loss(pos_score, neg_score)
    opt.zero_grad()
    loss.backward()
    opt.step()
    print(loss.item())

My main questions are related to node and link names;

  1. about node names: since my nodes are all the same, they have no “type” like in the example from the tutorial. What i am doing here is naming them "node"s, right?

  2. about link names: since my links have no names, and their types are defined by a one hot encoded vector, how should I specificate them in those (‘node’, ‘relation_name’, ‘node’) triplets?

Just to make it more clear. My nodes have this shape:

Id, feature1, feature2, feature3
0, 1, 0, 0

And my relations look like this:

Start, End, Type
0, 1, [1, 0, 0]

Thanks.

One way is to give each one-hot type a name, for instance “1”, “2” or “3”.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.