Is g.ndata['x'] trainable?

In DGL, g.ndata[x] represents the node features of the graph g , where x is the key of the feature. Is these node features trainable?

It can be trainable since it is just a Torch tensor, not sure whether it answers your question or not, feel free to follow up.

thanks for your reply! I observed that the node features in the GraphSAGE example come with the dataset. However, in my scenario, nodes don’t have original features. Therefore, I need to initialize learnable features, such as g.ndata[“feat”] = torch.nn.Parameter(torch.nn.init.xavier_uniform_(torch.empty(g.num_nodes(), args[“emb_dim”]))).to(args[“device”]). Is this correct?

Yes, it is correct. The parameter should be trainable.

1 Like

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