I have built my own DGL Dataset using the code below:
class ORValidationDataset(DGLDataset):
def __init__(self):
super().__init__(name='OR')
def process(self):
nodes_data = members
edges_data = interactions
graph_type = torch.from_numpy(nodes_data['topic'].astype('category').cat.codes.to_numpy())
node_labels = torch.from_numpy(nodes_data['type'].astype('category').cat.codes.to_numpy())
# graph_type = torch.CharTensor(nodes_data['topic'])
# node_labels = torch.CharTensor(nodes_data['type'])
edge_features = torch.from_numpy(edges_data['Weight'].to_numpy())
edges_src = torch.from_numpy(edges_data['Src'].to_numpy())
edges_dst = torch.from_numpy(edges_data['Dst'].to_numpy())
self.graph = dgl.graph((edges_src, edges_dst), num_nodes=nodes_data.shape[0])
self.graph.ndata['node_type'] = node_labels
self.graph.ndata['graph_type'] = graph_type
self.graph.edata['weight'] = edge_features
def __getitem__(self, i):
return self.graph
def __len__(self):
return 1
However when I try to run the following training pipeline to predict the links between the nodes, I get a ‘expected scalar type Char’ error. What am I doing wrong in terms of types? I know that there is a mismatch but I can’t seem to figure it out. Thanks!
optimizer = torch.optim.Adam(itertools.chain(model.parameters(), pred.parameters()), lr=0.01)
all_logits = []
for e in range(100):
# forward
h = model(train_g, train_g.ndata['graph_type'])
pos_score = pred(train_pos_g, h)
neg_score = pred(train_neg_g, h)
loss = compute_loss(pos_score, neg_score)
# backward
optimizer.zero_grad()
loss.backward()
optimizer.step()
if e % 5 == 0:
print('In epoch {}, loss: {}'.format(e, loss))
# ----------- 5. check results ------------------------ #
from sklearn.metrics import roc_auc_score
with torch.no_grad():
pos_score = pred(test_pos_g, h)
neg_score = pred(test_neg_g, h)
print('AUC', compute_auc(pos_score, neg_score))
the error comes from the conv1() in the forward function in the model. Here is the code for that as well:
class GraphSAGE(nn.Module):
def __init__(self, in_feats, h_feats):
super(GraphSAGE, self).__init__()
self.conv1 = SAGEConv(in_feats, h_feats, 'mean')
self.conv2 = SAGEConv(h_feats, h_feats, 'mean')
def forward(self, g, in_feat):
import pdb; pdb.set_trace()
h = self.conv1(g, in_feat)
h = F.relu(h)
h = self.conv2(g, h)
return h