message-edge.rst 899 Bytes
Newer Older
1
2
3
4
5
.. _guide-message-passing-edge:

2.4 Apply Edge Weight In Message Passing
----------------------------------------

6
7
:ref:`(中文版) <guide_cn-message-passing-edge>`

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
A commonly seen practice in GNN modeling is to apply edge weight on the
message before message aggregation, for examples, in
`GAT <https://arxiv.org/pdf/1710.10903.pdf>`__ and some `GCN
variants <https://arxiv.org/abs/2004.00445>`__. In DGL, the way to
handle this is:

-  Save the weight as edge feature.
-  Multiply the edge feature by src node feature in message function.

For example:

.. code::

    import dgl.function as fn

23
24
    # Suppose eweight is a tensor of shape (E, *), where E is the number of edges.
    graph.edata['a'] = eweight
25
26
27
    graph.update_all(fn.u_mul_e('ft', 'a', 'm'),
                     fn.sum('m', 'ft'))

28
The example above uses eweight as the edge weight. The edge weight should
29
usually be a scalar.