GraphSAGE with edge features?

Hi! I am a complete newbie here and I’m trying to get graph embeddings with GraphSAGE. The graphs I’m working with only have features on the edges and nothing on the nodes. I noticed that GraphSAGE only considers node features but not edges’. I was thinking about a couple approach to this problem:

  1. modify SAGEConv’s message passing function so that it uses edge features instead of nodes’
  2. aggregate the edge features to produce node features and then uses SAGEConv as usual (I am worried that this might lose out information on the edges)
  3. would NNConv be a better choice?

I will be very appreciative of any kind of suggestion! Thank you!

  1. I would start with replacing fn.copy_src('h', 'm') with fn.copy_e('h', 'm') in SageConv, assuming your edge features are stored in g.edata['h']. This should work well.
  2. NNConv tends to be more useful for small graphs like molecular graphs.
1 Like

Thanks so much! I just realised someone asked a similar question before at Using node and edge features in message passing.

I have g.update_all([fn.copy_src('h', 'm_n'), fn.copy_e('h', 'm_e')], [fn.mean('m_n', 'neigh'), fn.mean('m_e', 'h_e')]) now to do mean aggregation on neighboring node features to g.dstdata['neigh'] and edge features to g.dstdata['h_e']. My question is does fn.copy_src only consider neighbor that is connected with an incoming edge, and fn.copy_e on edges that are pointing towards the dst node? What if I want to consider only the outgoing edges, or both?

fn.copy_src only considers neighbors connected with an incoming edge and fn.copy_e only considers incoming edges. If you want to consider the outgoing edges, you can explicitly add them as new incoming edges.