Why am I not getting representations for both product and customer nodes (heterogenous graph)?

I have the following graph:

cust_prod_graph is Graph(num_nodes={‘customer’: 8813, ‘product’: 157466},
num_edges={(‘customer’, ‘browsed’, ‘product’): 860771, (‘customer’, ‘purchased’, ‘product’): 68367},
metagraph=[(‘customer’, ‘product’, ‘browsed’), (‘customer’, ‘product’, ‘purchased’)])
with both types of nodes having 5641 features.

I have the following code:

cust_feats = cust_prod_graph.nodes[‘customer’].data[‘cust_features’]
prod_feats = cust_prod_graph.nodes[‘product’].data[‘prod_features’]

node_features = {‘customer’: cust_feats, ‘product’: prod_feats}
opt = torch.optim.Adam(model.parameters()).
rel_names = cust_prod_graph.etypes
conv1 = dglnn.HeteroGraphConv({
rel: dglnn.GraphConv(n_features, 32).double()for rel in rel_names}, aggregate=‘sum’)

architecture of conv1 is HeteroGraphConv(
(mods): ModuleDict(
(browsed): GraphConv(in=5641, out=32, normalization=both, activation=None)
(purchased): GraphConv(in=5641, out=32, normalization=both, activation=None)
)
)
with conv1(cust_prod_graph,node_features) , I expect the embeddings of both product and graph nodes. However, my output looks like the following:

{‘product’: tensor([[ 12.9467, -8.6195, 11.2425, …, -14.4359, -68.9401,
-82.6712],
[ -7.5036, 15.4040, -75.5001, …, 28.9520, -148.9352,
-115.1991],
[ 166.8621, -45.5309, 379.8224, …, -249.0713, -37.2838,
-284.1231],
…,
[ -16.6725, 43.8654, 2.4352, …, 28.1842, -21.5894,
-12.7247],
[ -1.2243, 3.8499, -14.4112, …, 7.8305, -72.1459,
-70.6307],
[ 2.6126, -4.0843, -6.6758, …, -1.8361, -42.6932,
-46.4625]], dtype=torch.float64, grad_fn=)}.

I do not see the customer node representations. What am i doing wrong?

Hi, for HeteroGraphConv, messages are passed and aggregated at the destination nodes, and your relations have target nodes of type product, so only the product nodes have embeddings. For more details, you can refer to the documentation at https://docs.dgl.ai/en/latest/generated/dgl.nn.pytorch.HeteroGraphConv.html.

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