Node features when nodes have no features?

Hi all,

let’s imagine we have a HeteroGraph with different node types.
For a certain node type I have no node features. I mean: I simply wouldn’t have anything to place as feature tensor. I just know I have these nodes in my graph, but they’re feature-less.

Have you ever encounter this scenario?
What is an efficient approach in your opinion to tackle this problem?
Maybe to put the integer node ID as scalar feature for each node?

Thanks.

2 Likes

If we assume a transductive setting, we can learn embeddings from scratch for all nodes.

Hi @mufeili, thanks.

In practical terms though, what would you assign as node features? We do need a tensor as nodes features in order to perform the forward propagation, right?

I was actually thinking to create embeddings with torch.nn.Embedding

That’s exactly what I mean. You can do something as follows.

import torch.nn as nn

# assume g is a DGLGraph
embed = nn.Embedding(g.num_nodes(), feat_size)
g.ndata['h'] = embed.weight
4 Likes

Hi @mufeili,

Thanks.
What made you opt for g.ndata['h'] = embed.weight, instead of g.ndata['h'] = embed(node_ids)?

I would actually assign the ID embeddings as node features, and not the learnable weights. embed(node_ids) would be part of the forward. What do you think?

  1. If you use embed(node_ids), then the ID embeddings are the same as the learnable weights.
  2. With embed(node_ids), you create a copy of the learnable weights, which can consume a lot more memory.
1 Like

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