I have implemented this Link Prediction: model, but I have some doubts when fitting it to my graph: 5.3 Link Prediction — DGL 0.6.1 documentation
 Why is it not divided between Training and Testing? If I wanted to, how would I apply it in the last step, which involves calculating the loss?
Let’s say I have these splits:
numero_nodes = g.num_nodes('ent')
n_train = int(numero_nodes * 0.8)
train_mask = torch.zeros(numero_nodes, dtype=torch.bool)
test_mask = torch.zeros(numero_nodes, dtype=torch.bool)
train_mask[:n_train] = True
test_mask[n_train:] = True
g.ndata['train_mask'] = train_mask
g.ndata['test_mask'] = test_mask
How can I use these splits when training and testing the model with the following code? (is this even the right way to split traintest for link prediction?
def compute_loss(pos_score, neg_score):
# Margin loss
n_edges = pos_score.shape[0]
return (1  pos_score.unsqueeze(1) + neg_score.view(n_edges, 1)).clamp(min=0).mean()
k = 5
model = Model(10, 20, 5, hetero_graph.etypes)
user_feats = hetero_graph.nodes['user'].data['feature']
item_feats = hetero_graph.nodes['item'].data['feature']
node_features = {'user': user_feats, 'item': item_feats}
opt = torch.optim.Adam(model.parameters())
for epoch in range(10):
negative_graph = construct_negative_graph(hetero_graph, k, ('user', 'click', 'item'))
pos_score, neg_score = model(hetero_graph, negative_graph, node_features, ('user', 'click', 'item'))
loss = compute_loss(pos_score, neg_score)
opt.zero_grad()
loss.backward()
opt.step()
print(loss.item())

If I wanted to predict 2 relationships types at the same time, I understand that I would have to construct the negative graph to contain negative examples of both, but when using the model I see that I cannot pass a list of the type [(node_type, edge_type_1, node_type), (node_type, edge_type2, node_type)]. Is there any way to do it?

At the moment I can only calculate Loss and AUC. How can I also calculate the Accuracy? Is there a predefined function somewhere?

Once the model is trained, how can I use it to predict in new graphs which doesn’t contain those edges? Is there somethin like model.predict(new_graph)?
Thank you all.