Embedding mapped to nodes

I run into another problem here. I trained an embedding indexed by node IDs and plan to use it as my node features. Since my node IDs are not consecutive, I don’t know how to match my embedding to the nodes. Like before I just assign node features using ndata[‘feature’]=torch.ones(g.num_nodes(),4), but now I got different embedding for every node, do you have any idea how to map the correct embedding to the matched nodes.

The my graph information is attached (graph contains 932139 distinct nodes).

DGL only supports consecutive node IDs, so you will need to map the non-consecutive IDs to consecutive ones yourself, and maintain the mapping.

Cause my node IDs are object type initially, I use a hashmap to map IDs to int type. That’s why they are not consecutive. I don’t know how to map them to consecutive ones, do you have any suggestion?

You can use a dictionary. Say your nodes are a list of objects objs:

node_id_map = {obj: i for i, obj in enumerate(objs)}