GraphDE: A Generative Framework for Debiased Learning and Out-of-Distribution Detection on Graphs
Abstract
Despite the remarkable success of graph neural networks (GNNs) for graph representation learning, they are generally built on the (unreliable) i.i.d. assumption across training and testing data.
However, real-world graph data are universally comprised of outliers in training set and out-of-distribution (OOD) testing samples from unseen domains, which solicits effective models for i) debiased learning and ii)
OOD detection, towards general trustworthy purpose.
In this paper, we first mathematically formulate the two challenging problems for graph data and take an initiative on tackling them under a unified probabilistic model.
Specifically, we model the graph generative process to characterize the distribution shifts of graph data together with an additionally introduced latent environment variable as an indicator.
We then define a variational distribution, i.e., a recognition model, to infer the environment during training of GNN.
By instantiating the generative models as two-component mixtures, we derive a tractable learning objective and theoretically justify that the model can i) automatically identify and down-weight outliers in the training procedure, and ii) induce an effective OOD detector simultaneously.
Experiments on diverse datasets with different types of OOD data prove that our model consistently outperforms strong baselines for both debiasing and OOD detection tasks.
The source code has been made publicly available at https://github.com/Emiyalzn/GraphDE .
Introduction
For processing ubiquitous graph data, graph neural networks (GNNs) [17, 43] have emerged as effective approaches for graph representation learning [12], which in turn has spanned a wide range of applications, from drug discovery [23] to image classification [4].
Despite their success existing GNNs are generally built on the assumption that both training and testing data are independently sampled from the identical distribution (i.i.d.), which often does not hold [45, 22, 48].
Real-world training data is often shown universally mixed with outliers [30, 7], which specifically may incur large gradient steps in the wrong direction [38], or be overfitted by the model [3], thereby hurting models’ performance.
Besides, testing samples from unseen domains are also unavoidable when the model is deployed in the wild [2, 19], which may easily be classified into a wrong class with a high probability [13].
Inevitably, graph data also involve these two common problems.
As illustrated in Fig.
1, we indeed find that vanilla GNNs perform poorly when encountering large portion of outliers and out-of-distribution (OOD) testing samples, which solicits effective models for i) debiased learning and ii)
OOD detection, towards general trustworthy purpose.
0.2 Biased Ratio
T e s t
A cc u r a cy ( % )
SAGPool
SAGPool GraphDE-a
TopKPool
TopKPool GraphDE-a (a) Debiasing results on SPMotif
OOD Score
F r e qu e n c y F r e qu e n c y
OOD Score
Max SoftmaxScore
Variational Inferred Score
[Figure]
We argue that training outliers and OOD testing samples can be conceptually unified as they both represent data drawn from distributions other than the major in-distribution (ID) part of training data.
However, they are inherently different as the training outliers also catch label-related distribution shifts, e.g. noisy labels [1], while OOD testing samples are solely determined by their features [14] since we cannot access their ground-truth labels.
This difference also explains why many existing works tend to tackle the two problems independently.
In light of the intrinsic connection between these two types of data we present GraphDE, a probabilistic generative framework for Graph DE biased learning and OOD DE tection.
Specifically, we model the generative process to characterize the distribution shifts of graph data, along with an environment variable as an indicator.
Utilizing variational inference [50], we propose to infer the environment variable during the training procedure of GNN.
Our framework consists of three modules: the recognition model that infers the environment variable based on the input graph data; the structure estimation model by which we extract an OOD detector on testing dataset; the classification model which is our target GNN.
Following the idea of data resampling [38, 37], we model the latter two modules by two-component mixtures, with one component for ID data, and the other component robustifying the model by isolating outliers.
Based on this, we derive a tractable learning objective for our model and theoretically justify its effectiveness for the target tasks.
The contributions are:
• We focus on two critical but largely unexplored problems for graph data: debiased learning and OOD detection, find their fundamental correlations and define them under a probabilistic framework.
• We propose GraphDE with a novel learning objective and theoretically justify that: 1) it can identify and down-weight outliers during training; 2) it can provide an OOD detector on the testing set; 3) its constituent modules are optimized in a mutually-promoting manner.
• We evaluate GraphDE with different GNN backbones on diverse datasets of different OOD types, where GraphDE achieves consistent performance improvements over the baselines.
Specifically, as shown in Fig.
1, for the debiasing task, it yields up to 14.6% accuracy improvement on SPMotif; for the OOD detection task, it outperforms the strongest baseline by 9.31% on MNIST-75sp.
Problem Formulation and Related Works
In typical graph learning problems, given a set of labeled graphs D tr = { ( G i , y i ) } N tr i =1 , we need to train a model f θ : G → ˆ y to predict the labels on the testing dataset D te = { G i } N te i =1 .
Specifically, the input graph G =
( A, X ) is composed of an adjacency matrix A
= { a vu | v, u ∈ V } and node features
X = { x v | v ∈ V } , where V is the node set.
Define G as a random variable of the input graph and y as a random variable of the graph label, the data-generating process can then be characterized as p ( G , y | e )
= p ( G | e ) p ( y | G , e ) where we introduce an environment variable e as a potential unknown indicator for data from particular distributions.
The biased data (we use the form interchangeable to outliers) in the training set and out-of-distribution (OOD) data in the testing set can both be treated as data drawn from different distributions to the distribution generating the majority of the training set and testing data of our interests, i.e., the in-distribution (ID) data so-called.
Hence, we can model them by a binary environment variable e , with e = 1 denoting the ID portion and e = 0 for the biased/OOD portion.
Then the training and testing datasets can be split into D tr = D trin ∪ D trout and D te =
D tein ∪ D teout accordingly.
Note that i) the partitions of training/testing data are only for illustration purpose and are strictly unknown in practice; ii) the testing data and distribution are also strictly unknown during the training process; iii) here e is mainly used for distinguishing the ID part with the OOD counterpart of datasets.
In fact, the
OOD part ( e = 0 ) may consist of data from multiple distributions 2 .
Denote the loss on sample ( G, y ) by L ( y, f θ ( G )) , e.g., cross-entropy loss for classification problems.
Then the standard empirical risk minimization (ERM) objective can be written as
[Equation]
This objective works based on the i.i.d.
assumption across training and testing data.
As we aim at promoting the ID test accuracy (i.e. the performance on D tein ), however, the updating gradient by training data drawn from p ( G , y | e = 0) will hurt model performance drastically [3].
On the other hand, for testing data from unseen distributions D teout , the model would incline to produce imprecise results as p tr ( e ) ̸
= p teout ( e ) , which is undesired and should be avoided for the trustworthy purpose.
We next formulate the two problems of our interests.
Task I: Debiased learning for training data.
The target is to mitigate outliers’ negative effects during training, thereby enhancing the performance on ID testing data.
We modify the ERM objective:
[Equation]
where L ( y, f
[Equation] [Equation]
=
[Equation]
where the loss function for biased training data is fixed as L 0 , so the debiasing objective is equivalent to minimize E ( G,y ) ∼ p
( G , y | e =1) [ L ( y, f θ ( G ))] , i.e., the training loss for the ID portion D trin .
Task II: OOD detection for testing data.
We aim to obtain an OOD detector g composed of a trained model f θ : G → ˆ y , a scoring function s and a threshold τ :
[Equation]
As we are willing to induce an OOD detector during the training procedure of GraphDE, we leverage the trained model f θ from task
I and what we need is to find the optimal score function s ∗ that can best separate out ID and OOD data (e.g. maximize the AUROC).
Related works on debiased learning.
A series of strategies have been proposed to debias the training dataset in general machine learning [38, 5] and computer vision [30, 7].
Many works propose to preprocess the dataset by filtering out the outliers [5, 25].
However, these methods cannot capture label-related distribution variations such as noisy labels [1] and also cannot be easily adapted to deal with graph data.
Another popular strategy is data resampling [38, 37], which relies on the training loss to identify and down-weight outliers in the training set.
However, these methods only capture bias in the mapping from features to labels, but ignore the variation in feature space.
For the first time to our best knowledge, we formally define and deal with the graph debiased learning problem.
Related works on OOD detection.
A trustworthy learning system should not only produce accurate predictions for ID data, but also distinguish and reject OOD examples without further prediction.
[Figure]
ID:
OOD:
OOD: inferred e
Generative Models mutually boost
Generative Models infer infer
ID:
OOD:
ID:
OOD: computed = + +
Recognition Model #
(%|',))
# 3 (+|',))
Training Stage
[Figure]
Deep learning based OOD detection has achieved promising progress in vision [27, 13].
Besides, node and edge-level anomaly detection on graphs are also widely studied, some of which are based on classical network science [26], while others utilize the power of GNNs [36, 9].
In comparison, only limited works [51, 29] attempt to solve graph-level OOD detection.
Specifically, OCGIN [51] designs a one-class GNN objective to distinguish between ID and OOD data.
GLocalKD [29] utilizes joint random distillation of graph and node representations to learn rich global and local pattern information of graph-structured data.
However, both of them need to be trained individually for the detection task.
In this paper, we extract an OOD detector during the training procedure of the target
GNN, while outperforming all the baselines on 7 out of 9 benchmarks.
Appendix B gives more comprehensive description on related works on GNNs and Trustworthy GNNs.
Methodology 3.1 Probabilistic Generative Learning for Debiased Learning and OOD Detection
To improve the ID test accuracy, we want to make the model more robust by automatically identifying potential outliers during training.
Thus, we take a generative perspective on the graph data and adopt variational inference to infer the environment variable during training.
Generative Process.
We model the joint distribution p ( X , y , A , e ) to capture graph-level distribution shifts.
In line with the homophily principle from random graph theory [33], i.e., linking probability depends on some inherent properties of nodes, we assume that the graph structure is generated based on the node features and the environment variable.
The graph labels are then generated based on the graph structure, node features, and the environment.
We also assume p ( e ) and p ( X ) to be independent distributions for environments and node features, respectively.
We do not specify the form of p ( X ) , since everything will be conditioned on X in this paper, similar to [28, 44].
We have:
[Equation]
where the generative models p ( A | X , e ) and p ( y | X , A , e ) could be modeled by some flexible parametric distributions p θ ( A | X , e ) and p θ ( y | X , A , e ) with parameter θ .
These two distributions will later be instantiated as the structure estimation model and classification model, respectively.
We define the generative models with two-component mixtures.
For example, p θ ( A | X , e ) is composed of an ID component p θ ( A | X ) , and an OOD component p
( A | X ) (the subscript 0 implies a fixed distribution).
The environment variable e ∈ { 0 , 1 } indicates whether the graph should be modeled by the ID ( e = 1 ) or the OOD ( e = 0 ) component.
Specifically, these two terms are decomposed as:
[Equation]
Recognition Model.
As the variables X , A and y are all observed during training, what we need is to infer the sample-wise environment variable e conditional on these observed variables.
Thus, we resort to variational inference [50] and introduce a recognition model q ϕ ( e | A , X , y ) parameterized with ϕ to approximate the true posterior p θ ( e | A , X , y ) .
Learning Objective.
We train the model parameters θ and ϕ by optimizing the Evidence Lower
BOund (ELBO) of the observed data tuple ( A, X, y ) :
[Equation]
Eq.
6 shows that by maximizing the ELBO, we are maximizing the log-likelihood of observed data log p θ ( A, y | X ) while minimizing the KL divergence between the recognition model and the true posterior p θ ( e | A, X, y ) .
Finally, the learning objective for the training dataset can be written as:
[Equation]
[Table]
[Equation]
Justification of GraphDE.
We provide theoretical analysis here to reveal the rationale of GraphDE.
Without loss of generality, we do not take account into the KL loss here for simplicity.
The proofs of the propositions are postponed to Appendix A.
Proposition 1. 1)
The learning objective for GraphDE is in a re-weighted form when q ϕ ( e | A , X , y ) is instantiated as a Bernoulli distribution, with q ϕ ( e i
= 1 | A
i , X i , y i ) acting as a weight for the i -th sample; 2) Given the ideal recognition model q ∗ ϕ that gives q ∗ ϕ ( e = 1 |
( A, X, y ) ∈ D in ) =
1 and q ∗ ϕ ( e = 1 | ( A,
X, y ) ∈
D out )
= 0 , the generative models can learn to best fit the ID data.
Prop. 1 reveals how the inferred posterior takes effect on the learning objective.
Typically, if q ϕ ( e | A , X , y ) can assign a higher probability to ID data, our model can thereby learn to ignore the negative effects of biased training data and better fit the target distribution (i.e. ID).
Proposition 2. 1)
Assuming the generative models fit to the ID data, i.e. p θ ( A | X ∈ D in ) ≥ p θ ( A | X ∈ D out ) and p θ ( y | ( A, X ) ∈ D in ) ≥ p θ ( y | ( A, X ) ∈
D out ) , the recognition model will learn to predict q ϕ ( e = 1 | ( A, X
, y ) ∈ D in ) ≥ q ϕ
( e = 1 | ( A,
X, y ) ∈
D out ) ; 2) Given optimal generative models that best fit the ID data and perform randomly on outliers, there exists a recognition model q ∗ ϕ which yields the minimal objective while ideally predict the environment variable.
Prop. 2 proves GraphDE’s effectiveness from the recognition model’s perspective.
To summarize, the above two propositions show that q ϕ ( e | A , X , y ) , p θ ( y | A , X ) and p θ ( A | X ) can mutually promote each other during training.
As deep networks tend to learn simple shared (i.e. ID) patterns first [3], this positive feedback can guide GraphDE to identify outliers in early epochs and thereby learn better representations of ID data.
Besides, the propositions also suggest that given either of the recognition model or the generative model optimal, the other can be trained to be optimal, which suggests the existence of the global optimum.
Based on these, we can further understand the implications of the three loss terms in Eq.
7: i)
L cls is the re-weighted version of the original classification loss; ii) L reg acts as graph regularization and will impact the gradient of q ϕ ( e | A , X , y ) , weighting ID data higher than the outliers; iii) the third term L kl is the KL divergence between the learned posterior and the fixed prior distribution, ensuring the posterior not go too complex.
Inference on Testing Dataset.
For new data, we need to infer the posterior conditional distribution of e and y given ( A , X ) , i.e. p θ ( e | A , X ) and p θ ( y | A , X ) , respectively.
To compute p θ ( e | A , X ) is just to do OOD detection .
For binary e , we can compute its posterior analytically:
[Equation]
The posterior can be used as the score function s for the OOD detector, once we have the well-trained p θ ( A | X , e ) .
Subsequently, we can calculate p θ ( y | A , X ) by the total probability theorem:
[Equation]
where p θ ( y | A , X , e ) can also be obtained after training.
3.2 GraphDE Instantiations
We proceed to specify the distributions p θ ( A | X , e ) , p θ ( y | X , A , e ) , p ( e ) and q ϕ ( e | A , X , y ) .
We assume p ( e ) =
Bernoulli ( α ) where α ∈ [0 , 1] represents our prior belief about the cleanliness of the dataset.
A higher α implies a larger portion of ID data in D tr .
It is fixed as a scalar during training.
3.2.1 Instantiations of the Recognition Model
We propose two variants for the recognition model q ϕ ( e | A , X , y ) .
In the first way, we directly assign a learnable scalar for each sample in the training dataset, i.e., q ϕ ( e i
|
A i , X i , y i ) =
Bernoulli ( α i ) , where α i ∈ [0 , 1] is a trainable parameter jointly optimized with generative models through the ELBO in Eq.
We call this variant GraphDE-v(ariational) as we optimize directly over α i .
In the second way, notice that e is a binary variable by definition, we can compute the posterior analytically by
[Equation]
We call this variant GraphDE-a(nalytical) and the optimization procedure in this setting is essentially an EM algorithm [31]: in the E-step, we evaluate the posterior distribution of the latent variable e by Eq.
10; in the M-step, we optimize the model parameters θ using gradient descent w.r.t.
the objective in Eq.
In comparison, GraphDE-v runs more efficiently as it does not need to calculate the posterior, while GraphDE-a can give a tight approximation log p θ ( A, y | X )
=
L ELBO .
We compare the space/time complexity of the algorithms in Appendix F.3.
3.2.2 Instantiations of the Structure Estimation Model
Recall that p θ ( A | X , e ) is defined by a two-component mixture (Eq. 5), we need to specify p θ ( A | X ) and p
( A | X ) separately for the structure estimation model.
We follow the common practice and assume that the edges are conditionally independent [28].
Then the conditional probability of A can be further factorized as p θ ( A | X )
= (cid:81) v,u ∈ V p
θ ( a vu | X ) .
We next consider two versions for p θ ( a vu | X ) .
First, we adopt the latent space models (LSM) [15] where the probability of a vu only depends on the representations of nodes v and u :
[Equation]
Eq.
11 can be viewed as a logistic regression model where σ ( · ) denotes the Sigmoid function, U is a linear transformation matrix, and w is a learnable vector.
Second, we propose a variant of LSM referred as CosLSM which utilizes the cosine similarity function to measure the similarity between the node representation pair ( x v , x u ) :
[Equation]
where we harness multi-head [42] linear transformations { U i } mi =1 for better capacity.
Note that if we train the structure estimation model completely based on the observed edges, the model will yield trivial solutions which predict all edges’ probabilities as 1.
To avoid this issue, we randomly sample one disconnected node pair labeled as a vu = 0 for each existing edge during training.
Finally, for p 0 ( a | X ) , we simply fix it as p 0 ( a vu = 1 | X ) = 1 / 2 .
Although more complex distributions can be used for improving the capacity, our experiment results empirically show that this simple distribution is enough for a wide range of debiasing and detection tasks on graphs.
3.2.3 Instantiations of the Classification Model
We next specify p θ ( y | A , X ) and p 0 ( y | A , X ) for the classification model.
Similar to the structure estimation model, we fix p
( y | A , X ) =
K − 1 where K denotes the total number of classes.
Typically, a GNN takes ( A , X ) as input and outputs the probability of y .
So for p θ ( y | A , X ) , we adopt two types of GNN models: the global pooling models [17, 43] and hierarchical pooling models [21, 18].
Denote node v ’s neighborhoods by N v , specifically, common GNN convolutional layers execute recursive feature propagation along G :
[Equation]
[Equation]
) where W ( l ) denotes weight matrix in the l -th layer and AGG ( l ) is a permutation-invariant function that aggregates node representations.
In hierarchical pooling GNNs, each convolutional layer is followed by a pooling layer to filter out nodes for the next convolution operation:
[Equation]
(14) where idx is the selected node indices obtained by operations such as selecting the top- k score (calculated by a learnable function) nodes.
Finally, for both types of GNNs, a global pooling layer (e.g. max or mean operation over node features) is adopted to extract a graph-level representation h to be fed into the classifier Φ whose probability is obtained by an output softmax layer:
[Equation]
where n denotes the total number of convolutional layers.
Experiments
In this section, we conduct extensive experiments to answer the following questions:
• Q1:
How effective is GraphDE in debiased learning and OOD detection?
• Q2:
How do the composed modules and hyperparameters impact GraphDE’s performance?
Besides, how does GraphDE take effect during the training procedure?
4.1 Experiment Setup
Datasets.
One synthetic and three real-world datasets of different OOD types are used for debiasing and OOD detection tasks.
Here we briefly introduce them, leaving details of statistics to Appendix E.
• Spurious-Motif [49] (SPMotif) is a synthetic dataset in which each graph is composed of one base (denoted by S ) and one motif (denoted by C ).
The graph label y is solely determined by the motif C .
To simulate distribution shifts, we manually construct spurious correlations between S and y .
We use datasets with different spurious correlations to represent ID and OOD data, respectively.
This dataset is unsuitable for typical OOD detection task, as the distribution shift is dominated by label information, opposed to that the OOD detectors focus on detecting input graphs with abnormal structures or node features.
• MNIST-75sp [18] converts the MNIST images into super-pixel graphs with at most 75 nodes.
For OOD data, we add Gaussian noise to node features to simulate distribution shift.
• Collab [47] is a social network derived from 3 public collaboration datasets.
We use the graph size to simulate distribution shift, with graphs of no more than 45 nodes denoted as ID data.
• DrugOOD [16] aims to benchmark the OOD generalization performance in the field of AI-aided drug discovery.
We use the provided dataset curator to generate a dataset with different scaffolds , and treat the largest 6000 molecules as ID data.
[Figure]
[Table]
Note that during the debiased training stage of GraphDE
[Table]
we need to mixed a certain number of OOD data into the training dataset.
To prevent potential data leakage [14] during the evaluation of OOD detection, the OOD testing dataset should be drawn from a different distribution
w.r.t.
the OOD data mixed into the training dataset.
We denote these two sources of OOD data as the OOD testing dataset and the OOD mixed dataset, respectively.
We leave more details of dataset splits to Appendix E. GNN backbones.
We adopt two types of GNN backbones for debiasing and OOD detection tasks.
• Global pooling backbones.
We adopt two popular GNNs: GCN [17] and GAT [43].
To extract the global graph representation for graph classification, we use a global mean pooling or global max pooling layer after the GNNs to summarize the node representations.
• Hierarchical pooling backbones.
This architecture is comprised of blocks each of which consists of a graph convolutional layer and a pooling layer.
Typically, TopKPool [18] selects local parts of input graph for propagation by a learnable score function; SAGPool [21] uses the self-attention mechanism to calculate attention scores, and retain important nodes for propagation.
Debiasing settings.
For the debiasing task, we mix the training set with certain ratio of outliers and compare models’ performance on ID testing data.
We evaluate GraphDE’s debiasing performance on the four datasets.
Besides, As far as we know, there are little existing works concerning debiased learning on graph data.
For demonstrating the empirical superiority of our approach, we adopt two recently proposed methods that claim to enhance the general-purpose robustness of GNNs as competitors: 3 : DropEdge [39] randomly removes a number of edges from the input graph in each training epoch, and GRAND [11] uses a random propagation strategy to perform graph augmentation.
We study the negative effect of outliers by varying the biased ratio ( |D trout | / |D tr | ) of training data.
OOD detection settings.
We evaluate GraphDE’s OOD detection performance on three real-world datasets (with equal number of ID and OOD testing samples), using three widely used metrics [14]: area under the receiver operating characteristic curve ( AUROC ), area under the precision-recall curve ( AUPR ), and the false positive rate at 95% true positive rate ( FPR95 ).
Besides, we consider three types of baselines: first, we use the backbones’ max softmax score (MSP) [13] as a vanilla baseline; second, we adopt two-stage graph kernel baselines in [51] (specifically, we adopt WL [40] and PK [34] kernels, LOF [5] and OCSVM [6] detectors); finally, we use OCGIN [51] and GLocalKD [29] as two deep learning based detection baselines.
[Table]
4.2 Main Results (Q1)
We train and evaluate each model under the settings as described in the last section (more hyperparameter and training/testing details in Appendix D).
All the experiments are run over 5 different random seeds.
More experimental results can be found in Appendix F.
We make the following observations:
Debiasing results.
Tab. 1 reports GraphDE’s debiasing performance on SPMotif.
In this setting, we treat the robust GNN baselines and two variants of our GraphDE as plug-in modules and apply them to all the four backbones for comparison.
The results show that GraphDE consistently (for all the backbones) outperforms the baselines by a large margin along with low variance.
Specifically, for the TopKPool backbone, GraphDE-a surpasses the backbone by 10.11% and the strongest baseline (GRAND) by 5.29%.
Such improvements strongly suggest that GraphDE can achieve better debiasing performance for various backbones.
Besides, the results also show that the GraphDE-a generally outperforms GraphDE-v, as the EM algorithm can give a tight approximation for the log-likelihood.
Fig.
3 illustrates GraphDE’s performance on three real-world datasets.
In this setting, we mainly study the debiasing performance w.r.t.
different biased ratios, so the backbone for robust GNN baselines and
GraphDE are all fixed as GAT.
As shown in the figure, GraphDE consistently outperforms baselines on the three datasets for all the biased ratios.
The backbones’ performance drops drastically as the biased ratio gets higher, and the robust GNN baselines can mitigate this effect to some extend.
In comparison, GraphDE performs much more stable.
This advantage is more pronounced when the biased ratio is large, e.g. GraphDE surpasses all the other baselines by nearly 5% on Collab when the biased ratio is 0.2.
An interesting observation is that GraphDE can also achieve a better test accuracy when the biased ratio is 0, implying that the pure training set also violates the i.i.d.
assumption.
Detection results.
Tab. 2 reports GraphDE’s detection performance on three real-world datasets.
As can be seen from the table, the max softmax score (MSP) achieves low detection performance.
It suggests that vanilla GNNs are poorly calibrated [35] and it is of critical need to develop new graphlevel OOD detectors.
The results show that GraphDE performs the best on 7 out of 9 benchmarks.
Specifically, on MNIST-75sp, GraphDE surpasses the strongest baseline by approximately 10% for
AUROC, while also pulls down the false positive rate (FPR95).
4.3 Further Study (Q2)
Impact of prior ratio.
We select different prior ratios 1 − p ( e ) to study its impact on debiasing performance.
As shown in the Fig. 4(a), the ID test accuracy doesn’t fluctuate much from 0.05 to 0.7, but drops drastically when prior ratio goes higher than 0.7.
Besides, we also find that the test accuracy peaks at prior ratio 0.1 for biased ratio 0.1, and 0.2 for biased ratio 0.2, exactly when L kl becomes 0.
Ablation on L reg .
We remove L reg in the objective to study the structure estimation model’s impact on debiasing performance.
As illustrated in Fig. 4(b), we can find that the test accuracy drops obviously at all biased ratios.
Specifically, The test accuracy drops over 6% at biased ratio 0.25.
The results prove the structure estimation model’s capability of down-weighting outliers in training data.
Ablation on L cls .
We remove L cls to study the influence of the classification model on the OOD detection performance.
As shown in Fig. 4(c), we plot the detection AUROC on the testing dataset w.r.t.
different biased ratios.
The figure illustrates that the AUROC generally drops as the biased ratio gets higher, since the outliers will hurt the fitting performance of the structure estimation model.
Typically, we can see that the blue line (without L cls ) is consistently lower than the red line, with the
[Figure] [Figure]
gap getting larger as the biased ratio goes higher.
Specifically, the performance gap is approximately 3% when biased ratio is 0.3.
The results prove that the classification model can help down-weight training outliers, thereby promoting the detection performance of the structure estimation model.
Training procedure.
We plot GraphDE’s test accuracy after every training epoch on ID and OOD (i.i.d. to training outliers) datasets.
As shown in Fig.
5(a), the ID test accuracy simply fluctuates, rises, and converges.
In comparison, the trend of OOD test accuracy can be divided into two phases.
As separated by the green dashed line, we can see the red line first increases then decreases.
Generally, in the increasing phase, GraphDE is optimized to better fit the outliers in the training data.
However, in the decreasing phase, as the outliers are down-weighted by a large extend, GraphDE focuses on fitting ID data.
This transition prevents overfitting of outliers and promotes the ID test accuracy.
Visualization of inferred probability.
We visualize the recognition model’s inferred probability q ϕ ( e = 1 |
A, X, y ) on the training dataset.
As shown in Fig.
5(b), ID data is assigned with a higher probability on both datasets.
In particular, most outliers are assigned with probability at around 0 on
SPMotif.
This directly indicates that the outliers are down-weighted during the training procedure.
Conclusion and Outlook
In this paper, we have provided a viable approach to the problem of debiased learning and OOD detection over graph data.
Specifically, a generative process is modeled to capture distribution shifts of graph data.
By introducing a variational recognition model to infer the environment variable and two-component mixed generative models, the learning objective for GraphDE is derived, which can identify and down-weight outliers during training, as well as inducing an effective OOD detector on new data.
While our framework is mainly designed for graph data where both the debiased learning and OOD detection remain relatively under-explored, it can be potentially generalized to other data formats like images or texts, which we leave for future studies.
Acknowledgement
This work was partly supported by National Key Research and Development Program of China (2020AAA0107600), National Natural Science Foundation of China (61972250, 72061127003), and
Shanghai Municipal Science and Technology (Major) Project (2021SHZDZX0102, 22511105100).
Checklist
For all authors... (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope?
[Yes] (b) Did you describe the limitations of your work?
[Yes] See Appendix G. (c) Did you discuss any potential negative societal impacts of your work?
[Yes] See Appendix G. (d) Have you read the ethics review guidelines and ensured that your paper conforms to them?
[Yes] 2.
If you are including theoretical results... (a) Did you state the full set of assumptions of all theoretical results?
[Yes] (b) Did you include complete proofs of all theoretical results?
[Yes] See Appendix A. 3.
If you ran experiments... (a) Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)?
[Yes] See Appendix E for dataset information.
See the supplementary for the codes.
They will be released public upon publication.
(b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)?
[Yes] See Appendix D and Appendix E. (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)?
[Yes] See experiment section.
(d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)?
[Yes] See Appendix D. 4.
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets... (a) If your work uses existing assets, did you cite the creators?
[Yes] See Appendix E. (b) Did you mention the license of the assets?
[N/A] (c) Did you include any new assets either in the supplemental material or as a URL?
[N/A] (d) Did you discuss whether
and how consent was obtained from people whose data you’re using/curating?
[N/A] (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content?
[N/A] 5.
If you used crowdsourcing or conducted research with human subjects... (a) Did you include the full text of instructions given to participants and screenshots, if applicable?
[N/A] (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable?
[N/A] (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation?
[N/A]
A Proof for Technical Results A.1 Derivation of the Learning Objective
Since Eq.
7 is just the unfolding form of Eq.
[Equation]
we will give the derivation of Eq.
6 in this section.
Consider the KL divergence between q ϕ ( e | A, X, y ) and p θ ( e | A, X, y ) :
[Equation]
KL
[Equation]
A, X, y
[Equation]
|
[Equation]
Simply move the terms and we can yield:
[Equation]
which is consistent with Eq. 6.
A.2 Proof for Proposition
We prove the two sub-propositions separately.
Proof for 1).
For one Bernoulli distribution p ( x ) =
Bernoulli ( x | α )
[Equation]
we have E p ( x ) [ x ] = α .
Thus, when q ϕ ( e | A , X , y ) is instantiated as a Bernoulli distribution, we have:
[Equation]
We can tell that L cls is just in the re-weighted form, with q ϕ ( e i =
| A
i , X i , y i ) acting as a weight for the i -th sample.
The deduction is also suitable for L reg .
Proof for 2).
Suppose we know the ground truth environments e i for each training sample, as we are given the ideal recognition model, Eq.
18 can be further written as:
[Equation]
For the optimization objective, we can ignore the second term as p 0 ( y | X , A ) is a fixed distribution, thus we have:
[Equation]
where G i =
( A i , X i ) .
As we can see, optimizing over Eq.
20 is just to minimize the empirical loss E ( G,y )
∼ p ( G , y | e =1)
[ L ( y, f θ ( G ))] , which is consistent with the debiased learning objective in Eq.
As the objective gives full weight to ID data while isolating the outliers (which bring wrong gradients), the classification model can learn to best fit the ID data.
The proof for the structure estimation model is just the same.
A.3 Proof for Proposition
We prove the two sub-propositions separately.
Proof for 1).
Using L cls as an example, following Eq.
18, we can calculate its gradient on the i -th sample:
[Equation]
We optimize on ϕ to minimize L cls , i.e. maximize −L cls .
As we have assumed that the classification model p θ ( y | A , X ) will assign higher loss to outliers, we have:
[Equation]
, where e i = 1 , e
[Equation]
=
[Equation] [Equation]
so we can yield that:
[Equation]
To maximize −L cls , in this sense, the recognition model will generally learn to assign higher weight for ID data ( e i = 1 ) than the outliers ( e j = 0 ).
The proof for the structure estimation model is just the same.
Proof for 2).
Suppose we are given the optimal generative models p ∗ θ ( y | A , X ) and p ∗ θ ( A | X ) that best fit ID data while performing randomly on the outliers, using p ∗ θ ( y | A , X ) as an example, we have:
[Equation]
where K is the number of target classes.
As we have instantiated in Sec. 3.2 that p 0 ( y | A , X ) =
K − 1 , we have:
[Equation]
so the recognition model can assign probability 0 to all outliers as they don’t impact the return loss.
In comparison, for the ID data, we have:
[Equation]
the inequality is induced based on that the ideal classification model must predict better than random.
Thus, the objective is minimized when the recognition model predicts with probability 1 for all ID data.
In conclusion, there exists a recognition model that achieves the minimal objective while ideally predict the environment variable.
B More Related Works
Graph neural networks.
GNNs [17, 43] are increasingly attracting attention in recent years because of their notable success in graph representation learning [12].
They generally utilize a messagepassing paradigm, which combines node features and graph structure to update node embeddings.
A series of GNNs have been proposed to achieve state-of-the-art performance on various graph tasks, including node classification [17], link prediction [24], and graph classification [10].
Despite their great success, recent evidence shows that common GNNs exhibit limited power when training data is insufficient with missing edges and labels [20].
And, existing works usually pose the i.i.d.
assumption across training and testing data, which does not necessarily hold in practice [45].
GNNs’ performance may degenerate by a large extend when the training dataset is mixed with outliers drawn from other distributions [3].
Besides, incorrect predictions can also be made because of distribution shifts on testing dataset.
Thus, it’s critical to develop methods to boost GNNs’ robustness to outliers as well as detect OOD samples on testing dataset.
Trustworthy and Robust GNNs.
With widespread utilization of GNNs, their trustwothiness has raised public concern these days.
Previous works have shown that GNNs are vulnerable to simple perturbations [52, 41] on graph structures and node attributes.
Therefore, a series of works are proposed to promote GNNs’ robustness to adversarial attacks through methods like data augmentation [11] and structure learning [8].
Besides, the OOD generalization capability of GNNs, either at node-level [45] or graph-level [22, 48], are increasingly drawing attention recently.
We emphasize that our work is orthogonal to them for that: first, we are not focusing on the adversarial robustness, but robustness to outliers, which are drawn from other distributions and should be filtered out during training; second, we are trying to detect and reject OOD samples rather than promote GNNs’ generalization capability.
C GraphDE Training Procedure
Using GraphDE-a as an example, its training procedure is summarized in Alg. 1. Algorithm 1: The training procedure of GraphDE-a. and optimize parameters θ ;# M-step. Output: Trained parameters θ .
D Implementation Details
We present our implementation details here for reproducibility.
Our model and all the baselines are implemented with Python 3.8, PyTorch 1.10.0 and PyTorch Geometric 2.1.0.
All experiments are run on a Tesla V100.
We choose GCN [17], GAT [43], TopKPool [18] and SAGPool [21] as our backbone models, whose implementations are provided by the original papers.
For robust GNN baselines DropEdge [39] and
GRAND [11], and the deep learning based OOD detection baselines OCGIN [51] and GLocalKD [29], we also refer to their official implementations.
Specifically, we use GAT as the backbone for our model and baselines, except on SPMotif, which we have tried all the backbones.
D.1 Details for Debiasing Experiments
Classification model architectures.
For debiased learning experiments, the baseline models GCN,
GAT, TopKPool, SAGPool are implemented in the following manner:
• For GCN and GAT, we use two GNN layers with hidden size 64 by default.
TopKPool and SAGPool are comprised of two blocks, each of which consists of one GIN layer and one pooling layer.
• For DrugOOD and MNIST, we use the global mean pool to extract the graph-level representation, while on Collab and SPMotif, the global max pool is adopted.
• We use two MLP layers with hidden size 64 after the global pooling layer for graph classification.
• The activation function is ReLU.
Structure estimation model architectures.
• For SPMotif and Collab, we use LSM as the structure estimation model.
The transformation matrix U ’s output size is 64.
• For MNIST-75sp and DrugOOD, we utilize CosLSM as the structure estimation model.
The transformation matrix U
i ’s output size is 64.
We use 4 heads by default.
• The activation function is ReLU.
Training Details.
We use mini-batch gradient descent to optimize our model and the baselines.
More concretely, we use the cross entropy loss (or negative log likelihood) and the Adam optimizer is adopted for optimization.
The total training epoch number is fixed at 400.
We use early stopping of 20 epochs.
Testing Details.
We report the ID test accuracy achieved by the epoch that gives the highest accuracy on validation dataset.
Hyperparameters.
We adopt grid search to tune the hyperparameters.
The learning rate is searched within { 0 . 1 , 0 . 01 , 0 . 001 , 0 . 0001 } , dropout is searched within { 0 . 0 , 0 . 1 , 0 . 5 } .
Specifically, the hyperparameters are set as follows.
• For GCN and GAT, the learning rate is 0.01 and the batch size is 64.
No dropout is used.
For dataset MNIST and DrugOOD, batchnorm is used.
• For SAGPool and TopKPool, the min score is set to 0.001, i.e. nodes with scores higher than 0.
will be selected for propagation.
• The dropedge rate is chosen within { 0 . 1 , 0 . 2 , 0 . 3 , 0 . 4 , 0 . 5 } .
• For GRAND, the propagation order is chosen within { 1 , 2 , 3 , 4 , 5 } , while the dropnode rate is chosen within { 0 . 05 , 0 . 1 , 0 . 3 , 0 . 5 } .
• For our model, the hyperparameters are set as default.
D.2 Details for Detection Experiments
Architectures.
For detection experiments, our model GraphDE is implemented in the same manner as in the debiasing setting.
Training Details.
For MSP and our model GraphDE, the OOD detector is extracted from the trained model, i.e. the training paradigm is the same as in the debiasing setting.
The two-stage graph kernel baselines don’t require training.
For OCGIN, we adopt its modified one-class objective and train for 100 epochs with Adam optimizer.
For GLocalKD, we adopt the same setting as in the original paper [29] and train for 50 epochs with Adam optimizer.
Testing Details We feed equal amounts of ID and OOD data into the trained model and calculate the three metrics: AUROC, AUPR, and FPR95 to evaluate the OOD detection performance of our model.
Area under the receiver operating characteristic curve(AUROC) can be considered as the probability that an outlier is assigned a higher OOD score than an ID sample, so a higher AUROC score is better.
Area under the precision-recall curve(AUPR) is a useful performance metric for imbalanced data, which takes into account the base rate of outliers.
FPR95 is the false positive rate of
OOD examples when the true positive rate for ID examples is 95%, which represents performance at one strict threshold.
Hyperparameters.
The biased ratio is set as 30% for fair comparison.
For the two-stage graph kernel baselines, the kernel is chosen within {PK [34], WL [40]}, while the detector is chosen within {OCSVM [6], LOF [5]}.
• For OCGIN, we adopt 3 GIN [46] layers with hidden size 64.
The learning rate is set as 0.001.
We do not use weight decay or dropout.
Batch normalization is turned on or off manually for better detection performance.
• For GLocalKD, we adopt 2 GraphConv [32] layers with hidden size 512 and output size 256.
The learning rate is set as 0.0001.
We adopt batch normalization and the dropout is set as 0.3 during training.
We do not use weight decay.
• For graph kernels, the WL iteration number is set as 5, the bin width of PK is set as 0.1.
• For LOF, the leaf number and the number of neighbors is set as 30 and 20.
• For our model, the hyperparameters are set as default.
[Table]
E Dataset Information
We present detailed information for our used datasets concerning the data collection, preprocessing, and statistic information.
An overview of the datasets is represented in Tab. 3.
E.1 Dataset Information
Synthetic dataset.
SPMotif is a synthetic dataset in which each graph is composed of one base (denoted by S = 0 , 1 , 2 ) and one motif (denoted by C = 0 , 1 , 2 ).
The graph label y is solely determined by the motif C .
We manually construct spurious correlations between the base S and label y to simulate distribution shifts.
Concretely, we sample each motif from a uniform distribution, while the distribution of its base is determined by:
[Equation]
We change the mapping relationship to create different spurious correlations to simulate distribution shift, namely, the distribution of S in OOD testing dataset is:
[Equation]
To avoid data leakage as discussed in the main text, the distribution of S in OOD mixed dataset is:
[Equation]
which is different to both ID and OOD testing datasets.
The ratio b is set as 0.9 for ID, OOD testing, and OOD mixed datasets.
We employ 9000 training graphs, 9000 OOD mixed graphs, 3000 validation graphs, and 6000 ID and OOD testing graphs.
For debiased learning which only needs OOD mixed dataset, we directly use Eq.
28 to generate outliers instead.
Real-world datasets.
We adopt three real-world datasets MNIST-75sp, Collab and DrugOOD to evaluate our model.
• MNIST-75sp is converted from the original dataset MNIST, each image of which depicts a handwritten digit from 0 to 9.
The converted super-pixel graphs have at most 75 nodes, with node features set as super-pixel coordinates and intensity, while edges are the spatial distance between the nodes.
We add Gaussian noise N (0 , 0 . 3) to node features for outliers in the training dataset, while using Gaussian noise N (0 , 0 . 6) to simulate distribution shifts in the OOD testing dataset.
The number of graphs used in the training and validation datasets are 3000 and 1000, and we use 2000 ID and OOD testing datasets.
For debiased learning which only needs OOD mixed dataset, we add Gaussian noise N (0 , 0 . 45) to node features.
• Collab is a scientific-collaboration dataset consisting of 5000 researchers’ ego network.
Each node represents a researcher, and the edge represents the collaboration.
We use the graph size to simulate distribution shift, with graphs of [45, 80] nodes denoted as ID, graphs of (80, 100] nodes treated as OOD mixed data, while those of more than 100 nodes treated as OOD testing data.
Specifically, We use 1000 samples for training, 300 samples for validation, 501 samples for training outliers, and 500 samples to formulate ID and OOD testing dataset.
For debiased learning, in order to create larger distribution shifts, we treat graphs with less than 45 nodes as ID data, and those with more than 90 nodes as OOD mixed data (i.e. training outliers
• DrugOOD is a systematic OOD dataset curator and benchmark for drug discovery, providing large-scale, realistic, and diverse datasets for graph OOD learning problems.
The OOD property lies in the scaffold difference.
Specifically, we utilize the provided built-in configuration file, namely, lbap_general_ic50_scaffold.py to generate the dataset.
As described in their paper [16], DurgOOD generates domain descriptor (the molecular size is applied to the domain of scaffold) for each domain, and then sort the domains with descriptors.
Then the sorted domains are sequentially divided into training set, OOD validation and testing set (with a proportion of 6:2:2).
We use these three sets to construct our experimental datasets since they have different data distributions.
Specifically, we randomly select 1000, 300, 500 graphs from the original training set to formulate the ID training, validation and testing datasets.
Our OOD mixed dataset is consisted of 1000 graphs from the original OOD validation dataset.
Finally, 500 graphs are drawn from the original OOD testing dataset to compose our OOD testing dataset.
For debiased learning, we treat the original training dataset as ID data, and the original testing dataset as training outliers, to create larger distribution shifts.
E.2 Dataset Preprocessing
All the datasets we use in the experiment are directly collected from the source except DrugOOD, which is generated by ourselves with the help of the provided dataset curator.
Besides, the node features of SPMotif are set as 4-dimensional uniform random features.
As Collab is originally comprised of plain graphs without node features, we use one-hot node degrees as features for them.
F More Experiment Results F.1 Detection Results
[Table]
WL+OCSVM 50.
WL+LOF 50.
PK+OCSVM 47.
PK+LOF 51.
OCGIN 47.98 ± 4.
47.49 ± 0.
88.20 ± 3.
GLocalKD 52.40 ± 0.
51.54 ± 0.
90.60 ± 0.
ours 52.56 ± 0.
51.69 ± 0.
91.33 ± 0.
[Figure]
Prior Ratio
[Figure]
A
UR
O C
[Figure]
Biased Ratio
[Figure]
UR
O C
[Figure]
[Table]
Tab. 4 reports GraphDE’s detection performance on the synthetic dataset SPMotif.
As is presented in the table, all the models, including the max softmax score(MSP), two-stage kernel methods, OCGIN,
GLocalKD
[Table]
and GraphDE, have a poor performance.
Despite the fact that GraphDE performs the best on 2 out of 3 benchmarks, it only provides a slight improvement, which is due to the properties of the dataset.
More concretely, this dataset is unsuitable for OOD detection since the distribution shift is dominated by the label information, opposed to that the OOD detectors focus on detecting input graphs with abnormal structures or node features.
Fig.6 demonstrates the detection performance of GraphDE-a. As is shown in the figure, the ID data is assigned with a higher score on Collab and DrugOOD, while OOD data tends to get a relatively low score.
However, the OOD score distributions of ID and OOD data are almost the same on SPMotif, which is consistent with the results in Tab. 4.
F.2 Further Study
We supplement extra experimental results on DrugOOD to support GraphDE’s effectiveness.
Impact of prior ratio.
Like that in Sec.
4.3, we tune and study the impact of prior ratio p ( e ) in the
KL loss L kl .
As can be seen from Fig 7(a) , the debiasing performance doesn’t fluctuate much from 0.05 to 0.8, while it drops dramatically when the prior ratio goes higher than 0.8.
In addition, the test
AUROC peaks at 0.1 for biased ratio 0.1, and 0.2 for biased ratio 0.2, exactly when L kl becomes 0, proving the validity of the KL loss.
Ablation study.
To study the effect of the structure regularization loss L reg , we remove L reg in the objective and plot Fig 7(b).
The figure clearly shows the sharp decline in all biased ratios.
Especially, the test AUROC undergoes a descent by nearly 5% when the biased ratio is 15%.
All of these verify the feasibility of the structure estimation model to help discriminate and down-weight outliers in the training procedure.
F.3 Algorithm Complexity
We provide additional empirical results of space/time usage as shown in Table 5 in this section to gain deeper insights into GraphDE.
Generally, we can conclude that the memory usage of GraphDE on both datasets is reasonable, as they can be accommodated by most of GPUs today.
Besides, the table shows that major additional memory footprint of GraphDE comes from the structure estimation model, such that the memory overhead is much more obvious on DrugOOD (consists of graphs with larger number of nodes and edges) than that on SPMotif.
As for the time complexity, using results on DrugOOD as an example, the models usually converge and early stop at around 150 epochs.
So it takes at around 5 minutes to train our GraphDE model on DrugOOD, which can achieve a 5% test accuracy improvement over the backbone.
Relatively, we believe this is a valuable time-accuracy trade-off.
Besides, we find that GraphDE-v is obviously faster than GraphDE-a, this is because it utilizes simple learnable scalars during training and does not need to calculate the posterior analytically.
So GraphDE-v can be a good choice if we need to train a
GraphDE model in limited time.
In comparison to other two plug-in modules, we find that GraphDE is much faster than GRAND on DrugOOD, while on par with it on SPMotif.
Besides, it is slower than DropEdge but with much better testing performance.
G Limitations and Potential Negative Impacts
Currently, our framework cannot readily incorporate vectorized data like images or texts.
Besides, more complex model instantiations may be developed to achieve better debiasing and OOD detection performance on graph data, which we leave for future work.
As we focus on developing trustworthy GNNs, we believe that the negative impacts of our work are small compared to its contributions.
However, it can still raise problems like data fairness due to its re-sampling strategy to conduct debiasing.
Besides, its robustness as an OOD detector should be studied in-depth as future work, since malicious attackers may fool GraphDE to treat OOD data as
ID data, leading to potential performance degradation in practice.