GANExplainer: GAN-based Graph Neural Networks Explainer
With the rapid deployment of graph neural networks (GNNs) based techniques
into a wide range of applications such as link prediction, node classification,
and graph classification the explainability of GNNs has become an indispensable
component for predictive and trustworthy decision-making. Thus, it is critical
to explain why graph neural network (GNN) makes particular predictions for them
to be believed in many applications. Some GNNs explainers have been proposed
recently. However, they lack to generate accurate and real explanations. To
mitigate these limitations, we propose GANExplainer, based on Generative
Adversarial Network (GAN) architecture. GANExplainer is composed of a generator
to create explanations and a discriminator to assist with the Generator
development. We investigate the explanation accuracy of our models by comparing
the performance of GANExplainer with other state-of-the-art methods. Our
empirical results on synthetic datasets indicate that GANExplainer improves
explanation accuracy by up to 35\% compared to its alternatives.
Yiqiao Li, Jianlong Zhou, Boyuan Zheng, Fang Chen
# GANExplainer: GAN-based Graph Neural Networks Explainer

###### Abstract

With the rapid deployment of graph neural networks (GNNs) based techniques into a wide range of applications such as link prediction, node classification, and graph classification the explainability of GNNs has become an indispensable component for predictive and trustworthy decision-making. Thus, it is critical to explain why graph neural network (GNN) makes particular predictions for them to be believed in many applications. Some GNNs explainers have been proposed recently. However, they lack to generate accurate and real explanations. To mitigate these limitations, we propose GANExplainer, based on Generative Adversarial Network (GAN) architecture. GANExplainer is composed of a generator to create explanations and a discriminator to assist with the Generator development. We investigate the explanation accuracy of our models by comparing the performance of GANExplainer with other state-of-the-art methods. Our empirical results on synthetic datasets indicate that GANExplainer improves explanation accuracy by up to 35% compared to its alternatives.

## 1 Introduction

Graph neural networks (GNNs) [23], with the resurgence of deep learning, have become a powerful tool to model graph datasets and achieved impressive performance. However, a GNN model is typically very complicated and how it makes predictions are unclear; while unboxing the working mechanism of a GNN model is crucial in many practical applications (e.g., criminal associations predicting [20], traffic forecasting [6], and medical diagnosis [2]). Thus, an explainable model is favoured and even necessary, as explanations benefit users in multiple ways, such as improving the model's fairness/security and it also enhances understanding and trust in the model's predictions. As a result, explaining GNNs has achieved considerable research attention in recent years.

Recently, several explainers [25, 5, 26, 14, 12] have been proposed to tackle the problem of explaining GNN models. These attempts can be categorized into _local_ and _global_ explainers according to their interpretation scales. In particular, if the method only provides an explanation for a specific instance, it is a _local explainer_. In contrast, if the method explains the whole model, then it is a
global explainer_. Alternatively, GNN explainers can also be classified as either _transductive_ or _inductive_ explainers based on their capacity to generalize to extra unexplained nodes. GNNExplainer [25] and GraphLIME [5] are challenging to be applied in inductive settings as their explanations are limited to a single instance, and they provide local explanations, which are incapable of capturing the archetypal patterns shared by the same classes or groupings. While PGExplainer [14], Gem [12], and XGNN [26] can provide a global explanation of the model prediction. Specifically, a trained PGExplainer [14] and Gem [12] can be used in inductive scenarios to infer explanations for unexplained instances without retraining the explanation models.

However, XGNN trains a graph generator for explaining a class by outputting class-wise graph patterns. It hardly applies to a specific instance, since the graph patterns may not even exist on the instance. PGExplainer trained a shared generative probabilistic model using the multiple explained instances rather than explicitly dissecting and modelling the class-wise knowledge. Gem trained an auto-encode generative model based on Granger causality. Still, the graph dataset's explanation is inconsistent since it lacks a discriminator to monitor the generation progress.

To address the above limitations, we propose a global inductive explainer, Generative Adversarial Explainers (GANExplainer) using the virtues of Generative Adversarial Network (GAN) [4]. GAN application widely arranged from image generation to 3D object generation, but not used in GNN explaining. We are the first methods to use GAN to generate explanations for GNNs. Inspired by the explanations generated by other explainers, our ultimate goal is to encourage a compact subgraph of the computation graph to have a large causal influence on the outcome of the target GNN. Our setting is general and works for any graph learning tasks, including node classification and graph classification. Our contributions can be summarized as followings:

* We endeavour to apply GAN to a new domain. GAN has been implemented in numerous fields, including computer vision [18], image processing [16], and natural language processing [15]. However, no attempts are made to explain GNNs using GAN. We are the first to use a GAN to shed light on how GNNs process and learn from graph data, thereby enhancing our understanding of their inner workings.
* We present an innovative GNNs Explainer. Inspired by the GAN architecture, we propose a GANExplainer that is supervised by the target GNN and can consistently provide accurate explanations. GANExplainer is composed of both a Generator and a Discriminator. The objective of the Generator is to generate explanations that can be fed into the target GNN to obtain the same predictions. The Discriminator is a graph classifier that category the generating and input graphs into distinct categories.
* We enhance the accuracy of GNNs Explainers. GANExplainer is not only capable of generating global explanations, but can also be utilised in inductive settings. Compared to state-of-the-art inductive GNN explainers, GANExplainer has superior performance.
## 2 Related Work

Generate Adversarial Network.Generative adversarial networks (GANs) [4] are a type of deep learning model that can generate new data samples similar to a training dataset. They consist of two neural networks: a generator and a discriminator. The generator tries to capture the distribution of actual examples and generate new data examples. The discriminator is usually a binary classifier used to discriminate generated examples from actual examples as accurately as possible. The optimization of GANs is a minimax optimization problem. The optimization terminates at a saddle point, forming a minimum for the generator and a maximum for the discriminator. That is, the GAN optimization goal is to reach Nash equilibrium. At that point, the generator can be considered to have accurately captured the distribution of real examples.

GANs provide a way to learn deep representations without extensively annotated training data. They achieve this by deriving backpropagation signals through a competitive process involving a pair of networks. The representations that can be learned by GANs may be used in a variety of applications, including video generation [18], image generation [24], face generation [4], object detection [3], and texture synthesis [9]. However, utilizing GAN in explaining GNNs is still under exploration.

GNNs Explainers.GNNs incorporate both graph structure and feature information, which results in complex non-linear models, rendering explaining its prediction remain a challenging task. Besides, model explanations could bring a lot of benefits to users (e.g., improving safety and promoting fairness). Thus, some popular works have emerged in recent years focusing on the explanation of GNN models by leveraging the properties of graph features and structures. We here briefly review the respective GNNs explainers below.

GNNExplainer[25] is a seminal method in the field of explaining GNN models. It provides local explanations for GNNs by identifying the most relevant features and subgraphs, which are essential in predicting a GNN. PGExplainer[14] introduces explanations for GNNs with the use of a probabilistic graph. It provides model-level explanations for each instance and possesses strong generalizability. CF-GNNExplainer [13] generate counterfactual explanations for the majority of instances for GNN explanations but ignores the correlation between the prediction and the explanation. Thus, Bajaj et al. [1] proposed RCExplainer generating robust counterfactual explanations. And Wang et al. [22] proposed ReFine, which pursues multi-grained explainability by pre-training and fine-tuning.

Also, reinforcement learning is prevalent in explaining GNNs. Such as, Yuan et al. [27] proposed XGNN, which is a model-level explainer that trains a graph generator to generate graph patterns to maximize a specific prediction of the model. Since XGNN focuses on model-level explanations, it may not preserve the local fidelity, which means its explanations may not be a substructure existing in the input graph. Thus, to solve this limitation, Wang et al. [21] proposed RC-Explainer, which generates causal explanations for GNNs by combining the
causal screening process as a Markov Decision Process in reinforcement learning. Further, Shan et al. [17] proposed RG-Explainer, a reinforcement learning enhanced explainer that can be applied in the inductive setting, demonstrating its better generalization ability.

_Gem_[12] is able to provide both local and global explanations, and it is also operated in an inductive setting. Thus, it can explain GNN models without retraining. Notably, it adopts a parameterized graph auto-encoder with Graph Convolutional Network(GCN) [8] layers to generate explanations. Also, Gem applies Granger causality to generate causal explanations. However, Gem is not consistently getting accurate explanations. Thus, we aim to improve it by adding a discriminator in our framework, which can provide high-accuracy explanations in synthetic and real-world datasets.

## 3 Methods

### Problem Formulation

GNN explainer provides a faithful and compact subgraph to illustrate why the GNNs make the prediction, which indicates essential graph structures and features leading to the model outcomes. Alternatively, it is important to note that the explanation subgraph must be a real subgraph of the input graph, meaning it must contain a subset of the vertices and edges of the input graph.

For a graph \(\mathbf{g}=(\mathbf{V},\mathbf{A},\mathbf{X})\) with label \(\mathbf{L}=\{l_{1},l_{2},...,l_{i}\},l\in C=\{c1,c2,...,c_{j}\}\) and \(j\) is the number of categories. Where \(\mathbf{A}\) presents the adjacency matrix, when node \(i\) and node \(j\) are connected, \(A_{ij}=1\), if node \(i\) and node \(j\) are not connected, then \(A_{ij}=0\). We have the prediction \(f(\mathbf{g})=y\) of a GNN model, and the explanation \(E(f(\mathbf{g}),\mathbf{g})=Exp\) from a GNN explainer. We expect putting the explanation from the GNNs explainer \(Exp\) to the target model \(f(\mathbf{g})\) can obtain the

Figure 1: The framework of GANExplainer. We generate ground truth through the Gem distillation process.
same prediction. Shortly, we expect obtaining \(f(\mathbf{g})=y\) and \(f(E(f(\mathbf{g}),\mathbf{g}))=y\). Alternatively, we expect the explanation to be the subgraph of the input graph, that is \(Exp\in\mathbf{g}\).

Thus, to provide an accurate and real explanation, We propose a GANExplainer based on GAN architecture, which thoroughly applies the feature and structure of the graph together. Applying the feature and structure of a graph to the GAN architecture could potentially allow the GANExplainer to more accurately capture the underlying relationships and patterns in the data, which could lead to more accurate explanations.

### GANExplainer

Inspired by the GAN architecture, we propose the GANExplainer, which attempts to generate explanations for GNN under the supervision of the target GNN or ground truth. The framework of GANExplainer is shown in Figure 1.

To keep the explanation generated by GANExplainer as a substructure of the input graph, we assign weights to each edge to determine its relative importance. Suppose the explanation adjacency matrix \(\mathbf{Exp}\) contains elements that are not present in the adjacency matrix \(\mathbf{A}\) of the input graph. In that case, the explanation subgraph is not a real subgraph of the input graph. Our objective is to generate real explanations that only contain truth edges of the input graph. Thus, we use GANExplainer to produce a weight matrix \(\mathbf{W}\) instead of generating a subgraph directly. When we get a weight matrix \(\mathbf{W}\), we multi the weight matrix into adjacency matrix \(\mathbf{A}\), and we get the explanation adjacency matrix \(\mathbf{Exp}\) (\(\mathbf{Exp}=\mathbf{W}*\mathbf{A}\)). \(\mathbf{Exp}\) represents the explanation subgraph. The element at the \(i-th\) row and \(j-th\) column of the explanation adjacency matrix is the weight of the edge between the \(i-th\) and \(j-th\) vertices in the explanation subgraph.

Generator.The purpose of the generator is to create a weighted subgraph. The Generator is composed of an encode and a decoder section. Particularly, for synthetic datasets, the Generator employs a 6-layer encode and a 2-layer decode, while for real-world datasets, it employs a 7-layer encode and a 2-layer decode. The Generator initially produces a weighted graph based on the input graph, the ground truth of the input graph, and the prediction of the target GNN. The product is then introduced into the Discriminator. Then, based on the feedback from the Discriminator, the Generator was modified.

Discriminator.The objective of the Discriminator is to identify whether the graph is real or artificial. The discriminator is a three-layer graph classifier with convolutional layers. In specific, the output of the Discriminator for the input graphs is real labels. In comparison, the discriminator produces fake labels for the graphs generated by the Generator, which information will be fed back into Generator and assist with the Generator development.
### Improved Loss Function

GANs consist of a generator and a discriminator. The generator and the discriminator interact to get a balance like in a minimax game. The objective of the generator \(G\) is to generate data that tricks the discriminator, whereas the objective of the discriminator \(D\) is to differentiate between actual and generated data. Consequently, the loss function of the original GAN is defined as follows:

\[\min_{G}\max_{D}V(D,G)=E_{x\sim p_{\text{data }(x)}}[\log D(x)]\] \[+E_{z\sim p_{z}(z)}[\log(1-D(G(z)))]\]

where the \(x\) is the input graph data, and the \(z\) is the normalized graph adjacency matrix.

Explainers should provide explanations for GNNs by finding both significant subgraphs and essential features that play a crucial role in the prediction of GNN. Therefore, we must use the target GNN as a check to ensure that we generate explanations that can explain the GNN, and that these explanations are not limited to the critical structures of datasets. Consequently, if we only use the original GAN objective function, we will generate another graph/subgraph that cannot explain why the GNN makes the prediction. In order to generate explanations with two virtues fidelity and reality, we have enhanced the generator's objective function. The objective function of the Generator of GANExplainer is defined as follows:

\[\min_{G}\,_{z\sim p_{z(x)}}[\log(1-D(G(z)))+\lambda\frac{1}{N}\sum_{i=1}^{N} {(f(\mathbf{g})-f(G(z)))^{2}}]\]

where the \(f\) means the target GNN; the \(N\) is the node set of \(\mathbf{g}\). In our experiments for synthetic datasets, we set \(\lambda=2\), while for real-world datasets we set \(\lambda=3\).

## 4 Experiments

In this section, we conduct experiments to inspect the performances of our model. We first describe the details of the datasets and implementation we used in 4.1 and 4.2 respectively. After that, we present and analyze the experimental results on synthetic datasets in 4.3 and real-world datasets in 4.4 from two aspects: quantitative evaluation and qualitative evaluation.

### Datasets

We focus on two widely used synthetic node classification datasets, including BA-Shapes and Tree-Cycles [25, 10], and two Real-world graph classification datasets, Mutagenicity [7] and NCI1 [19]. Statistics of these datasets are shown in Table 1.

The BA-Shapes dataset is based on a Barabasi-Albert (BA) graph on 300 nodes and attaches 80 "house"-structured network motifs to randomly selected
nodes of the base graph. Nodes are categorised into four classes depending on their structural roles, which correspond to nodes at the top, middle, and bottom of houses and nodes that do not belong to a house.

The Tree-Cycles dataset starts with a base 8-level balanced binary tree and attaches 80 six-node cycle motifs, which are attached to random nodes of the base graph. Nodes are divided into 2 classes according to nodes belong the tree or the cycle.

Mutagenicity datasets contain 4337 molecule graphs, where nodes represent atoms, and edges denote chemical bonds. The graph classes, including the non-mutagenic or the mutagenic class, indicate their mutagenic effects on the Gram-negative bacterium Salmonella Typhimurium. Carbon rings with chemical groups \(NH_{2}\) or \(NO_{2}\) are known to be mutagenic. Carbon rings, however, exist in both mutagen and nonmutagenic graphs, which are not discriminative.

NCI1 represents a balanced subset of chemical compounds screened for activity against non-small cell lung cancer. This dataset contains more than 4,000 chemical compounds, each of which has a class label between positive and negative. Each chemical compound is represented as an undirected graph where nodes, edges and node labels correspond to atoms, chemical bonds, and atom types respectively.

### Experimental Settings

In our experiments, we replicate the experimental conditions of Gem so that we can fairly compare our results to those of Gem, which are our baseline. In accordance with experimental Gem settings, they select K to select various top edges as explanations. Consequently, we set K to the same value for each dataset as the Gem. Consistent with experimental Gem settings, we divide the data into 80% training data, 10% validation data, and 10% testing data. We maintain the consistency of the testing data. Both training data and validation data are utilised in their entirety during the training process.

Baseline approaches.With the wide application of GNNs, more and more GNN explainers have been proposed to address the problem of explaining GNN models. _GNNExplainer_ is a seminal method in the field of explaining GNN models. In addition, the PGExplainer and Gem are most related to our method. Note

\begin{table}
\begin{tabular}{c c c c c} \hline \hline  & \multicolumn{2}{c}{Node Classification} & \multicolumn{2}{c}{Graph Classification} \\ \cline{2-5}  & BA-Shapes & Tree-Cycles & Mutagenicity & NCI1 \\ \hline \# of Graphs & 1 & 1 & 4,337 & 4110 \\ \# of Edges & 4110 & 1950 & 266,894 & 132,753 \\ \# of Nodes & 700 & 871 & 131,488 & 122,747 \\ \# of Labels & 4 & 2 & 2 & 2 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Datasets information.
that for the synthetic datasets, we know the motif of each dataset. However, for real-world datasets, there are no explicit motifs (no ground truth motifs) for classification. Thus, for real-world datasets, we need to explain all classes. Since PGExplainer assumes NO2 or NH2 as the motifs for the mutagen graphs and trains an MLP for model explanation with the mutagen graphs including at least one of these two motifs. In addition, as the results reported by the Gem, we note that the performance of Gem is better than PGExplainer. Thus, we consider GNNExplainer and Gem as alternative approaches. We set all the hyperparameters of the baselines as reported in the corresponding papers.

Metrics.A better explainer should be able to generate more compact subgraphs yet maintains the prediction accuracy while the associated explanations are fed into the target GNN. After comparing the characteristic of each metric [11, 28], we chose quantitative and qualitative evaluation. To this end, we generate the explanations for the test set based on GNNExplainer, Gem, and GANExplainer, respectively. Then we use the predictions of the target GNN for the explanations to calculate the explanation accuracy. The explanation accuracy can be defined as:

\[ACC_{exp}=\frac{Correct_{f(\mathbf{g})=f(Exp)}}{|Test|}\]

where the \(f\) means the target GNN; \(\mathbf{g}\) presents the graph; \(Exp\) presents the explanation; \(|Test|\) means the total number of test set.

### GANExplainer on Synthetic Datasets

Firstly, we conduct experiments on synthetic datasets, including BA-Shapes and Tree-Cycles. We evaluate the accuracy of explanations provided by GANExplainer (our model), Gem, and GNNExplainer. We also present quantitative and qualitative evaluations of our experiments.

The accuracy of explanations for synthetic datasets with various K settings is detailed in Table 2. The results indicate that GANExplainer consistently provides the most accurate explanations in all cases. On the BA-Shapes dataset, GNNExplainer, Gem, and GANExplainer perform well for synthetic datasets.

\begin{table}
\begin{tabular}{l|c c c c|c c c c} \hline \hline K (edges) & \multicolumn{5}{c|}{BA-Shapes} & \multicolumn{5}{c}{Tree-Cycles} \\  & 5 & 6 & 7 & 8 & 9 & 6 & 7 & 8 & 9 & 10 \\ \hline GNNExplainer & 0.7941 & 0.8824 & 0.9118 & 0.9118 & 0.9118 & 0.2000 & 0.5429 & 0.7143 & 0.8571 & 0.9429 \\ Gem & 0.9412 & 0.9412 & 0.9412 & 0.9412 & 0.9412 & 0.7429 & 0.7429 & 0.7714 & 0.8857 & 0.9143 \\ GANExplainer & 0.7647 & 1.000 & 0.9706 & 0.9853 & 0.9853 & 0.9143 & 1.0000 & 0.9714 & 1.0000 & 1.0000 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Results on Synthetic Datasets.
However, GANExplainer also incorporates a number of enhancements. GANExplainer outperforms GNNExplainer and Gem on BA-Shapes. On the Tree-Cycles dataset, GANExplainer performs well on Tree-Cycles, whereas neither GNNExplainer nor Gem perform well. Specifically, when K=7 on Tree-Cycles, GANExplainer achieves a 35% and 84% improvement over Gem and GNNExplainer, respectively.

Qualitative is an effective way to visualize the explanations. We obtain the difference in explanations between GNNExplainer, Gem and GANExplainer by qualitative analysis. We visualise the explanations of Tree-Cycles when \(K=6\), shown in Figure 2. We note that the explanations of GNNExplainer and Gem can not get the correct prediction when fed into the target GNN. However, we can get the correct prediction similar to the prediction of the target GNN when fed the explanation from our explainer, GANExplainer.

### GANExplainer on Real-world Datasets

We report the results of real-world datasets in the following. The quantitative evaluation is shown in Table 3. As shown in the table, We note that the results reported successfully verify that our proposed GANExplainer can generate explanations that consistently yield high explanation accuracies over all datasets.

To further check the explainability of the generated explanations, we report the qualitative evaluation of the Mutagenicity (graph 3903 and graph 3904, \(K=15\)) in Figure 3.

When the target GNN gets the prediction of the graph, we expect to get the same prediction of explanation. Specifically, for graph 3903, the label is 1, while we get the wrong prediction of the target GNN 0. We want to explain why the target GNN makes the prediction 0. Thus, we visualise the explanations from GNNExplainer, Gem and GANExplainer, respectively. From the figure, we note that the explanations of GNNExplainer and GANExplainer get the same prediction as the original graph, after feeding explanations into the target GNN. However, the explanation of Gem makes a different prediction. Thus, we can conclude that the explanations provided by GNNExplainer and GANExplainer are correct while the explanation of Gem is incorrect. Furthermore, comparing the explanation of GNNExplainer and GANExplainer, we note the explanation of GANExplainer provides a more complete explanation.

\begin{table}
\begin{tabular}{l|c c c|c c c} \hline \hline K (egeeds) & \multicolumn{3}{c|}{Mutagenicity} & \multicolumn{3}{c}{NCI1} \\
15 & 20 & 25 & 30 & 15 & 20 & 25 & 30 \\ \hline GNNExplainer 0.6981 & 0.7188 & 0.7442 & 0.7834 & 0.6909 & 0.7031 & 0.7566 & 0.8004 \\ Gem & 0.6705 & 0.7027 & 0.7741 & 0.7949 & 0.6253 & 0.7055 & 0.7956 & 0.8126 \\ GANExplainer 0.6935 & 0.7442 & 0.7650 & 0.7857 & 0.6642 & 0.7494 & 0.7908 & 0.8273 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Results on Real-world Datasets.
Figure 3: The explanation visualization on Mutagenicity when \(K=15\). Graph 3903 the label is 1, and the graph 3904 the label is 0. In this diagram, the first column is the original graph structure and the predicted label of the target GNN. The second to fourth columns are the explanation of graphs from GNNExplainer, Gem, and GANExplainer, respectively.

Figure 2: The explanation visualization of Node 709, the label is 1, on Tree-Cycles when \(K=6\). In this diagram, the blue nodes mean the prediction label of the target GNN is 1, and the grey nodes mean the predictions of the target GNN for these nodes are 0. The red circle node is the node that needs to explain why the target GNN predicting label is 1. The first subfigure is the original graph structure, and the prediction of the target GNN is 1, which means the target GNN makes the right prediction. The second to fourth subfigures are the explanation of the node 709 from GNNExplainer, Gem, and GANExplainer, respectively.
## 5 Conclusion

In this paper, we propose GANExplainer, an explainer based on GAN, which can create accurate and real explanations for any graph neural network. Specifically, GANExplainer is model-agnostic, does not rely on the linear-independence assumption of the explained features, and does not require knowledge of the internal structure of the target GNN. Furthermore, GANExplainer can be applied in inductive settings to explain the whole GNN model. Our findings are consistent across diverse datasets and graph learning tasks.
