SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Temporal graphs are widely used to model dynamic systems with time-varying interactions. In real-world scenarios, the underlying mechanisms of generating future interactions in dynamic systems are typically governed by a set of recurring substructures within the graph, known as temporal motifs. Despite the success and prevalence of current temporal graph neural networks (TGNN), it remains uncertain which temporal motifs are recognized as the significant indications that trigger a certain prediction from the model, which is a critical challenge for advancing the explainability and trustworthiness of current TGNNs. To address this challenge, we propose a novel approach, called Temporal Motifs Explainer (TempME), which uncovers the most pivotal temporal motifs guiding the prediction of TGNNs. Derived from the information bottleneck principle, TempME extracts the most interaction-related motifs while minimizing the amount of contained information to preserve the sparsity and succinctness of the explanation. Events in the explanations generated by TempME are verified to be more spatiotemporally correlated than those of existing approaches, providing more understandable insights. Extensive experiments validate the superiority of TempME, with up to  $8.21\%$  increase in terms of explanation accuracy across six real-world datasets and up to  $22.96\%$  increase in boosting the prediction Average Precision of current TGNNs. $^{1}$
Temporal Graph Neural Networks (TGNN) are attracting a surge of interest in real-world applications, such as social networks, financial prediction, etc. These models exhibit the ability to capture both the topological properties of graphs and the evolving dependencies between interactions over time [1, 2, 3, 4, 5, 6, 7, 8]. Despite their widespread success, these models often lack transparency, functioning as black boxes. The provision of human-intelligible explanations for these models becomes imperative, enabling a better understanding of their decision-making logic and justifying the rationality behind their predictions. Therefore, improving explainability is fundamental in enhancing the trustworthiness of current TGNNs, making them reliable for deployment in real-world scenarios, particularly in high-stakes tasks like fraud detection and healthcare forecasting [9, 10, 11, 12].
The goal of explainability is to discover what patterns in data have been recognized that trigger certain predictions from the model. Explanation approaches on static graph neural networks have been well-studied recently [13, 14, 15, 16, 17, 18, 19]. These methods identify a small subset of important edges or nodes that contribute the most to the model's prediction. However, the success of these methods on static graphs cannot be easily generalized to the field of temporal graphs, due to the complex and volatile nature of dynamic networks [8, 4, 3]. Firstly, there can be duplicate events occurring at the same timestamp and the same position in temporal graphs. The complicated dependencies
<sup>1</sup>The code is available at https://github.com/Graph-and-Geometric-Learning/TempME.
between interactions were under-emphasized by existing explanation approaches [20, 21]. Moreover, the important events should be temporally proximate and spatially adjacent to construct a human-intelligible explanation [22]. We refer to explanations that satisfy these requirements as cohesive explanations. As illustrated in Figure 1(a), a non-cohesive explanation typically consists of scattered events (highlighted in purple). For instance, event 1 and event 10 in the disjointed explanation are neither temporally proximate nor spatially adjacent to other explanatory events, leading to a sub-optimal explanation and degrading the inspiration that explanations could bring us. There have been some recent attempts at TGNN explainability [21, 23]. Unfortunately, they all face the critical challenge of generating cohesive explanations and fall short of providing human-intelligible insights. Moreover, they entail high computational costs, making them impractical for real-world deployment.
To address the aforementioned challenges of temporal explanations, we propose to utilize temporal motifs in the explanation task. Temporal motifs refer to recurring substructures within the graph. Recent studies [24, 25, 26, 27, 28, 29, 30, 31] demonstrate that these temporal motifs are essential factors that control the generative mechanisms of future events in real-world temporal graphs and dynamic systems. For example, preferential attachment (Figure 1(c)) elucidates the influencer effect in e-commerce marketing graphs [32, 33]. Triadic closure (Figure 1(d)) explains the common-friend rules in social networks [34, 6, 1, 25]. Therefore, they are plausible and reliable composition units to explain TGNN predictions. Moreover, the intrinsic self-connectivity of temporal motifs guarantees the cohesive property of the generated explanations (Figure 1(b)).
Figure 1: (a) and (b): Non-cohesive explanation and cohesive explanation (highlighted in colors). (c) and (d): Temporal motifs govern the generation of future interactions (numbers denote event orders).
Proposed work. In the present work, we propose TempME, a novel Temporal Motif-based Explainer to identify the most determinant temporal motifs to explain the reasoning logic of temporal GNNs and justify the rationality of the predictions. TempME leverages historical events to train a generative model that captures the underlying distribution of explanatory motifs and thereby improves the explanation efficiency. TempME is theoretically grounded by Information Bottleneck (IB), which finds the best tradeoff between explanation accuracy and compression. To utilize Information Bottleneck in the context of temporal graphs, we incorporate a null model (i.e., a randomized reference) [22, 35, 36] into the model to better measure the information contained in the generated explanations. Thereby, TempME is capable of telling for each motif how the occurrence frequency difference in empirical networks and randomized reference reflects the importance to the model predictions. Different from previous works that only focus on the effect of singular events [23, 21], TempME is the first to bring additional knowledge about the effect of each temporal motif.
We evaluate TempME with three popular TGNN backbones, TGAT [3], TGN [4] and GraphMixer [5]. Extensive experiments demonstrate the superiority and efficiency of TempME in explaining the prediction behavior of these TGNNs and the potential in enhancing the prediction performance of TGNNs, achieving up to  $8.21\%$  increase in terms of explanation accuracy across six real-world datasets and up to  $22.96\%$  increase in boosting the prediction Average Precision of TGNNs.
The contributions of this paper are: (1) We are the first to utilize temporal motifs in the field of explanations for TGNNs to provide more insightful explanations; (2) We further consider the null model in the information bottleneck principle for the temporal explanation task; (3) The discovered temporal motifs not only explain the predictions of different TGNNs but also exhibit ability in enhancing their link prediction performance.
GNN Explainability Explainability methods for Graph Neural Networks can be broadly classified into two categories: non-generative and generative methods. Given an input instance with its
prediction, non-generative methods typically utilize gradients [15, 37], perturbations [38, 39], relevant walks [40], mask optimization [13], surrogate models [41], and Monte Carlo Tree Search (MCTS) [16] to search the explanation subgraph. These methods optimize the explanation one by one during the explanation stage, leading to a longer inference time. On the contrary, generative methods train a generative model across the entire dataset by learning the distribution of the underlying explanatory subgraphs [19, 18, 14, 42, 43, 44, 45], which obtains holistic knowledge of the model behavior over the whole dataset. Compared with static GNN, the explainability of temporal graph neural networks (TGNNs) remain challenging and under-explored. TGNNExplainer [23] is the first explainer tailored for temporal GNNs, which relies on the MCTS algorithm to search for a combination of the explanatory events. Recent work [21] utilizes the probabilistic graphical model to generate explanations for discrete time series on the graph, leaving the continuous-time setting underexplored. However, these methods cannot guarantee cohesive explanations and require significant computation costs. There are also some works that have considered intrinsic interpretation in temporal graphs [26] and seek the self-interpretable models [46, 20]. As ignored by previous works on temporal explanation, we aim for cohesive explanations that are human-understandable and insightful in a generative manner for better efficiency during the explanation stage.
Network Motifs The concept of network motifs is defined as recurring and significant patterns of interconnections [35], which are building blocks for complex networks [47, 24]. Kovanen et al. [22] proposed the first notion of temporal network motifs with edge timestamps, followed by relaxed versions to involve more diverse temporal motifs [48, 24, 49]. Early efforts developed efficient motif discovery algorithms, e.g., MFinder [50], MAVisto [51], Kavosh [36], etc. The standard interpretation of the motif counting is presented in terms of a null model, which is a randomized version of the real-world network [35, 52, 22, 53]. Another research line of network motifs focuses on improving network representation learning with local motifs [54, 55, 56]. These approaches emphasize the advantages of incorporating motifs into representation learning, leading to improved performance on downstream tasks. In this work, we constitute the first attempt to involve temporal motifs in the explanation task and target to uncover the decision-making logic of temporal GNNs.
Temporal Graph Neural Network. We treat the temporal graph as a sequence of continuous timestamped events, following the setting in TGNNExplainer [23]. Formally, a temporal graph can be represented as a function of timestamp  $t$  by  $\mathcal{G}(t) = \{\mathcal{V}(t),\mathcal{E}(t)\}$ , where  $\mathcal{V}(t)$  and  $\mathcal{E}(t)$  denote the set of nodes and events that occur before timestamp  $t$ . Each element  $e_k$  in  $\mathcal{E}(t)$  is represented as  $e_k = (u_k,v_k,t_k,a_k)$ , denoting that node  $u_k$  and node  $v_k$  have an interaction event at timestamp  $t_k < t$  with the event attribution  $a_k$ . Without loss of generality, we assume that interaction is undirected [5, 1]. Temporal Graph Neural Networks (TGNN) take as input a temporal graph  $\mathcal{G}(t)$  and learn a time-aware embedding for each node in  $\mathcal{V}(t)$ . TGNNs' capability for representation learning on temporal graphs is typically evaluated by their link prediction performance [57, 1, 25], i.e., predicting the future interaction based on historical events. In this work, we also focus on explaining the link prediction behavior of TGNNs, which can be readily extended to node classification tasks.
Explanation for Temporal Graph Neural Network. Let  $f$  denote a well-trained TGNN (aka. base model). To predict whether an interaction event  $e$  happens between  $u$  and  $v$  at timestamp  $t$ , the base model  $f$  leverages the time-aware node representation  $x_{u}(t)$  and  $x_{v}(t)$  to output the logit/probability. An explainer aims at identifying a subset of important historical events from  $\mathcal{E}(t)$  that trigger the future interaction prediction made by the base model  $f$ . The subset of important events is known as an explanation. Formally, let  $Y_{f}[e]$  denote the binary prediction of event  $e$  made by base model  $f$ , the explanation task can be formulated as the following problem that optimizes the mutual information between the explanation and the original model prediciton [13, 23]:
$$
\operatorname {a r g m a x} _ {| \mathcal {G} _ {\mathrm {e x p}} ^ {e} | \leq K} I \left(Y _ {f} [ e ]; \mathcal {G} _ {\mathrm {e x p}} ^ {e}\right) \quad \Leftrightarrow \quad \underset {| \mathcal {G} _ {\mathrm {e x p}} ^ {e} | \leq K} {\operatorname {a r g m i n}} - \sum_ {c = 0, 1} \mathbb {1} \left(Y _ {f} [ e ] = c\right) \log \left(f \left(\mathcal {G} _ {\mathrm {e x p}} ^ {e}\right) [ e ]\right) \tag {1}
$$
where  $I(\cdot, \cdot)$  denotes the mutual information function,  $e$  is the interaction event to be explained,  $\mathcal{G}_{\mathrm{exp}}^{e}$  denotes the explanation constructed by important events from  $\mathcal{V}(t)$  for  $e$ .  $f(\mathcal{G}_{\mathrm{exp}}^{e})[e]$  is the probability output on the event  $e$  predicted by the base model  $f$ .  $K$  is the explanation budget on the explanation size (i.e., the number of events in  $\mathcal{G}_{\mathrm{exp}}^{e}$ ).
4 Proposed Method: TempME
A simple optimization of Eq. 1 easily results in disjointed explanations [23]. Therefore, we utilize temporal motifs to ensure that the generated explanations are meaningful and understandable.
The pipeline of TempME is shown in Figure 2. Given a temporal graph and a future prediction between node  $u$  and node  $v$  to be explained, TempME first samples surrounding temporal motif instances (Sec. 4.1). Then a Motif Encoder creates expressive Motif Embedding for each extracted motif instance, which consists of three main steps: event anonymization, message passing, and graph pooling (Sec. 4.2). Based on Information-bottleneck (IB) principle, TempME characterizes the importance scores of these temporal motifs, under the constraints of both explanation accuracy and information compression (Sec. 4.3). In the explanation stage, succinct and cohesive explanations are constructed by sampling from the Bernoulli distribution controlled by the importance score  $p$  for the prediction behavior of the base model.
Figure 2: Framework of TempME. Numbers on the edge denote the event order.
4.1 Temporal Motif Extraction
We first extract a candidate set of motifs whose importance scores are to be derived. Intuitively, event orders encode temporal causality and correlation. Therefore, we constrain events to reverse over the direction of time in each motif and propose the following Retrospective Temporal Motif.
Definition 1. Given a temporal graph and node  $u_0$  at time  $t_0$ , a sequence of  $l$  events, denotes as  $I = \{(u_1, v_1, t_1), (u_2, v_2, t_2), \dots, (u_l, v_l, t_l)\}$  is a  $n$ -node,  $l$ -length,  $\delta$ -duration Retrospective Temporal Motif of node  $u_0$  if the events are reversely time ordered within a  $\delta$  duration, i.e.,  $t_0 > t_1 > t_2 > \dots > t_l$  and  $t_0 - t_l \leq \delta$ , such that  $u_1 = u_0$  and the induced subgraph is connected and contains  $n$  nodes.
Temporal dependencies are typically revealed by the relative order of the event occurrences rather than the absolute time difference. Consequently, we have the following definition of equivalence.
Definition 2. Two temporal motif instances  $I_{1}$  and  $I_{2}$  are equivalent if they have the same topology and their events occur in the same order, denoted as  $I_{1} \simeq I_{2}$ .
Temporal Motifs are regarded as important building blocks of complex dynamic systems [52, 35, 22, 50]. Due to the large computational complexity in searching high-order temporal motifs, recent works show the great potential of utilizing lower-order temporal motifs, e.g., two-length motifs [52] and three-node motifs [24, 55, 58], as units to analyze large-scale real-world temporal graphs. A collection of temporal motifs with up to 3 nodes and 3 events is shown in Appendix B.
Given a temporal graph with historical events  $\mathcal{E}$  and node  $u_{0}$  of interest at time  $t_0$ , we sample  $C$  retrospective temporal motifs with at most  $n$  nodes and  $l$  events, starting from  $u_{0}$  ( $\delta$  is usually set as 1 large for the comprehensiveness of motifs). Alg. 1 shows our Temporal Motif Sampling approach, where  $\mathcal{E}(S,t)$  denotes the set of historical events that occur to any node in  $S$  before time  $t$ . At each step, we sample one event from the set of historical events related to the current node set. Alg. 1 adapts Mfinder [50], a motif mining algorithm on static graphs, to the scenario of temporal graphs. We could also assign different sampling probabilities to historical events in Step 3 in Alg. 1 to obtain temporally biased samples. Since the purpose of
Algorithm 1: Temporal Motif Sampling  $(\mathcal{E},n,l,u_0,t_0,C);l\geq n$
Node set:  $S_{c} \gets \{u_{0}\}$ , for  $1 \leq c \leq C$
Event sequence:  $\dot{I}_c \gets ()$ , for  $1 \leq c \leq C$
for  $c = 1$  to  $C$  do
for  $j = 1$  to  $l$  do Sample one event  $e_j = (u_j,v_j,t_j)$  from  $\mathcal{E}(S_c,t_{j - 1})$  if  $|S_{c}| <   n$  then  $S_{c} = S_{c}\cup \{u_{j},v_{j}\}$ $I_{c} = I_{c}\parallel e_{j}$
return  $\{I_c\mid 1\leq c\leq C\}$
our sampling is to collect a candidate set of expressive temporal motifs for the explanation, we implement uniform sampling in Step 3 for algorithmic efficiency.
Relation to Previously Proposed Concepts. Recent works [1, 6] propose to utilize temporal walks and recurrent neural networks (RNN) [59] to aggregate sequential information. Conceptually, temporal walks construct a subset of temporal motif instances in this work. In contrast, temporal motifs capture more graph patterns for a holistic view of the governing rules in dynamic systems. For instance, the motif of preferential attachment (Fig. 1(c)) cannot be represented as temporal walks.
4.2 Temporal Motif Embedding
In the present work, we focus on explaining the link prediction of temporal graph neural networks. Given an interaction prediction between node  $u$  and node  $v$  to be explained, we sample  $C$  surrounding temporal motif instances starting from  $u$  and  $v$ , respectively, denoted as  $M_u$  and  $M_v$ . Note the proposed framework is also flexible for explaining other graph-related problems. For instance, to explain the node classification on dynamic graphs, we sample  $C$  temporal motif instances around the node of interest. Each temporal motif is represented as  $(e_1, e_2, \dots, e_l)$  with  $e_i = (u_i, v_i, t_i)$  satisfying Definition 1. We design a Motif Encoder to learn motif-level representations for each surrounding motif in  $M_u$  and  $M_v$ .
Event Anonymization. The anonymization technique is at the core of many sequential feature distillation algorithms [1, 6, 60, 61]. Previous works [6, 1] mainly focus on node anonymization, while temporal motifs are constructed by sequences of temporal events. To bridge this gap, we consider the following event anonymization to adapt to temporal motifs. To maintain the inductiveness, we create structural features to anatomize event identities by counting the appearance at certain positions:
$$
h \left(e _ {i}, u, v\right) [ j ] = | \left\{I \mid I \in M _ {u} \cup M _ {v}, I [ j ] = \left(u _ {i}, v _ {i}, t\right); \forall t \right\} |, f o r i \in \{1, 2, \dots , l \}. \tag {2}
$$
$h(e_i, u, v)$  (abbreviated as  $h(e_i)$  for simplicity) is a  $l$ -dimensional structural feature of  $e_i$  where the  $j$ -th element denotes the number of interactions between  $u_i$  and  $v_i$  at the  $j$ -th sampling position in  $M_u \cup M_v$ .  $h(e_i)$  essentially encodes both spatial and temporal roles of event  $e_i$ .
Temporal Motif Encoding. The extracted temporal motif is essentially a subgraph of the original temporal graph. Instead of using sequential encoders, we utilize local message passing to distill motif-level embedding. Given a motif instance  $I$  with node set  $\mathcal{V}_I$  and event set  $\mathcal{E}_I$ , let  $X_p$  denote the associated feature of node  $p \in \mathcal{V}_I$ .  $E_{pq} = (a_{pq} \| T(t - t_{pq}) \| h(e_{pq}))$  denotes the event feature of event  $e_{pq} \in \mathcal{E}_I$ , where  $a_{pq}$  is the associated event attribute and  $h(e_{pq})$  refers to the structural feature of event  $e_{pq}$  (Eq. 2). Note that the impact of motifs varies depending on the time intervals. For instance, motifs occurring within a single day differ from those occurring within a year. Thus, we need a time encoder  $T(\cdot)$  which maps the time interval into 2d-dimensional vectors via  $T(\Delta t) = \sqrt{1 / d} [\cos(w_1 \Delta t), \sin(w_1 \Delta t), \dots, \cos(w_d \Delta t), \sin(w_d \Delta t)]$  with learnable parameters  $w_1, \dots, w_d$  [52, 1]. To derive the motif-level embedding, we initially perform message passing to aggregate neighboring information and then apply the READOUT function to pool node features.
$$
\tilde {X} _ {p} = \text {M E S S A G E P A S S I N G} \left(X _ {p}; \left\{X _ {q}; E _ {p q} \mid q \in \mathcal {N} (p) \right\}\right) \text {a n d} m _ {I} = \text {R e A D O U T} \left(\left\{\tilde {X} _ {p}, p \in \mathcal {V} _ {I} \right\}\right) \tag {3}
$$
Following Eq. 3, one may use GIN [62] or GAT [63] inMESSAGEPASSING step and simple mean-pooling or learnable adaptive-pooling [64] as READOUT function to further capture powerful motif representations. We refer to Appendix D.4 for more details about the Temporal Motif Encoder.
4.3 Information-Bottleneck-based Generator
Motivation. A standard analysis for temporal motif distribution is typically associated with the null model, a randomized version of the empirical network [22, 50, 35]. The temporal motif that behaves statistically differently in the occurrence frequency from that of the null model is considered to be structurally significant. Therefore, we assume the information of temporal motifs can be disentangled into interaction-related and interaction-irrelevant ones. The latter is natural result of the null model. Based on this assumption, we resort to the information bottleneck technique to extract compressed components that are the most interaction-related. We refer to Appendix C for theoretical proofs.
Sampling from Distribution. Given an explanation query and a motif embedding  $m_I$  with  $I \in \mathcal{M}$ , where  $\mathcal{M}$  denotes the set of extracted temporal motifs, we adopt an MLP for mapping  $m_I$  to an importance score  $p_I \in [0,1]$ , which measures the significance of this temporal motif instance for the explanation query. We sample a mask  $\alpha_I \sim \text{Bernoulli}(p_I)$  for each temporal motif instance and then apply the masks to screen for a subset of important temporal motif instances via  $\mathcal{M}_{\mathrm{exp}} = A \odot \mathcal{M}$ .
$A$  is the mask vector constructed by  $\alpha_{I}$  for each motif  $I$  and  $\odot$  denotes element-wise product. The explanation subgraph for the query can thus be induced by all events that occur in  $\mathcal{M}_{\mathrm{exp}}$ .
To back-propagate the gradients w.r.t. the probability  $p_I$  during the training stage, we use the Concrete relaxation of the Bernoulli distribution [65] via Bernoulli $(p) \approx \sigma(\frac{1}{\lambda} (\log p - \log (1 - p) + \log u - \log (1 - u)))$ , where  $u \sim \text{Uniform}(0, 1)$ ,  $\lambda$  is a temperature for the Concrete distribution and  $\sigma$  is the sigmoid function. In the inference stage, we randomly sample discrete masks from the Bernoulli distribution without relaxation. Then we induce a temporal subgraph with  $\mathcal{M}_{\mathrm{exp}}$  as the explanation. One can also rank all temporal motifs by their importance scores and select the Top  $K$  important motifs to induce more compact explanations if there is a certain explanation budget in practice.
Information Bottleneck Objective. Let  $\mathcal{G}_{\mathrm{exp}}^e$  and  $\mathcal{G}(e)$  denote the explanation and the computational graph of event  $e$  (i.e., historical events that the base model used to predict  $e$ ). To distill the most interaction-related while compressed explanation, the IB objective maximizes mutual information with the target prediction while minimizing mutual information with the original temporal graph:
$$
\min  - I \left(\mathcal {G} _ {\exp} ^ {e}, Y _ {f} [ e ]\right) + \beta I \left(\mathcal {G} _ {\exp} ^ {e}, \mathcal {G} (e)\right), \quad s. t. | \mathcal {G} _ {\exp} ^ {e} | \leq K \tag {4}
$$