Hello
I found a similar question but it didn’t satisfy my query.
I am following the official dgl link prediction tutorial.
My graph has two nodes (user, item). Each node has different feature dimension. I get the following error:
DGLError: Dot operator is only available for arrays with the same size on last dimension, but got torch.Size([5]) and torch.Size([3]).
Following is the code I am using:
n_users = 1000
n_items = 500
n_clicks = 5000
n_hetero_features = 10
click_src = np.random.randint(0, n_users, n_clicks)
click_dst = np.random.randint(0, n_items, n_clicks)
hetero_graph = dgl.heterograph({
('user', 'click', 'item'): (click_src, click_dst),
})
hetero_graph.nodes['user'].data['h'] = torch.randn(n_users, 5)
hetero_graph.nodes['item'].data['h'] = torch.randn(n_items, 3)
hetero_graph.edges['click'].data['h'] = torch.randint(1, 2, (hetero_graph.number_of_edges(),))
# k negative samples
k = 5
in_features = hetero_graph.ndata['h']['user'].shape[1]
hidden_features = 20
out_features = 5
model = Model(in_features, hidden_features, out_features, hetero_graph.etypes)
user_feats = hetero_graph.nodes['user'].data['h']
item_feats = hetero_graph.nodes['item'].data['h']
node_features = {'user': user_feats, 'item': item_feats}
opt = th.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())
Could someone please help me with following questions:
- How do I fix this error? Why is this error happening?
- if my nodes have different dimensions (in this case 5 & 3), what should I set as
in_features
values ? - What is
out_features
value? In my example, is it the number of unique items or unique users? - How should I tell the model to use edge feature as well ?
I have scanned through github issues, this forums answer currently I’m quite confused how to go forward.
Regards
yolo