Hi,
I was wondering, if I have already built a heterograph like below, can I add new edge types to it/change the structure? For example, can I add a new ‘user agrees_with source’? If so, how would I do that?
data_dict = {('source', 'has_follower', 'user'): (torch.tensor([0, 0]), torch.tensor([0, 0])), ('user', 'follows', 'source'): (torch.tensor([0, 0]), torch.tensor([0, 0])) }
dgl_graph = dgl.heterograph(data_dict)
I also have another question, I constructed another graph in which I added a new ‘tweet’ node, which is connected to only some sources and some users. When trying to run this model and train it with link prediction, I get an error in the ScorePrediction. Here is the code I’m using for that:
class HeteroScorePredictor(nn.Module):
def forward(self, edge_subgraph, x):
with edge_subgraph.local_scope():
edge_subgraph.ndata['h'] = x
for etype in edge_subgraph.canonical_etypes:
if edge∂_subgraph.num_edges(etype) <= 0:
continue
edge_subgraph.apply_edges(dgl.function.u_dot_v('h', 'h', 'score'), etype=etype)
return edge_subgraph.edata['score']
And here is the error:
Traceback (most recent call last):
File "lib/python3.6/multiprocessing/process.py", line 258, in _
bootstrap
self.run()
File "lib/python3.6/multiprocessing/process.py", line 93, in ru
n
self._target(*self._args, **self._kwargs)
File "GNN_model.py", line 1039, in running_code
pos_score, neg_score = model(positive_graph, negative_graph, blocks, node_features)
File "lib/python3.6/site-packages/torch/nn/modules/module.py",
line 550, in __call__
result = self.forward(*input, **kwargs)
File "GNN_model.py", line 200, in forward
pos_score = self.pred(g, x)
File "lib/python3.6/site-packages/torch/nn/modules/module.py",
line 550, in __call__
result = self.forward(*input, **kwargs)
File "GNN_model.py", line 187, in forward
edge_subgraph.apply_edges(dgl.function.u_dot_v('h', 'h', 'score'), etype=etype)
File "lib/python3.6/site-packages/dgl/heterograph.py", line 411
9, in apply_edges
edata = core.invoke_gsddmm(g, func)
File "lib/python3.6/site-packages/dgl/core.py", line 201, in in
voke_gsddmm
x = alldata[func.lhs][func.lhs_field]
File "lib/python3.6/site-packages/dgl/view.py", line 66, in __g
etitem__
return self._graph._get_n_repr(self._ntid, self._nodes)[key]
File "lib/python3.6/site-packages/dgl/frame.py", line 386, in _
_getitem__
return self._columns[name].data
KeyError: 'h'
I’m not sure what the issue is here since I’m skipping edge types that don’t exist in the score predictor.