graphstorm.model.RelationalAttLayer

class graphstorm.model.RelationalAttLayer(in_feat, out_feat, rel_names, num_heads, *, bias=True, activation=None, self_loop=False, dropout=0.0, num_ffn_layers_in_gnn=0, fnn_activation=<function relu>, norm=None)

Relational graph attention layer from ` Relational Graph Attention Networks <https://arxiv.org/abs/1904.05811>`__.

For the GATConv on each relation type: .. math:

h_i^{(l+1)} = \sum_{j\in \mathcal{N}(i)} \alpha_{i,j} W^{(l)} h_j^{(l)}

where \(\alpha_{ij}\) is the attention score between node \(i\) and node \(j\):

\[ \begin{align}\begin{aligned}\alpha_{ij}^{l} &= \mathrm{softmax_i} (e_{ij}^{l})\\e_{ij}^{l} &= \mathrm{LeakyReLU}\left(\vec{a}^T [W h_{i} \| W h_{j}]\right)\end{aligned}\end{align} \]

Note:

  • For inner relation message aggregation we use multi-head attention network.

  • For cross relation message we just use average.

Examples:

# suppose graph and input_feature are ready
from graphstorm.model.rgat_encoder import RelationalAttLayer

layer = RelationalAttLayer(
        h_dim, h_dim, g.canonical_etypes,
        num_heads, activation, self_loop,
        dropout, num_ffn_layers_in_gnn,
        fnn_activation, norm)
h = layer(g, input_feature)

Parameters

in_featint

Input feature size.

out_featint

Output feature size.

rel_nameslist[str]

Relation names.

num_headsint

Number of attention heads

biasbool, optional

True if bias is added. Default: True

activationcallable, optional

Activation function. Default: None

self_loopbool, optional

True to include self loop message. Default: False

dropoutfloat, optional

Dropout rate. Default: 0.0

num_ffn_layers_in_gnn: int, optional

Number of layers of ngnn between gnn layers

ffn_actication: torch.nn.functional

Activation Method for ngnn

normstr, optional

Normalization Method. Default: None