# MBHAN: Motif-Based Heterogeneous Graph Attention Network
## 4 The Proposed Method
### Motif Subgraph-Level Attention Mechanism  
In heterogeneous graphs, each node consists of multifaceted semantic information, but a particular motif subgraph only reflects a side view of that node given its current motif connectivity pattern. To more thoroughly learn the embedding of the nodes, it is necessary to fuse the representations of the corresponding nodes in all the motif subgraphs. To achieve this, MBHAN employs a motif subgraph-level semantic attention mechanism for each possible triangular motif subgraph in the heterogeneous graph. This enables it to learn the importance of different motif subgraphs for the final representation of the node and fuse them within an end-to-end learning process. Using the node embeddings learned in the node-level attention mechanism as input, the learning process for each motif subgraph can be represented as follows:  
\[\left(\beta_{m_{0}},\beta_{m_{1}},\ldots,\beta_{m_{k}}\right)=att_{motif-level} \big{(}\mathcal{Z}_{m_{0}},\mathcal{Z}_{m_{1}},\ldots,\mathcal{Z}_{m_{k}} \big{)}, \tag{6}\]  
where \(att_{motif-level}\) refers to the execution of a motif subgraph-level deep learning attention process. This can capture the importance of all the triangular motif subgraphs in the heterogeneous graph for the final embeddings of the nodes. To capture the impact of each motif subgraph on the final node representation, MBHAN first uses a one-layer multilayer perceptron (MLP) to nonlinearly transform the embeddings of the nodes in the corresponding motif subgraphs. It then measures the motif importance of the impact on the final node embedding by using the motif semantic-level attention vector, \(q\), where \(W\) is the weight matrix and \(b\) is the bias vector:  
\[w_{m_{i}}=\frac{1}{|\mathcal{V}|}\sum\
olimits_{i\in\mathcal{V}}q^{T}\cdot \text{tanh}\big{(}W\cdot z_{i}^{m_{i}}+b\big{)}, \tag{7}\]  
Note that MBHAN attempts to learn the representation of all the nodes in the heterogeneous graphs, so a simple weighted global average for the different types of nodes is clearly inappropriate. As the motif subgraph division of MBHAN is predicated on the heterogeneity of the nodes, different motif subgraphs will have semantic nuances due to the node types, and their influence on the node-level representation learning process will certainly vary. So, to isolate the influence of node heterogeneity, different types of nodes should be treated differently in the attention mechanism's execution. Equation (7) can therefore be reformulated as:  
\[w_{m_{i}^{l}}=\frac{1}{|\mathcal{V}^{l}|}\sum\
olimits_{i\in\mathcal{V}^{l}}q^{ T}\cdot\text{tanh}\big{(}W\cdot z_{i}^{m_{i}}+b\big{)},\ t\in\mathcal{T}, \tag{8}\]  
where \(w_{m_{i}^{l}}\) is the importance coefficient for the \(t\)-type nodes in the motif subgraph, \(\mathcal{G}_{m_{i}}\), and \(\mathcal{V}^{t}\) is the set of \(t\)-type nodes. To ensure the stability of the training process, different types of nodes all share the one-layer MLP parameters described above when calculating each separate attention coefficient. Having calculated the importance coefficients for different types of nodes in different motif subgraphs, they are normalized to obtain the motif subgraph-level attention weights for each node type, \(t\), in \(\mathcal{G}_{m_{i}}\) by using a SoftMax function:  
\[\beta_{m_{i}^{l}}=\frac{\exp\Big{(}w_{m_{i}^{l}}\Big{)}}{\sum\
olimits_{t=1}^{ T}\exp\Big{(}w_{m_{i}^{l}}\Big{)}}, \tag{9}\]  
\(\beta_{m_{i}^{T}}\) can be interpreted as the contribution of each of the \(t\)-type nodes in \(\mathcal{G}_{m_{i}}\) to a specific task. The higher the value of \(\beta_{m_{i}^{l}}\), the more important the \(t\)-type nodes in \(\mathcal{G}_{m_{i}}\). The importance varies across different tasks.