RGCN Node classification error

Hi, I’m trying to implement a heterogeneous graph for node classification using my own dataset and I am referring to this documentation https://docs.dgl.ai/en/0.8.x/guide/training-node.html#guide-training-node-classification

This is how I have defined my heterograph.

hetero_graph = dgl.heterograph({
    ('customer', 'purchase', 'item'): (torch.tensor(cust_id),torch.tensor(item_id))
})

hetero_graph.nodes['customer'].data['feature'] = cust_node_features
hetero_graph.nodes['item'].data['feature'] = item_node_features
hetero_graph.nodes['customer'].data['label'] = labels

no_of_users = hetero_graph.num_nodes('customer')
no_of_purchases = hetero_graph.num_edges()

hetero_graph.nodes['customer'].data['train_mask'] = torch.zeros(no_of_users, dtype=torch.bool).bernoulli(0.6)
hetero_graph.edges['purchase'].data['train_mask'] = torch.zeros(no_of_purchases, dtype=torch.bool).bernoulli(0.6)

The output of this is.

Graph(num_nodes={‘customer’: 42, ‘item’: 175},
num_edges={(‘customer’, ‘purchase’, ‘item’): 193},
metagraph=[(‘customer’, ‘item’, ‘purchase’)])

The RGCN model is

RGCN(
(conv1): HeteroGraphConv(
(mods): ModuleDict(
(purchase): GraphConv(in=10, out=20, normalization=both, activation=None)
)
)
(conv2): HeteroGraphConv(
(mods): ModuleDict(
(purchase): GraphConv(in=20, out=2, normalization=both, activation=None)
)
)
)

I’m using the RGCN class defined in the above link. When I run the below lines, I’m getting an empty string {} for h_dict variable. The output of node_features is attached

#no_of_cust_node_features = 10
model = RGCN(no_of_cust_node_features, 20, 2, hetero_graph.etypes) 
cust_feats = hetero_graph.nodes['customer'].data['feature']
item_feats = hetero_graph.nodes['item'].data['feature']
labels = hetero_graph.nodes['customer'].data['label']
train_mask = hetero_graph.nodes['customer'].data['train_mask']
node_features = {'customer': cust_feats, 'item': item_feats}
h_dict = model(hetero_graph, {'customer': cust_feats, 'item': item_feats})
h_dict

Can someone please help me to understand why I’m getting an empty string instead of some values?

Can you provide a minimal script to reproduce the issue?

Hi, please find the link to my code
https://drive.google.com/file/d/12lvMFEDemv5DUZWv48ApbuMDkFtozcCe/view?usp=sharing

I cannot run from google.colab import drive drive.mount('/content/drive'). Did you run the notebook locally? Can you provide a python script with synthetic data?

Hi, I am using google colab to run my notebook. I have added the data file, python file and the notebook to this directory.
https://drive.google.com/drive/folders/1ZVGJKJtgba5jBXFSaD_fr6tW1G_ibgSQ?usp=share_link

The graph has a single canonical edge type ('customer', 'purchase', 'item'). After h = self.conv1(graph, inputs), h contains a single key-value pair for item nodes. The second graph convolutional layer then yields an empty dictionary. A simple fix can be adding reverse edges with type ('item', 'rev-purchase', 'customer').

Hi, Thank you for the response. I tried adding this reverse edge, but I’m getting a matrix shape error as below. Is it because of the model layers?

Yes, this is from model layers.

1 Like

I’m just starting out with DGL. In the RGCN model, there are 2 convolutional layers where the first layer takes the input features and the second layer takes the hidden features. In this case, how to modify the layers?

Did you have GraphConv for all relations in each HeteroGraphConv? Also you need to check if the feature size is properly handled.

Yes GraphConv is there in each HeteroGraphConv. I think the feature size is the issue

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