Help with custom message function with dual embeddings

Lets say, I have the below sample graph nodes and edges
edges - v_t, b_t

v_t
(A1,A2), (A1,A3), (A1,A4)
(B1,B2), (B1,B3)

b_t
(A1,B1)

I want to generate h_s and h_t dual embeddings, for instance h_s and h_t of A1 should look like below
h_s = features of A1 + features of connected v_t nodes A2, A3, A4
h_t = features of b_t B1 + features of B1’s connected v_t B2, B3

How to write a message function for this in dgl?

What does v_t and b_t mean? Are they different edge types?
Also, does v_t and b_t have additional characteristics or constraints? According to your example, it seems that you assume each A node can only have one b_t edge connecting a B node, while each A/B node can have an arbitrary number of v_t edges connecting the same node type. Not sure if I understood your intention correctly. Namely, the interpretation of your h_t formulation will be ambiguous if A has multiple b_t edges, so it will be hard to give a definitive answer without extra info.

Yea, these are edge types. Both the edge types can have n neighbours. I just gave a simple example.

Essentially I’m trying to combine the information from both the edge types into the dual embeddings. You can think of it as viewed together and bought together edge types. My main intention is to make h_s as source node embedding… and h_t as destination node embedding which will have complentary items for the source nodes.

@BarclayII Here is my current attempt at achieving this

h_src = node_features
h_dst = node_features
g.nodes['item'].data["h_src"] = h_src
g.nodes['item'].data["h_dst"] = h_dst


g['viewed_together'].update_all(fn.copy_u('h_src', 'm'), fn.sum('m', 'h_src'))

g['bought_together'].srcdata['h_temp'] = g['viewed_together'].dstdata['h_src']

g['bought_together'].update_all(fn.copy_u('h_temp', 'm'), fn.sum('m', 'h_dst'))

g.nodes['item'].data['h_dst'] += g['viewed_together'].srcdata['h_src']

Does this look alright?

The basic logic looks fine. I would recommend something like this:

g.update_all(fn.copy_u('h_src', 'm'), fn.sum('m', 'h_src'), etype='viewed_together')
...

sure, could you explain if this suggestion is efficiency related or something else?

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