DyExplainer: Explainable Dynamic Graph Neural Networks
Graph Neural Networks (GNNs) resurge as a trending research subject owing to
their impressive ability to capture representations from graph-structured data.
However, the black-box nature of GNNs presents a significant challenge in terms
of comprehending and trusting these models, thereby limiting their practical
applications in mission-critical scenarios. Although there has been substantial
progress in the field of explaining GNNs in recent years, the majority of these
studies are centered on static graphs, leaving the explanation of dynamic GNNs
largely unexplored. Dynamic GNNs, with their ever-evolving graph structures,
pose a unique challenge and require additional efforts to effectively capture
temporal dependencies and structural relationships. To address this challenge,
we present DyExplainer, a novel approach to explaining dynamic GNNs on the fly.
DyExplainer trains a dynamic GNN backbone to extract representations of the
graph at each snapshot, while simultaneously exploring structural relationships
and temporal dependencies through a sparse attention technique. To preserve the
desired properties of the explanation, such as structural consistency and
temporal continuity, we augment our approach with contrastive learning
techniques to provide priori-guided regularization. To model longer-term
temporal dependencies, we develop a buffer-based live-updating scheme for
training. The results of our extensive experiments on various datasets
demonstrate the superiority of DyExplainer, not only providing faithful
explainability of the model predictions but also significantly improving the
model prediction accuracy, as evidenced in the link prediction task.
Tianchun Wang, Dongsheng Luo, Wei Cheng, Haifeng Chen, Xiang Zhang
# DyExplainer: Explainable Dynamic Graph Neural Networks

###### Abstract.

Graph Neural Networks (GNNs) resurge as a trending research subject owing to their impressive ability to capture representations from graph-structured data. However, the black-box nature of GNNs presents a significant challenge in terms of comprehending and trusting these models, thereby limiting their practical applications in mission-critical scenarios. Although there has been substantial progress in the field of explaining GNNs in recent years, the majority of these studies are centered on static graphs, leaving the explanation of dynamic GNNs largely unexplored. Dynamic GNNs, with their ever-evolving graph structures, pose a unique challenge and require additional efforts to effectively capture temporal dependencies and structural relationships. To address this challenge, we present DyExplainer, a novel approach to explaining dynamic GNNs on the fly. DyExplainer trains a dynamic GNN backbone to extract representations of the graph at each snapshot, while simultaneously exploring structural relationships and temporal dependencies through a sparse attention technique. To preserve the desired properties of the explanation, such as structural consistency and temporal continuity, we augment our approach with contrastive learning techniques to provide priori-guided regularization. To model longer-term temporal dependencies, we develop a buffer-based live-updating scheme for training. The results of our extensive experiments on various datasets demonstrate the superiority of DyExplainer, not only providing faithful explainability of the model predictions but also significantly improving the model prediction accuracy, as evidenced in the link prediction task.

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

+
Footnote †: journal: Acm LSRB 978, 1-4509-XXXXX-X/18/06... $15.00

## 1. Introduction

The advent of Graph Neural Networks (GNNs) has caused a veritable revolution in the field, and has been embraced with great enthusiasm due to their demonstrated efficacy in a variety of applications, ranging from node classification (K
at each snapshot to inform the node representations, while the latter accounts for the temporal dependencies between representations generated by long-term snapshots. Despite the proliferation of dynamic GNNs [32, 46], most of these approaches deduce the representation at each snapshot \(t\) solely based on the embedding at the previous snapshot \((t-1)\), thereby making it challenging to fully comprehend the intricate, long-term temporal dependencies between snapshots in real-world applications. For instance, social network connections between individuals, groups, and communities may be subject to change over time, influenced by a multitude of factors, such as geographical distance, personal life stage, and evolving interests. To encompass longer-term temporal dependencies, we have devised a buffer-based, live-updating scheme with temporal attention. Specifically, the temporal attention aggregates the node embeddings from the preceding \(B\) snapshots stored in a buffer. In this regard, prior works on dynamic GNNs are reduced to a special case of the DyExplainer, where \(B=1\). The proposed framework constitutes a generalization that encompasses all recent graph learning methods for dynamic graphs. For example, by relinquishing explainability and incorporating the Markov chain property for temporal evolution, our framework degenerates to ROLAND [46]. Additionally, by restricting temporal aggregations to only the final layer, our framework degenerates to a common approach in which a sequence model, such as GRU [2], is placed on top of GNNs [30, 40, 47].

The dual sparse attention components of DyExplainer serve a trifold function. Firstly, they impart incisive explanations for the model's predictions in downstream tasks. Secondly, they serve as a sparse regularizer, enhancing the learning process. As research in the field of ranshomon set theory [33, 43] demonstrates, sparse and interpretable models possess a higher degree of robustness and better generalization performance, as outlined in Sec. 4.3. Lastly, the attention components allow for the augmentation of the approach with priori-guided regularization, preserving the desirable properties of the explanation, such as structural consistency and temporal continuity. Structural consistency pertains to the consistency of node embeddings between connected nodes in a single snapshot, while temporal continuity enforces smoothness constraints on the temporal attention between closely spaced snapshots, guided by pre-established human priors. To achieve more lucid explanations, we employ the use of contrastive learning techniques, treating connected pairs as positive examples and unconnected pairs as negative examples for consistency regularization, and recent snapshots as positive examples and distant historical snapshots as negative examples for continuity regularization. Overall, our contributions are summarized as follows:

* We put forward the problem of explainable dynamic GNNs and propose a general DyExplainer to tackle it. As far as we know, it is the first work solving this problem.
* DyExplainer seamlessly integrates the modeling of both structural relationships and long-term dependencies via sparse attentions. As a result, it is capable of providing real-time explanations for both the structural and temporal factors that influence the model's predictions. This innovative explaining module has been designed to be encoder-agnostic, thereby affording flexibility to a range of dynamic GNN backbones. Its implementation requires minimal overhead, as it only entails adding a lightweight parameterization to the encoder for its explanation modules. This makes DyExplainer highly efficient even for large backbone networks.
* We propose two contrastive regularizations to provide consistency and continuity explanations. Our approach to augmenting desired properties in the explanation is a fresh contribution to the field and may be of independent interest.
* Extensive experiments on various datasets demonstrate the superiority of DyExplainer, not only providing faithful explainability of the model predictions but also significantly improving the model prediction accuracy, as evidenced in the link prediction task.

Figure 1. DyExplainer for dynamic graphs. \(H^{(t)}\) is the node representation for snapshot \(G^{(t)}\) after backbone module. \(H^{\prime(t)}\) is the updated node representation after explainable module. \(\widehat{A}^{(t)}\) is the structural attention for snapshot \(G^{(t)}\).
## 2. Problem Definition

We formulate a dynamic graph as a series of \(T\) attributed graphs as \(\mathcal{G}=(G^{(1)},...,G^{(T)})\), where each graph \(G^{(t)}=(\mathcal{V},\mathcal{E}^{(t)},X^{(t)})\) is a snapshot at time step \(t\). \(\mathcal{V}=\{v_{1},v2,...v_{N}\}\) is the set of \(N\) nodes shared by all snapshots and \(\mathcal{E}^{(t)}\in\mathcal{V}\times\mathcal{V}\) is the set of edges of a graph \(G^{(t)}\). \(X^{(t)}\in\mathbb{R}^{N\times D}\) is the node feature matrix at snapshot \(t\), where \(D\) is the number of dimensions of node features. The topology and node features of each snapshot are dynamically changing over time. We aim to learn an explainable dynamic GNN model \(f\) from the long-term snapshots defined as:

\[\widehat{\mathbf{A}}^{(t-B+1)},...,\widehat{\mathbf{A}}^{(t)},\mathbf{H}^{\prime(t+1)} \gets f\left(G^{(t-B+1)},...,G^{(t)}\right), \tag{1}\]

where \(\widehat{\mathbf{A}}^{(t-B+1)},...,\widehat{\mathbf{A}}^{(t)}\) are explanations we are interested and \(\mathbf{H}^{\prime(t+1)}\) is the future node representation predicted for the downstream tasks. In our study, we examine its application for link prediction. It's worth noting that our framework can also easily support other downstream tasks.

## 3. Method

### Encoder Backbone

There are different approaches to designing dynamic GNNs. As a plug-and-use framework, the proposed DyExplainer is flexible to the choice of dynamic GNNs as the backbone. In this work, we adopt a state-of-the-art method ROLAND (Roland, 2017) as the backbone due to its powerful expressiveness and impressive empirical performances in real-life datasets. Specifically, it hierarchically updates the node embedding to obtain the \(\mathbf{H}^{(t)}\) at snapshot \(t\). With ROLAND as the backbone, the architecture of the encoder is shown in Figure 2. We put the node embedding inferred by the backbone to a buffer of size \(B\) for the learning of our explainer module. Formally, we denote the node embeddings in the buffer as \(\{\mathbf{H}^{(t-B+1)},...,\mathbf{H}^{(t)}\}\).

### Explainable Aggregations

The node embedding at snapshot \(t\) is denoted by \(\mathbf{H}^{(t)}=\{\mathbf{h}_{1},...,\mathbf{h}_{N}\}\), \(\mathbf{h}_{i}\in\mathbb{R}^{F}\), where \(N\) is the number of nodes, and \(F\) is the feature dimension of the node embedding.

#### 3.2.1. Structural Aggregation

On dynamic graphs, each snapshot has its unique topology information. An effective explanation, therefore, should highlight the crucial structural components at a given snapshot that significantly contribute to the model's prediction. To this end, inspired by the idea in (Srivastava et al., 2017), we propose structural attention to aggregate the weighted neighborhoods at each time step. Formally, we have

\[\omega_{ij}^{(s,t)}=\text{LeakyReLU}\Big{(}\mathbf{a}^{(s)T}\Big{[} \mathbf{W}^{(s)}\mathbf{h}_{i}^{(t)}||\mathbf{W}^{(s)}\mathbf{h}_{j}^{(t)}\Big{]}\Big{)}, \tag{2}\]

\[\widehat{\mathbf{A}}_{ij}^{(t)}=\text{softmax}_{j}\Big{(}\omega_{ij}^{(s,t)} \Big{)}=\frac{\exp\Big{(}\omega_{ij}^{(s,t)}\Big{)}}{\sum_{\mathbf{k}\in\mathcal{ N}_{i}^{(t)}}\exp\Big{(}\omega_{ik}^{(s,t)}\Big{)}}, \tag{3}\]

where \(\widehat{\mathbf{A}}^{(t)}\) is the structural attention at time step \(t\), \(\mathbf{W}^{(s)}\) is a weight matrix in a shared linear transformation, \(\mathbf{a}^{(s)}\) is the weight vector in the single-layer network, \(\mathcal{N}_{i}^{(t)}\) is the set of neighbors of node \(i\) at time step \(t\), and \(||\) indicates the concatenation operation.

However, the utilization of weights in traditional attention models may pose a challenge in complex dynamic graph environments, particularly with regard to explanation. Explanations in these settings are often derived by imposing a threshold and disregarding insignificant attention weights. This approach, however, fails to account for the cumulative impact of numerous small but non-zero weights, which can be substantial. Moreover, the non-exclusivity of attention weights raises questions about their accuracy in reflecting the true underlying importance (Srivastava et al., 2017). To address this issue and equip structural attention with better explainability, we design a hard attention mechanism to alleviate the effects of small attention coefficients. The basic idea uses a prior work on differentiable sampling (Golovolov et al., 2015; Golovolov et al., 2015), which states that the random variable

\[\epsilon=\sigma\bigg{(}\Big{(}\log\epsilon-\log\big{(}1-\epsilon\big{)}+ \omega\Big{)}/\tau\bigg{)}\quad\text{where}\quad\epsilon\sim\text{Uniform}(0,1), \tag{4}\]

where \(\sigma(\cdot)\) is the sigmoid function and \(\tau\) is the temperature controlling the approximation. Equation 4 follows a distribution that converges to a Bernoulli distribution with success probability \(p=(1+e^{-\omega})^{-1}\) as \(\tau>0\) tends to zero. Hence, if we parameterize \(\omega\) and specify that the presence of an edge between a pair of nodes has probability \(p\), then using \(\epsilon\) computed from equation 4 to fill the corresponding entry of \(\widehat{\mathbf{A}}\) will produce a matrix \(\widehat{\mathbf{A}}\) that is close to binary. We use this matrix as the hard attention with the hope of obtaining a better explanation due to the dropping of small attention weights. Moreover, because equation 4 is differentiable with respect to \(\omega\), we can train the parameters of \(\omega\) like in a usual gradient-based training. In the structural attention, we have the parameterized \(\omega_{ij}^{(s,t)}\) in Equation 2, thus we get

\[\widehat{e}_{ij}^{(s,t)}=\sigma\bigg{(}\Big{(}\log\epsilon-\log\big{(}1- \epsilon\big{)}+\omega_{ij}^{(s,t)}\Big{)}/\tau\bigg{)}\quad\text{where}\quad \epsilon\sim\text{Uniform}(0,1),\]

which returns an approximate Bernoulli sample for the edge \((i,j)\). When \(\tau\) is not sufficiently close to zero, this sample may not be close enough to binary, and in particular, it is strictly nonzero. The rationality of such an approximation is that with temperature \(\tau>0\), the gradient \(\frac{\partial\widehat{e}_{ij}^{(s,t)}}{\partial\omega_{ij}^{(s,t)}}\) is well-defined. The output of the binary concrete distribution is in the range of (0,1). To further alleviate the effects of small values by encouraging them to be exactly zero, we propose a "stretching and clipping" technique in the hard attention mechanism. To explicitly zero out an edge, we follow (Koland, 2017) and introduce two parameters, \(\gamma<0\) and \(\xi>1\), to remove small values

Figure 2. Backbone encoder architecture.
of \(\widetilde{\mathbf{u}}_{ij}^{(s,t)}\) given by

\[\widetilde{\mathbf{A}}_{ij}^{(t)}=\min\Big{(}1,\max\big{(}e_{ij}^{(s,t)},0\big{)} \Big{)}\quad\text{where}\quad e_{ij}^{(s,t)}=\widetilde{\mathbf{u}}_{ij}^{(s,t)}( \xi-\gamma)+\gamma.\]

The structural attention \(\widehat{\mathbf{A}}^{(t)}\) does not insert new edges to the graph (i.e., when \((i,j)\notin\mathcal{E}^{(t)},\widetilde{\mathbf{A}}_{ij}^{(t)}=0\)), but only removes (denoises) some edges \((i,j)\) originally in \(\mathcal{E}^{(t)}\). Then, we obtain the node embedding \(\widetilde{\mathbf{H}}^{(t)}\in\mathbb{R}^{N\times F}\) at the time step \(t\) after the structural aggregation with each row given by

\[\widetilde{\mathbf{h}}_{l}^{(t)}=\sigma\Big{(}\sum_{j\in\mathcal{N}_{l}^{(t)}} \widetilde{\mathbf{A}}_{ij}^{(t)}\mathbf{W}^{(s)}\mathbf{h}_{j}^{(t)}\Big{)}. \tag{5}\]

#### 3.2.2. Temporal Aggregation

In light of the dynamic and evolving nature of node features and inter-node relationships over time, temporal dependency holds paramount importance in the modeling of dynamic graphs. Existing methods either adopt RNN architectures, such as GRU (He et al., 2017) and LSTM (Hochreiter et al., 2015) or assume the Markov chain property (Srivastava et al., 2017) to capture the temporal dependencies in dynamic graphs. As shown in (Srivastava et al., 2017), despite their utility, these methods are insufficient in capturing long-range dependencies, thereby hindering their ability to generalize and model previously unseen graphs. To overcome this limitation, we propose a solution that leverages an attention-based temporal aggregation mechanism to adaptively integrate node embeddings from distant snapshots. This is achieved through the utilization of a buffer-dependent temporal mask, which serves as a temporal topology to guide the aggregation process.

In Equation 5, the structural attention provides the node embedding \(\widetilde{\mathbf{H}}^{(t)}\in\mathbb{R}^{N\times F}\) for each snapshot \(t\). Therefore, we have a set of node embedding \(\{\widetilde{\mathbf{H}}^{(t-B+1)},...,\widetilde{\mathbf{H}}^{(t)}\}\). Concatenating them to a 3-dimensional tensor and take transpose, for each node \(i\), we have a buffer-dependent node embedding \(\widetilde{\mathbf{H}}^{(t)}\in\mathbb{R}^{B\times F}\), \(\widehat{\mathbf{H}}^{(i)}=\{\widetilde{\mathbf{h}}_{t-B+1},...,\widetilde{\mathbf{h}}_{t }\},\widetilde{\mathbf{h}}_{t}\in\mathbb{R}^{F}\). We propose the temporal attention given by

\[\widetilde{\mathbf{A}}_{t_{k},t_{j}}^{(t)}=\text{softmax}_{t_{j}} \Big{(}\omega_{t_{k},t_{j}}^{(t)}\Big{)}=\frac{\exp\Big{(}\omega_{t_{k},t_{j}} ^{(t)}\Big{)}}{\sum_{t_{p}\in\mathcal{M}_{k}}\exp\Big{(}\omega_{t_{k},t_{p}}^{ (s,t_{j})}\Big{)}}, \tag{6}\]

where \(\widetilde{\mathbf{A}}^{(i)}\) is the temporal attention for node \(i\), \(\mathbf{W}\) is a weight matrix for linear transformation, \(\mathbf{a}\) is a weight vector for single-layer network, \(\mathcal{M}_{k}\) is the time steps that has element 1 in the temporal mask. The values in \(\widetilde{\mathbf{A}}^{(i)}\in\mathbb{R}^{B\times B}\) indicate the importance of relations between the embedding for node \(i\) at the past snapshots. We compute Equation 6 and 7 in batch for acceleration due to the graphs usually have large numbers of nodes. Then, after the temporal attention, we obtain the node embedding \(\mathbf{H}^{(i)}\in\mathbb{R}^{B\times K}\) for each node \(i\) for all the B snapshots in the buffer, with each row given by

\[\mathbf{h}_{t_{k}}^{{}^{\prime}(i)}=\sigma\Big{(}\sum_{t_{j}\in\mathcal{M}_{k}} \widetilde{\mathbf{A}}_{t_{k},t_{j}}^{(t)}\mathbf{W}\mathbf{h}_{t_{j}}^{(i)}\Big{)}. \tag{8}\]

Therefore, we have the embedding of node \(i\) at time \(t\) is \(\mathbf{h}_{t}^{{}^{\prime}(i)}\in\mathbb{R}^{K}\), and the embedding of all nodes results in \(\mathbf{H}^{{}^{\prime}(t)}\in\mathbb{R}^{N\times K}\), \(\mathbf{H}^{{}^{\prime}(t)}=\{\mathbf{h}_{t}^{(0)},...,\mathbf{h}_{t}^{{}^{\prime}(N-1)}\}\).

### Regularizations

The framework of DyExplainer is flexible with various regularization terms to preserve desired properties on the explanation. Inspired by the graph contrastive learning that makes the node representations more discriminative to capture different types of node-level similarity, we propose a structural consistency and a continuity consistency. We now discuss the regularization terms as well as their principles.

#### 3.3.1. Consistency Regularization

Inspired by the homophily nature of graph-structured data (Kipf and Welling, 2017), we propose a topology-wise regularization to encourage consistent explanations of the connected nodes in a graph. Specifically, on the graph \(G^{(t)}=\{\mathcal{V},\mathcal{E}^{(t)}\}\), for a node \(i\in\mathcal{V}\), we sample a positive pair \((i,p)\), the edge \(e_{i,p}\in\mathcal{E}^{(t)}\). We sample unconnected pairs \((i,j)\) such that \(e_{i,j}\notin\mathcal{E}^{(t)}\) to form a set of non-negative samples \(\widetilde{\mathbf{N}}_{i}\), then we propose the consistency regularization for the structural attention \(\widetilde{\mathbf{A}}^{(t)}\) as

\[\mathcal{L}_{cons}=-\log\frac{\exp\left(\text{sim}\Big{(}\widetilde{\mathbf{A}}_{i }^{(t)},\widetilde{\mathbf{A}}_{p}^{(t)}\Big{)}\right)}{\exp\left(\text{sim} \Big{(}\widetilde{\mathbf{A}}_{i}^{(t)},\widetilde{\mathbf{A}}_{p}^{(t)}\Big{)} \right)+\sum_{j\in\widetilde{\mathbf{N}}_{i}}\exp\left(\text{sim}\Big{(} \widetilde{\mathbf{A}}_{i}^{(t)},\widetilde{\mathbf{A}}_{j}^{(t)}\Big{)}\right)}. \tag{9}\]

Note that the computation of Equation 9 is very time-consuming for graphs with large numbers of nodes and edges. In practice, we select some anchors to compute the \(\mathcal{L}_{cons}\).

#### 3.3.2. Continuity Regularization

As suggested in (Kipf and Welling, 2017), preserving continuity ensures the robustness of explanations that small variations applied to the input, for which the model prediction is nearly unchanged, will not lead to large differences in the explanation. In addition, continuity benefits generalizability beyond a particular input instance. Based on the practical principle, in dynamic graphs, we aim to maintain a consistent explanation of snapshots even as the graph structure evolves. Inspired by the idea in (Srivastava et al., 2017) that two close subsequences are considered as a positive pair while the ones with large distances are the negatives, we propose a continuity regularization.

For a snapshot \(G^{t}\), a positive pair \((G^{t},G^{p})\) is sampled from the sliding window in the temporal mask. The set of non-negative samples \(\tilde{\mathbf{N}}_{t}\) is historical snapshots that are not in the buffer. Then, the continuity regularization for each node \(i\) is given by

\[\mathcal{L}_{cont}=-\log\frac{\exp\left(\text{sim}\Big{(}\widetilde{\mathbf{A}}_{i }^{(t)},\widetilde{\mathbf{A}}_{i}^{(p)}\Big{)}\right)}{\exp\left(\text{sim} \Big{(}\widetilde{\mathbf{A}}_{i}^{(t)},\widetilde{\mathbf{A}}_{i}^{(p)}\Big{)}\right)+ \sum_{k\in\tilde{\mathbf{N}}_{t}}\exp\left(\text{sim}\Big{(}\widetilde{\mathbf{A}}_{i}^{(t )},\widetilde{\mathbf{A}}_{i}^{(k)}\Big{)}\right)}, \tag{10}\]

where \(\widetilde{\mathbf{A}}_{i}^{(t)}\in\mathbb{R}^{B\times B}\) is the temporal attention of node \(i\) on \(G^{t}\). To compute Equation 10 for all of the nodes instead of one-by-one, we form a block diagonal matrix with each diagonal block be the attention corresponding to each node, say \(\widetilde{\mathbf{A}}_{\text{block}}^{(t)}=\text{diag}\Big{(}\widetilde{\mathbf{A}}_{0 }^{(t)},...,\widetilde{\mathbf{A}}_{N}^{(t)}\Big{)}\).

### Buffer-based live-update

After we obtain the node embedding \(\mathbf{H}^{{}^{\prime}(t)}\in\mathbb{R}^{N\times K}\) for the current snapshot, DyExplainer uses an MLP to predict the probability of a future edge from node \(i\) to \(j\). We compute a cross entropy loss
between the predictions and the edge labels at the future snapshot. After all, we have the objective function

\[\mathcal{L}=(1-\alpha-\beta)\mathcal{L}_{ce}+\alpha\mathcal{L}_{cons}+\beta \mathcal{L}_{cont}. \tag{11}\]

Inspired by ROLAND (Roland, 2018), we develop a buffer-based live-update algorithm to train the model. The key idea is to balance the efficiency and the aggregation from historical embeddings. Specifically, we update the backbone lively and fine-tuning the attention modules with the node embedding from the buffer. Note that the backbone is updated based on cross-entropy loss because without attention module, the terms \(\mathcal{L}_{cons}\) and \(\mathcal{L}_{cont}\) are zeros. We provide the details in Algorithm 1.

```
1:Input: Dynamic graphs \(\mathcal{G}=(G^{(1)},...,G^{(T)})\), link prediction labels \(y_{1},...y_{T}\), number of snapshots \(T\), maximum fine-tuning epoch \(E\), maximum buffer size \(B\), trade-off parameters \(\alpha\) and \(\beta\), the DyExplainer model.
2:Initialize the node state \(H^{(0)}\) and an empty queue as a buffer with size 0;
3:for\(t=1,...,T-1\)do
4: Train and update the backbone module based on \(y_{t}\) with early stopping and get \(H^{(t)}\);
5:if Buffer size \(<\) B then
6: Insert \(\mathbf{H}^{(t)}\) into the buffer;
7:else
8: Delete \(\mathbf{H}^{(t-B)}\) and insert \(\mathbf{H}^{(t)}\),
9:endif
10:for\(e=1,...,E\)do
11: Input the node embedding stored in the buffer to the structural attention and get \(\hat{\mathbf{H}}^{(t)}\), as described in Section 3.2.1;
12: Compute \(\mathcal{L}_{cons}\) in equation 9;
13: Input the structural node embedding to the temporal attention and get \(\mathbf{H}^{(t)}\), as described in Section 3.2.2;
14: Compute \(\mathcal{L}_{cont}\) in equation 10;
15: Compute \(\mathcal{L}\) in equation 11;
16: Train and Update the attention modules based on \(y_{t}\).
17:endfor
18:endfor
```

**Algorithm 1**Buffer-based live-update algorithm.

## 4. Experiments

To evaluate the performance of the DyExplainer, we compare it against state-of-the-art baselines. Our findings demonstrate the effectiveness in model generalization for link predictionFurthermore, we quantitatively validate the accuracy of its explanations. We also delve deeper with ablation studies and case studies, offering a deeper understanding of the proposed method.

### Experimental Setup

**Datasets.** The experiments are performed on six widely used data sets in the following list. The data set (1) AS-733 is an autonomous systems dataset of traffic flows among routers comprising the Internet (Kang et al., 2017). (2) Reddit-Title and (3) Reddit-Body are networks of subreddit-to-subreddit hyperlinks extracted from posts. The posts contain hyperlinks that connect one subreddit to another. The edge label shows if the source post expresses negativity towards the target post (Kang et al., 2017). (4) UCI-Message is composed of private communications exchanged on an online social network system among students (Kang et al., 2017). The data sets Bitcoin-OTC and Bitcoin-Alpha consist of "who-trusts-whom" networks of individuals who engage in trading on these platforms (Kang et al., 2017; Kang et al., 2018).

**Baselines.** We compare DyExplainer with both link prediction methods and explainable methods. For link prediction methods, we use 7 state-of-the-art dynamic GNNs. The (1) EvolveGCN-H and (2) EvolveGCN-O models employ an RNN to dynamically adapt the weights of internal GNNs, enabling the GNN to change during testing (Kang et al., 2017). (3) T-GCN integrates a GNN into the GRU cell by replacing the linear transformations in GRU with graph convolution operators (Zhu et al., 2017). The (4) GCRN-GRU and (5) GCRN-LSTM methods are widely adopted baselines that are generalized to capture temporal information by incorporating either a GRU or an LSTM layer. GCRN uses a ChebNet (Chen et al., 2017) for spatial information and separate GNNs to compute different gates of RNNs. The (6) GCRN-Baseline first builds node features using a Chebyshev spectral graph convolution layer to capture spatial information, then feeds these features into an LSTM cell to extract temporal information (Zhu et al., 2017). The (7) ROLAND views the node embeddings at different layers in the GNNs as hierarchical node states, which it updates recurrently over time. It integrates advanced design features from static GNNs and enables lively updating. Throughout our experiments, we use the GRU-based ROLAND which is shown to perform better than the others (Roland, 2018).

To evaluate the effectiveness of explainability, we compare DyExplainer with GNNExplainer (Zhu et al., 2017) and a gradient-based method (Grad). (1) GNNExplainer is a post-hoc state-of-the-art method providing explanations for every single instance. (2). Grad learns weights of edges by computing gradients of the model's objective function w.r.t. the adjacency matrix.

**Metrics.** For measuring link prediction performance, we use the standard mean reciprocal rank (MRR). For evaluating the faithfulness of explainability, we mainly use the Fidelity score of probability (Zhu et al., 2017). We let \(\mathcal{G}^{t}=\{\mathcal{V}_{t},\mathcal{E}_{t}\}\) be the graph at the snapshot \(t\), with \(\mathcal{V}_{t}\) a set of vertices and \(\mathcal{E}_{t}\) a set of edges. For snapshot \(t\), there is a set of edges \(\mathcal{E}^{\prime}_{t}\) needed to make predictions. After training the DyExplainer, we obtain an explanation mask \(\mathbf{M}_{t}\in\{0,1\}^{n\times n}\) for the snapshot \(\mathcal{G}^{t}\), with each element 0 or 1 to indicate whether the corresponding edge is identified as important. According to \(\mathbf{M}_{t}\) we obtain the important edges in \(\mathcal{G}^{t}\) to create a new graph \(\hat{\mathcal{G}}^{t}\). The Fidelity score is computed as

\[Fidelity=\frac{1}{\left|\mathcal{E}^{\prime}_{t}\right|}\sum_{i=1}^{\left| \mathcal{E}^{\prime}_{t}\right|}\left|f(\mathcal{G}^{t})_{\mathcal{E}^{\prime}_ {t}}-f(\hat{\mathcal{G}}^{t})_{\mathcal{E}^{\prime}_{t}}\right|, \tag{12}\]

where \(\left|\mathcal{E}^{\prime}_{t}\right|\) is the number of edges need to predict, \(f\left(\mathcal{G}^{t}\right)_{\mathcal{E}^{\prime}_{t}}\) means the predicted probability of edge \(\mathcal{e}^{\prime}_{t}\in\mathcal{E}^{\prime}_{t}\). We follow (Zhu et al., 2017; Wang et al., 2019) to compute the Fidelity scores at different sparsity given by

\[Sparsity=1-\frac{\left|\mathbf{M}_{t}\right|}{\left|\mathcal{E}_{t}\right|}, \tag{13}\]

where \(\left|\mathbf{M}_{t}\right|\) is the number of important edges identified in \(\mathbf{M}_{t}\) and \(\left|\mathcal{E}_{t}\right|\) means the number of edges in \(\mathcal{G}_{t}\).

**Implementation details.** To ensure a fair comparison, all methods were trained through live updating as outlined in (Roland, 2018). The evaluation is supposed to happen at each snapshot, however, models training on streaming data with early-stopping usually do not
converge in the early epochs. Therefore, we report the average of MRR of the most recent 60% snapshots. The hyper-parameter space of the DyExplainer model is similar to the hyper-parameter space of the underlying static GNN layers. For all methods, the node state hidden dimensions are set to 128 with GNN layers featuring skip connection, sum aggregation, and batch normalization. The DyExplainer is trained for a maximum of 100 epochs in each time step before early stopping, and its explainable module is fine-tuned for several additional epochs. For the attention modules, the slope in LeakyReLU is set to 0.2. We follow the practice in (Chen et al., 2017) to adopt the exponential decay strategy by starting the training with a high temperature of 1.0, and annealing to a small value of 0.1. For each dataset, we follow (Wang et al., 2018) of the parameter settings in the backbone. we use grid search to tune the hyperparameters of DyExplainer. Specifically, we tune: (1) The hidden dimension for structural and temporal attention modules (8, 16); (2) the learning rate for live-update the backbone (0.001 to 0.02); (3) the learning rate for fine-tuning the explainable module (0.001 to 0.1); (4) buffer size of the explainable module (3 to 20); (5) trade-off parameters \(\alpha\) for temporal regularization and \(\beta\) for structural regularization (0 to 1).

**Computing environment.** We implemented all models using PyTorch (Krizhevsky et al., 2015), PyTorch Geometric (Abadi et al., 2015), and Scikit-learn (Krizhevsky et al., 2015). All data sets used in the experiments are obtained from (Krizhevsky et al., 2015). We conduct the experiments on a server with four NVIDIA RTX A6000 GPUs (48GB memory each).

### Link Prediction Performance

Table 1 showcases the MRR results for all compared methods on all datasets, which were all trained through live updating. The results are obtained by averaging the MRR of the most recent 60% snapshots on the test datasets. The buffer size for DyExplainer was set to 5 across all datasets, and the attention module was fine-tuned for 4 epochs. The ROLAND method outperforms the other baselines on most datasets. DyExplainer surpasses the best baseline on 4 datasets, showing a 7.89% improvement on Bitcoin-Alpha, and performs similarly to the best baseline on the remaining datasets. This effectively demonstrates the Rashomon set theory (Rashomon et al., 2017; Rashomon et al., 2017), and highlights the benefits of seeking a simple and understandable model, which can result in improved robustness and better overall performance.

### Ablation Study

To present deep insights into the proposed method, we conducted multiple ablation studies on the Bitcoin-Alpha dataset to empirically verify the effectiveness of the proposed explainable aggregations and the contrastive regularizations. Specifically, we compare DyExplainer with variants. (1) w/o structural attention and w/o temporal attention are the DyExplainer without one of the attention modules in the explainable aggregations. (2) w/o consistency regularization and w/o continuity regularization refers to DyExplainer without one of the contrastive regularization terms in the loss. Results are shown in Figure 3.

From the figure, we observe that: (1) the performance of w/o structural attention is much worse than w/o temporal attention; (2) the performance of w/o consistency regularization is much worse than w/o continuity regularization. It is evident from both (1) and (2) that the topological information within a single snapshot holds greater sway over the prediction outcome, as compared to the temporal dependencies that exist between snapshots. (3) The results of the ablation studies performed on regularization and attention further reinforce the superiority of our approach over these alternatives.

### Explanations Performance

In order to demonstrate the reliability of the explanations provided by DyExplainer, we conduct quantitative evaluations that compare our approach with various baselines across three datasets characterized by a limited number of edges: UCI-Message, Bitcoin-OTC, and Bitcoin-Alpha. Specifically, we adopt the Fidelity vs. Sparsity

\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & AS-733 & Reddit-Title & Reddit-Body & UCI-Message & Bitcoin-OTC & Bitcoin-Alpha \\ \hline EvolveGCN-H & 0.263 \(\pm\) 0.098 & 0.156 \(\pm\) 0.121 & 0.072 \(\pm\) 0.010 & 0.055 \(\pm\) 0.011 & 0.081 \(\pm\) 0.025 & 0.054 \(\pm\) 0.019 \\ EvolveGCN-O & 0.180 \(\pm\) 0.104 & 0.015 \(\pm\) 0.019 & 0.093 \(\pm\) 0.022 & 0.028 \(\pm\) 0.005 & 0.018 \(\pm\) 0.008 & 0.005 \(\pm\) 0.006 \\ GCRN-GRU & **0.337 \(\pm\) 0.001** & 0.328 \(\pm\) 0.005 & 0.204 \(\pm\) 0.005 & 0.095 \(\pm\) 0.013 & 0.163 \(\pm\) 0.005 & 0.143 \(\pm\) 0.004 \\ GCRN-LSTM & 0.335 \(\pm\) 0.001 & 0.343 \(\pm\) 0.006 & 0.209 \(\pm\) 0.003 & **0.107 \(\pm\) 0.004** & 0.172 \(\pm\) 0.013 & 0.146 \(\pm\) 0.008 \\ GCRN-Baseline & 0.321 \(\pm\) 0.002 & 0.342 \(\pm\) 0.004 & 0.202 \(\pm\) 0.002 & 0.090 \(\pm\) 0.011 & 0.176 \(\pm\) 0.005 & **0.152 \(\pm\) 0.005** \\ TGCN & 0.335 \(\pm\) 0.001 & 0.382 \(\pm\) 0.005 & 0.234 \(\pm\) 0.004 & 0.080 \(\pm\) 0.015 & 0.080 \(\pm\) 0.006 & 0.060 \(\pm\) 0.014 \\ ROLAND & 0.330 \(\pm\) 0.004 & **0.384 \(\pm\) 0.013** & **0.342 \(\pm\) 0.008** & 0.090 \(\pm\) 0.010 & **0.189 \(\pm\) 0.008** & 0.147 \(\pm\) 0.006 \\ \hline DyExplainer & **0.341 \(\pm\) 0.000** & **0.383 \(\pm\) 0.002** & **0.335 \(\pm\) 0.010** & **0.109 \(\pm\) 0.004** & **0.194 \(\pm\) 0.002** & **0.164 \(\pm\) 0.002** \\ \hline \hline \end{tabular}
\end{table}
Table 1. Comparison of MRR for the DyExplainer and the baselines. Standard deviations are obtained by repeating each model training 5 times. For each data set, the two best cases are boldface.

Figure 3. Ablation studies on Bitcoin-Alpha.
metrics for our evaluation, in accordance with the methodology described in (Srivastava et al., 2017; Wang et al., 2018). The Fidelity metric assesses the accuracy with which the explanations reflect the significance of various factors to the model's predictions, while the Sparsity metric quantifies the proportion of structures that are deemed critical by the explanation techniques. For a fair comparison, for all three methods, we use a trained dynamic GNN (Wang et al., 2018) as the base model to calculate the predicted probability.

The baseline method, GNNExplainer, was not originally developed for dynamic graph settings. Nevertheless, for a fair comparison, we assess the Fidelity of both DyExplainer and GNNExplainer using only the graph at the final snapshot, despite the fact that DyExplainer provides explanations for all snapshots stored in a buffer. GNNExplainer identifies the most influential nodes within a k-hop neighborhood and generates a mask to highlight these nodes for a given prediction node. As our DyExplainer provides a global attention mechanism for the entire graph, for a fair comparison, we calculate the average Fidelity of each mask produced by GNNExplainer with respect to all of the edges. To obtain the Fidelity and Sparsity metrics for each mask, we select a subset of the top-ranked edges based on the weights from the explanation mask and use this subset to create a new graph. The Fidelity of an edge is defined as the difference between the predicted probability of that edge on the new graph and the global graph. For DyExplainer, we directly select the top-ranked edges based on the attention weights to form a new graph, as there is only one global attention mechanism that provides the explanation.

The comparison of Fidelity and Sparsity is presented in Figure 5. The evaluation of various methods is based on their Fidelity scores under comparable levels of Sparsity, as the Sparsity level cannot be precisely controlled. From the figure, we see that for all three datasets, the Fidelity of these methods increases as Sparsity increases. This is due to the calculation of Fidelity as the difference between the predicted probability of the model on the reduced graph and the original graph, leading to higher Fidelity values with greater Sparsity. Furthermore, GNNExplainer demonstrates superior Fidelity compared to Grad on Bitcoin-OTC and Bitcoin-Alpha, while performing similarly on UCI-Message. Additionally, DyExplainer outperforms both methods on all three datasets at varying Sparsity levels, revealing that it provides more accurate explanations.

### Case Studies

To show the evolving and continuity of underlying patterns the DyExplainer detects from the dynamic graph, we visualize the attention values of some edges at different snapshots on the Bitcoin-Alpha data set in Figure 4. From this figure, we observe that the edges \((192,62)\), \((193,295)\), \((203,297)\) and \((232,192)\) has close importance on snapshots 1-3. It indicates the temporal continuity of edge importance exists in dynamic graphs and our intuition is reasonable. The edges \((175,100)\), \((192,62)\), and \((468,462)\) are less important at snapshots 1-3 while becoming more important at snapshot 7. It infers that the importance of an edge is evolving along with the time steps.

We further visualize the temporal attention to show which historical snapshot has more influence on the current. The importance of snapshots provided by the temporal attention is shown in Figure 6. From the figure, we see that the most important snapshot to the current is snapshot 32. To see how the patterns have an effect, we randomly pick an edge \((623,26)\) at snapshot 35 to investigate the local structure of this edge at snapshot 32. The visualization of nodes 623 and 26 are shown in Figure 7. Note that these two nodes are unconnected at snapshot 32. The widths of edges are according to the weights of structural attention. Thicker ones mean large weights. From the figure, we can find that there are three clusters of substructures with larger weights, which can be viewed as important patterns that DyExplainer detects.

## 5. Related Work

The goal of explainability in GNNs is to provide transparency and accountability in the predictions of the models, especially when they are used in critical applications such as detecting the fraud (Krizhevsky et al., 2017) or medical diagnosis (Krizhevsky et al., 2017). Recently, many works are proposed to explain the GNN predictions, with a focus on diverse facets of the models from various perspectives. According to the type of explanation they provide, the methodologies can be categorized into two main classes: instance-level and model-level methods (Zhu et al., 2018).

The instance-level methods explain the GNN models by identifying the most influential features of the graph to the given prediction. Among them, some methods employ the gradients or the feature values to indicate the importance of features. SA (Beng et al., 2016) computes the gradient value as the importance score for each input feature. While it is easy to compute by the back-propagation, the results cannot accurately capture the importance of each feature due to the output changing minimally with respect to the input change, and a gradient value is hard to reflect the input contribution. CAM (Srivastava et al., 2017) maps the node features in the final layer to the input space to identify important nodes. However, the representation from the final layer of GNN may not reflect the node contribution because the feature distribution may change after mapping by a neural network. Another kind of method aims to provide instance-level explanations by a surrogate model that approximates the predictions of the original GNN model. GraphLine (Chen et al., 2017) provides a model-agnostic local explanation framework for the node classification task. It adopts the node feature and predicted labels in the K-hop neighbors of

Figure 4. Heat map of edge importance over time. We sample some edges shared by continuous snapshots and show their attention values. 0.0 means this edge does not appear in this snapshot.
the predicted node and trains an HSIC Lasso. GNNExplainer (GNNExplainer, 2017) takes a trained GNN and its predictions as inputs to provide explanations for a given instance, e.g. a node or a graph. The explanation includes a compact subgraph structure and a small subset of node features that are crucial in GNN's prediction for the target instance. However, the explanation provided by GNNExplainer is limited to a single instance, making GNNExplainer difficult to be applied in the inductive setting because the explanations are hard to generalize to other unexplained nodes. PGExplainer (Zhou et al., 2019) is proposed to provide a global understanding of predictions made by GNNs. It models the underlying structure as edge distributions where the explanatory graph is sampled. To explain the predictions of multiple instances, the generation process in PGExplainer is parameterized by a neural network. Similar to the PGExplainer, GraphMask (Girshick et al., 2018) trains a classifier to predict whether an edge can be dropped without affecting the original predictions. As a post-hoc method, GraphMask obtains an edge mask for each GNN layer. SubgraphX (Zhou et al., 2019) explains the GNN predictions as an efficient exploration of different subgraphs with Monte Carlo tree search. It adopts Shapley values as a measure of subgraph importance that also capture the interactions among different subgraphs. All of these methods are to provide explanations with respect to the GNN predictions. Different from them, this work provides a high-level understanding to explain the GNN models. The model-level methods that study what graph patterns can lead to a certain GNN behavior, e.g., the improvement of performance, is particularly related to us. There are fewer studies in this field. The method XGNN (Zhou et al., 2019) aims to explain GNNs by training a graph generator so that the generated graph patterns maximize a certain prediction of the model. The explanations by XGNN are general that provide a global understanding of the trained GNNs.

Current explainers for GNNs are limited to static graphs, hindering their application in dynamic scenarios. The explanation of dynamic GNNs is an under-studied area. Indeed, there is a recent work (Zhou et al., 2019) attempted to provide explanations on dynamic graphs by exploring backward relevance, but it is limited to a specific model TGCN. Besides, the work in (Beng et al., 2019) considers explaining time series predictions by temporal GNNs. The work (Beng et al., 2019) learns attention weights for a linear combination of node representations dynamic graphs, but it explains the model by detecting the node importance. There are distinct challenges in explaining dynamic GNNs in general. Firstly, existing explanation methods mainly focus on identifying the important parts of the data in relation to the GNN predictions. However, dynamic GNNs make predictions for each snapshot, making it difficult to provide explanations for a particular prediction as it depends on all previous snapshots. Secondly, it is challenging to provide a generalizable solution to interpret various types of dynamic GNNs. DyExplainer, on the other hand, provides model-level explanations for all dynamic GNNs, overcoming these limitations.

## 6. Conclusion

We present DyExplainer, a pioneering approach to explaining dynamic GNNs in real-time. DyExplainer leverages a dynamic GNN backbone to extract representations at each snapshot, concurrently exploring structural relationships and temporal dependencies through a sparse attention mechanism. To ensure structural consistency and temporal continuity in the explanation, our approach incorporates contrastive learning techniques and a buffer-based live-updating scheme. The results of our experiments showcase the superiority of DyExplainer, providing a faithful explanation of the model predictions while concurrently improving the accuracy of the model, as evidenced by the link prediction task.

Figure 5. The quantitative studies for different explanation methods on UCI-Message, Bitcoin-OTC, and Bitcoin-Alpha.

Figure 6. Heat map of temporal importance over time. The current snapshot is at 35. The buffer size is set to 10. It means we consider the importance of the previous snapshot from 27 to 34.

Figure 7. Local structure of node 26 and 623 (red nodes) on snapshot 32. Orange points are their 3-hop neighborhoods. The green edges are obtained from the structural attention weights at snapshot 32.