Zero-shot Generalist Graph Anomaly Detection with Unified Neighborhood Prompts

## Abstract

Abstract Graph anomaly detection (GAD), which aims to identify nodes in a graph that significantly deviate from normal patterns, plays a crucial role in broad application domains. Existing GAD methods, whether supervised or unsupervised, are one-model-for-one-dataset approaches, i.e. , training a separate model for each graph dataset. This limits their applicability in real-world scenarios where training on the target graph data is not possible due to issues like data privacy. To overcome this limitation, we propose a novel zero-shot generalist GAD approach UNPrompt that trains a one-for-all detection model, requiring the training of one GAD model on a single graph dataset and then effectively generalizing to detect anomalies in other graph datasets without any retraining or fine-tuning. The key insight in UNPrompt is that i) the predictability of latent node attributes can serve as a generalized anomaly measure and ii) highly generalized normal and abnormal graph patterns can be learned via latent node attribute prediction in a properly normalized node attribute space. UNPrompt achieves generalist GAD through two main modules: one module aligns the dimensionality and semantics of node attributes across different graphs via coordinate-wise normalization in a projected space, while another module learns generalized neighborhood prompts that support the use of latent node attribute predictability as an anomaly score across different datasets. Extensive experiments on real-world GAD datasets show that UNPrompt significantly outperforms diverse competing methods under the generalist GAD setting, and it also has strong superiority under the one-model-for-one-dataset setting. Code will be made available at https://github.com/mala-lab/UNPrompt .

## 1 Introduction

Graph anomaly detection (GAD) aims to identify anomalous nodes that exhibit significant deviations from the majority of nodes in a graph. GAD has attracted extensive research attention in recent years (Ma et al., ; Pang et al., ; Qiao et al., ) due to the board applications in various domains such as spam review detection in online shopping networks (McAuley & Leskovec, ; Rayana & Akoglu, ) and malicious user detection in social networks (Yang et al., ). To handle high-dimensional node attributes and complex structural relations between nodes, graph neural networks (GNNs) (Kipf & Welling, ; Wu et al., ) have been widely exploited for GAD due to their strong ability to integrate the node attributes and graph structures. These methods can be roughly divided into two categories, i.e., supervised and unsupervised methods. One category formulates GAD as a binary classification problem and aims to capture anomaly patterns under the guidance of labels (Tang et al., ; Peng et al., ; Gao et al., ; Wang et al., ). By contrast, due to the difficulty of obtaining these class labels, another category of methods takes the unsupervised approach that aims to learn normal graph patterns, e.g., via data reconstruction or other proxy learning tasks that are related to GAD (Qiao & Pang, ; Liu et al., ; Ding et al., ; Huang et al., ).

Despite their remarkable detection performance, these methods need to train a dataset-specific model for each graph dataset for GAD. This one-model-for-one-dataset paradigm limits their applicability in real-world scenarios since training a model from scratch incurs significant computation costs and requires even a large amount of labeled data for supervised GAD methods (Liu et al., ; Qiao et al., ). Training on a target graph may even not be possible due to data privacy protection and regulation. To address this limitation, a new one-for-all anomaly detection (AD) paradigm, called generalist anomaly detection (Zhu & Pang, ; Zhou et al., ), has been proposed for image AD with the emergence of foundation models such as CLIP (Radford et al., ). This new direction aims to learn a generalist detection model on auxiliary datasets so that it can generalize to detect anomalies effectively in diverse target datasets without any re-training or fine-tuning. This paper explores this direction in the area of GAD.

Compared to image AD, there are some unique challenges for learning generalist models for GAD. First, unlike image data where raw features are in the same RGB space, the node attributes in graphs from different applications and domains can differ significantly in node attribute dimensionality and semantics. For example, as a shopping network dataset, Amazon contains the relationships between users and reviews, and the node attribute dimensionality is 25. Differently, Facebook, a social network dataset, describes relationships between users with 576-dimensional attributes. Second, generalist AD models on image data rely on the superior generalizability learned in large visual-language models (VLMs) through pre-training on web-scale image-text-aligned data (Zhu & Pang, ; Zhou et al., ), whereas there are no such foundation models for graph data (Liu et al., ). Therefore, the key question here is: can we learn generalist models for GAD on graph data with heterogeneous node attributes and structure without the support of foundation models?

Figure: Figure 1: (a) Visualization of two popular GAD datasets: Facebook and Amazon, where the node attributes are unified into a common semantic space via our proposed normalization compared to the original heterogeneous raw attributes. (b)-(d) The anomaly scores of BWGNN (normal probability) (Tang et al., ), TAM (local affinity) (Qiao & Pang, ) and UNPrompt (latent attribute predictability) on the two datasets, where the methods are all trained on Facebook and tested on Amazon under the zero-shot setting. It is clear that BWGNN and TAM struggle to generalize from Facebook to Amazon, while UNPrompt can learn well to generalize across the datasets.
Refer to caption: x1.png

To address these challenges, we propose UNPrompt, a novel generalist GAD approach that learns Unified Neighborhood Prompts on a single auxiliary graph dataset and then effectively generalizes to directly detect anomalies in other graph datasets under a zero-shot setting. The key insight in UNPrompt is that i) the predictability of latent node attributes can serve as a generalized anomaly measure and ii) highly generalized normal and abnormal graph patterns can be learned via latent node attribute prediction in a properly normalized node attribute space. UNPrompt achieves this through two main modules including coordinate-wise normalization-based node attribute unification and neighborhood prompt learning. The former module aligns the dimensionality of node attributes across graphs and transforms the semantics into a common space via coordinate-wise normalization, as shown in Figure 1(a). In this way, the diverse distributions of node attributes are calibrated into the same semantic space. On the other hand, the latter module learns graph-agnostic normal and abnormal patterns via a neighborhood-based latent attribute prediction task, in which we incorporate learnable prompts into the normalized attributes of the neighbors of a target node to predict the latent attributes of the target node. Despite being trained on a small pre-trained GNN using a single graph, UNPrompt can effectively generalize to detect anomalous nodes in different unseen graphs without any re-training at the inference stage, as shown in Figure 1(b)-(d).

Overall, the main contributions of this paper are summarised as follows.
(1) We propose a novel zero-shot generalist GAD approach, UNPrompt. To the best of our knowledge, this is the first method that exhibits effective zero-shot GAD performance across various graph datasets. There is a concurrent work on generalist GAD (Liu et al., ), but it can only work under a few-shot setting. (2) We reveal that a simple yet effective coordinate-wise normalization can be utilized to unify the heterogeneous distributions in the node attributes across different graphs. (3) We further introduce a novel neighborhood prompt learning module that utilizes a neighborhood-based latent node attribute prediction task to learn generalized prompts in the normalized attribute space, enabling the zero-shot GAD across different graphs. (4) Extensive experiments on real-world GAD datasets show that UNPrompt significantly outperforms state-of-the-art competing methods under the zero-shot generalist GAD. (5) We show that UNPrompt can also work in the conventional one-model-for-one-dataset setting, outperforming state-of-the-art models in this popular GAD setting.

## 2 Related Work

Graph Anomaly Detection.
Existing GAD methods can be roughly categorized into unsupervised and supervised approaches (Ma et al., ; Qiao et al., ). The unsupervised methods are typically built using data reconstruction, self-supervised learning, and learnable graph anomaly measures (Qiao et al., ; Liu et al., ). The reconstruction-based approaches like DOMINANT (Ding et al., ) and AnomalyDAE (Fan et al., ) aim to capture the normal patterns in the graph, where the reconstruction error in both graph structure and attributes is utilized as the anomaly score. CoLA (Liu et al., ) and SL-GAD (Zheng et al., ) are representative self-supervised learning methods assuming that normality is reflected in the relationship between the target node and its contextual nodes. The graph anomaly measure methods typically leverage the graph structure-aware anomaly measures to learn intrinsic normal patterns for GAD, such as node affinity in TAM (Qiao & Pang, ). In contrast to the unsupervised approaches, the supervised anomaly detection approaches have shown substantially better detection performance in recent years due to the incorporation of labeled anomaly data (Liu et al., ; Chai et al., ; Wang et al., ). Most supervised methods concentrate on the design of propagation mechanisms and spectral feature transformations to address the notorious over-smoothing feature representation issues (Tang et al., ; Gao et al., ; Chai et al., ). Although both approaches can be adapted for zero-shot GAD by directly applying the trained GAD models to the testing datasets, they struggle to capture generalized normal and abnormal patterns for GAD across different graph datasets. There are some studies working on cross-domain GAD (Ding et al., ; Wang et al., ) that aim to transfer knowledge from a labeled graph dataset for GAD on a target dataset, but it is a fundamentally different problem from generalist GAD since cross-domain GAD requires the training on both source and target graph datasets.

Graph Prompt Learning.
Prompt learning, initially developed in the field of natural language processing, seeks to adapt large-scale pre-trained models to different downstream tasks by incorporating learnable prompts while keeping the pre-trained models themselves frozen (Liu et al., ). Specifically, it designs task-specific prompts capturing the knowledge of the corresponding tasks and enhances the compatibility between inputs and pre-trained models to enhance the pre-trained models in downstream tasks. Recently, prompt learning has been explored in graphs to unify multiple graph tasks (Sun et al., ; Liu et al., ), improve the transferability of graph models on the datasets across the different domains (Li et al., ; Zhao et al., ) and graph continual learning (Niu et al., ), e.g., by optimizing the prompts with labeled data of various downstream tasks (Fang et al., ; Liu et al., ). Although being effective in popular graph learning tasks like node classification and link prediction, they are inapplicable to generalist GAD due to its unsupervised nature and/or irregular distributions of anomalies.

Generalist Anomaly Detection.
Generalist AD has been very recently emerging as promising approaches to tackle sample efficiency and model generalization problems in AD. There have been a few studies on non-graph data that have large pre-trained models to support the generalized pattern learning, such as image generalist AD (Zhou et al., ; Zhu & Pang, ). However, it is a very challenging task for data like graph data due to the lack of such pre-trained models. Recently
a concurrent approach, ARC (Liu et al., ), introduces an effective framework that leverages in-context learning to achieve generalist GAD without relying on large pre-trained GNNs. Unlike ARC which focuses on a few-shot GAD setting, i.e., requiring the availability of some labeled nodes in the target testing graph dataset, we tackle a zero-shot GAD setting assuming no access to any labeled data during inference stages.

## 3 Methodology

### 3.1 Preliminaries

#### Notations.

Let $\mathcal{G}=(\mathcal{V},\mathcal{E})$ be an attributed graph with $N$ nodes, where $\mathcal{V}=\{v_{1},v_{2},\ldots,v_{N}\}$ represents the node set and $\mathcal{E}$ is the edge set. The attributes of nodes can be denoted as $X=[\mathbf{x}_{1},\mathbf{x}_{2},\ldots,\mathbf{x}_{N}]^{T}\in\mathbb{R}^{N
\times d}$ and the edges between nodes can be presented by an adjacency matrix $A\in\{0,1\}^{N\times N}$ with $A_{ij}=1$ if there is an edge between $v_{i}$ and $v_{j}$ and $A_{ij}=0$ otherwise. For simplicity, the graph can be represented as $\mathcal{G}=(A,X)$. In GAD, the node set can be divided into a set of the normal nodes $\mathcal{V}_{n}$ and a set of anomalous nodes $\mathcal{V}_{a}$. Typically, the number of normal nodes is significantly larger than the anomalous nodes, i.e., $|\mathcal{V}_{n}|\gg|\mathcal{V}_{a}|$. Moreover, the anomaly labels can be denoted as $\mathbf{y}\in\{0,1\}^{N}$ with $\mathbf{y}_{i}=1$ if $v_{i}\in\mathcal{V}_{a}$ and $\mathbf{y}_{i}=0$ otherwise.

#### Generalist GAD.

Conventional GAD methods typically focus on model training and anomaly detection on the same graph. Specifically, given a graph $\mathcal{G}$, an anomaly scoring model $f:\mathcal{G}\rightarrow\mathbb{R}$ is optimized on $\mathcal{G}$ to detect anomalies within the same graph in a supervised or unsupervised manner. The scoring function is then expected to generate higher anomaly scores for abnormal nodes than normal nodes, i.e., $f(v_{i})<f(v_{j})$ if $v_{i}\in\mathcal{V}_{n}$ and $v_{j}\in\mathcal{V}_{a}$. By contrast, generalist GAD aims to learn a generalist model $f$ on a single training graph so that the learned model can be directly adapted to different target graphs across diverse domains without any fine-tuning or re-training. More specifically, the model is optimized on $\mathcal{G}_{\text{train}}$ with the corresponding anomaly labels $\mathbf{y}_{\text{train}}$. After model optimization, the learned model $f$ is utilized to detect anomalies within different unseen target graphs $\mathcal{T}_{\text{test}}=\{\mathcal{G}^{(1)}_{\text{test}},\ldots,\mathcal{G}
^{(n)}_{\text{test}}\}$ which has heterogeneous attributes and/or structure to $\mathcal{G}_{\text{train}}$, i.e., $\mathcal{G}_{\text{train}}\cap\mathcal{T}_{\text{test}}=\emptyset$. Depending on whether labeled nodes of the target graph are provided during inference, the generalist GAD problem can be further divided into two categories, i.e., few-shot and zero-shot settings. In this paper, we focus on the zero-shot setting where the generalist models cannot get access to any labeled data of the testing graphs during both training and inference.

### 3.2 Overview of The Proposed Approach – UNPrompt

The framework of the proposed approach is illustrated in Figure 2. UNPrompt consists of two main modules, coordinate-wise normalization-based node attribute unification and neighborhood prompt learning. Specifically, for all graphs, the node attribute unification aligns the dimensionality of node attributes across graphs and transforms the semantics into a common space via coordinate-wise normalization in a projected space. Then, in the normalized node attribute space, the generalized neighborhood-based latent attribute prediction task is performed with the neighborhood prompts to learn generalized GAD patterns at the training stage. In this prompt learning module, UNPrompt aims to maximize the predictability of the latent attributes of normal nodes while minimizing those of abnormal nodes. In this paper, we evaluate the predictability via the similarity. In doing so, the graph-agnostic normal and abnormal patterns are incorporated into the prompts. During inference, the target graph is directly fed into the learned models after node attribute unification without any re-training or labeled nodes of the graph. For each node, the predictability of latent node attributes is directly used as the normal score for final anomaly detection.

Figure: Figure 2: Overview of UNPrompt. For all graphs, node attribute unification is employed to align the attribute dimensionality and semantics. At the training stage, the neighborhood prompts are optimized to capture the generalized patterns by maximizing the predictability of the latent attributes (i.e., the embedding $\mathbf{z}_{i}$) of normal nodes while minimizing that of abnormal nodes. During inference, the learned prompts are directly applied to the testing nodes, and the latent attribute predictability of each testing node is used as the normal score for GAD.
Refer to caption: x2.png

### 3.3 Node Attribute Unification

Graphs from different distributions and domains significantly differ in the dimensionality and semantics of node attributes. Therefore, the premise of developing a generalist GAD model is to unify the dimensionality and semantics of node attributes into the same space. In this paper, we propose a simple yet effective node attribute unification module to address this issue, which consists of feature projection and coordinate-wise normalization. Different from ARC (Liu et al., ) which aligns the attributes based on feature reordering using feature smoothness, we calibrate the feature distributions of diverse graphs into the same frame, resulting in a simpler yet effective alignment.

#### Feature Projection.

To address the inconsistent attribute dimensions across graphs, various feature projection methods can be utilized, such as singular value decomposition (Stewart, ) (SVD) and principal component analysis (Abdi & Williams, ) (PCA). Formally, given the attribute matrix $X^{(i)}\in\mathbb{R}^{N^{(i)}\times d^{(i)}}$ of any graph $\mathcal{G}^{(i)}$ from $\mathcal{G}_{\text{train}}\cup\mathcal{T}_{\text{test}}$, we transform it into $\tilde{X}^{(i)}\in\mathbb{R}^{N^{(i)}\times d^{{}^{\prime}}}$ with the common dimensionality of $d^{{}^{\prime}}$,

$$ $X^{(i)}\in\mathbb{R}^{N^{(i)}\times d^{(i)}}\xrightarrow[\text{Projection}]{ \text{Feature}}\tilde{X}^{(i)}\in\mathbb{R}^{N^{(i)}\times d^{{}^{\prime}}}\,.$ (1) $$

#### Coordinate-wise normalization.

Despite the attribute dimensionality being unified, the semantics and distributions of each attribute dimension are still divergent across graphs, posing significant challenges to learning a generalist GAD model. A recent study (Li et al., ) has demonstrated that semantic differences across datasets are mainly reflected in the distribution shifts and calibrating the distributions into a common frame helps learn more generalized AD models. Inspired by this, we propose to use coordinate-wise normalization to align the semantics and unify the distributions across graphs. Specifically, the transformed attribute matrix $\tilde{X}^{(i)}$ is shifted and re-scaled to have mean zeros and variance ones via the following equation:

$$ $\bar{X}^{(i)}=\frac{\tilde{X}^{(i)}-\bm{\mu}^{(i)}}{\bm{\sigma}^{(i)}}\,,$ (2) $$

where $\bm{\mu}^{(i)}=[{\mu}^{(i)}_{1},\ldots,{\mu}^{(i)}_{d^{{}^{\prime}}}]$ and $\bm{\sigma}^{(i)}=[{\sigma}^{(i)}_{1},\ldots,{\sigma}^{(i)}_{d^{{}^{\prime}}}]$ are the coordinate-wise mean and variance of $\tilde{X}^{(i)}$ of the graph $\mathcal{G}^{(i)}$. In this way, the distributions of normalized attributes along each dimension are the same within and across graphs, as shown in Figure 1(a). This helps to capture the generalized normal and abnormal patterns for generalist GAD (see Table 2).

### 3.4 Neighborhood Prompt Learning via Latent Node Attribute Prediction

#### Latent Node Attribute Predictability as Anomaly Score.

To build a generalist GAD model, one must capture the generalized normal and abnormal patterns across graphs. Otherwise, the model would overfit the dataset-specific knowledge of the training graph which can be very different from that in target graphs. In this paper, we reveal that the predictability of latent node attributes can serve as a generalized anomaly measure, and thus, highly generalized normal and abnormal graph patterns can be learned via latent node attribute prediction in the normalized node attribute space with the neighborhood prompts. The key intuition of this anomaly measure is that normal nodes tend to have more connections with normal nodes of similar attributes due to prevalent graph homophily relations, resulting in a more homogeneous neighborhood in the normal nodes (Qiao & Pang, ); by contrast, the presence of anomalous connections and/or attributes makes abnormal nodes deviate significantly from their neighbors. Therefore, for a target node, its latent attributes (i.e., node embedding) are more predictable based on the latent attributes of its neighbors if the node is a normal node, compared to abnormal nodes. The neighborhood-based latent attribute prediction is thus used to measure the normality for GAD. As shown in our experiments (see Figures 1(b)-(d) and Tables 1 and 3), it is a generalized anomaly scoring method that works effectively across graphs. However, due to the existence of irrelevant and noisy attribute information in the original attribute space, the attribute prediction is not as effective as expected in the simply projected space after attribute unification. To address this issue, we propose to learn discriminative prompts via the latent attribute prediction task to enhance the effectiveness of this anomaly measure.

To achieve this, we first design a simple graph neural network $g$, a neighborhood aggregation network, to generate the aggregated neighborhood embedding of each target node.
Specifically, given a graph $\mathcal{G}=(A,\bar{X})$, the aggregated neighborhood embeddings for each node are obtained as follows:

$$ $\tilde{Z}=g(\mathcal{G})=\tilde{A}\bar{X}W\,,$ (3) $$

where $\tilde{Z}$ is the aggregated representation of neighbors, $\tilde{A}=(D)^{-1}A$ is the normalized adjacency matrix with $D$ being a diagonal matrix and its elements $D_{kk}=\sum_{j}A_{kj}$, and $W$ is the learnable parameters. Compared to conventional GNNs such as GCN (Kipf & Welling, ) and SGC (Wu et al., ), we do not require $\tilde{A}$ to be self-looped and symmetrically normalized as we aim to obtain the aggregated representation of all the neighbors for each node. To design the latent node attribute prediction task, we further obtain the latent attributes of each node as follows:

$$ $Z=\bar{X}W\,,$ (4) $$

where $Z$ serves as the prediction ground truth for the latent attribute prediction task. The adjacency matrix $A$ is discarded to avoid carrying neighborhood-based attribute information into $Z$ which would lead to ground truth leakage in this prediction task. We further propose to utilize the cosine similarity to measure this neighborhood-based latent attribute predictability for each node:

$$ $s_{i}=\text{sim}(\mathbf{z}_{i},\tilde{\mathbf{z}}_{i})=\frac{\mathbf{z}_{i}( \tilde{\mathbf{z}}_{i})^{T}}{\|\mathbf{z}_{i}\|\|\tilde{\mathbf{z}}_{i}\|}\,,$ (5) $$

where $\mathbf{z}$ and $\tilde{\mathbf{z}}_{i}$ are the $i$-th node embeddings in $Z$ and $\tilde{Z}$ respectively. A higher similarity denotes the target node can be well predicted by its neighbors and indicates the target is normal with a higher probability. Therefore, we directly utilize the similarity to measure the normal score of the nodes.

#### GNN Pre-training.

To build generalist models, pre-training is required. Here we pre-train the above neighborhood aggregation network via graph contrastive learning due to the ability to obtain robust and transferable models (You et al., ; Zhu et al., ) across graphs (see Appendix B for the details). Without pre-training, the dataset-specific knowledge would be captured by the model if it is directly optimized based on the neighborhood-based latent attribute prediction of normal and abnormal nodes, limiting the generalizability of the model to other graphs (see Table 2).

#### Neighborhood Prompting via Latent Attribute Prediction.

After learning the pre-trained model $g$, we aim to further learn more generalized normal and abnormal graph patterns via prompt tuning in the normalized node attribute space. Thus, we devise learnable prompts appending to the attributes of the neighboring nodes of the target nodes, namely neighborhood prompts, for learning robust and discriminative patterns that can detect anomalous nodes in different unseen graphs without any re-training at the inference stage.

Specifically, neighborhood prompting aims to optimize some learnable prompt tokens that help maximize the neighborhood-based latent prediction of normal nodes while minimizing that of abnormal nodes simultaneously. To this end, the prompt is designed as a set of shared and learnable tokens that can be incorporated into the normalized node attributes. Formally, the neighborhood prompts are represented as $P=[\mathbf{p}_{1},\ldots,\mathbf{p}_{k}]^{T}\in\mathbb{R}^{K\times d^{{}^{
\prime}}}$ where $K$ is the number of vector-based tokens $\mathbf{p}_{i}$. For each node in $\mathcal{G}=(A,\bar{X})$, the node attributes in the unified feature space are augmented by the weighted combination of these tokens, with the weights obtained from $K$ learnable linear projections:

$$ $\hat{\mathbf{x}}_{i}=\bar{\mathbf{x}}_{i}+\sum_{j}^{K}\alpha_{j}\mathbf{p}_{j} \,,\ \ \alpha_{j}=\frac{e^{(\mathbf{w}_{j})^{T}\mathbf{x}_{i}^{t}}}{\sum_{l}^{ K}e^{(\mathbf{w}_{l})^{T}\mathbf{x}_{i}^{t}}}\,,$ (6) $$

where $\alpha_{j}$ denotes the importance score of the token $\mathbf{p}_{j}$ in the prompt and $\mathbf{w}_{j}$ is a learnable projection. For convenience, we denote the graph modified by the graph prompt as $\tilde{\mathcal{G}}=(A,\bar{X}+P)$. Then, $\tilde{\mathcal{G}}$ is fed into the frozen pre-trained model $g$ to obtain the corresponding aggregated embeddings $\tilde{Z}$ and node latent attributes $Z$ via Eq.(3) and Eq.(4) respectively to measure the attribute predictability. To further enhance the representation discrimination, a transformation layer $h$ is applied on the learned $\tilde{Z}$ and $Z$ to transform them into a more anomaly-discriminative feature space,

$$ $\tilde{Z}=h(\tilde{Z})\,,\ \ \ \ Z=h(Z)\,.$ (7) $$

The transformed representations are then used to measure the latent node attribute predictability with Eq.(5). To optimize the prompts and transformation layer with the training graph $\mathcal{G}_{\text{train}}$, we employ the following training objective,

$$ $\min_{P,h}\ \ \sum\ell(\mathbf{z}_{i},\tilde{\mathbf{z}}_{i})\,,$ (8) $$

where $\ell(\mathbf{z}_{i},\tilde{\mathbf{z}}_{i})=-\text{sim}(\mathbf{z}_{i},\tilde{
\mathbf{z}}_{i})$ if $\mathbf{y}_{i}=0$, and $\ell(\mathbf{z}_{i},\tilde{\mathbf{z}}_{i})=\text{sim}(\mathbf{z}_{i},\tilde{
\mathbf{z}}_{i})$ if $\mathbf{y}_{i}=1$.

### 3.5 Training and Inference of UNPrompt

Training.
The training process of UNPrompt can be divided into two parts. First, given the training graph $\mathcal{G}_{\text{train}}$, a neighborhood aggregation network $g$ is optimized via graph contrastive learning at its pre-training stage. Then, the neighborhood prompts $P$ and the transformation layer $h$ are optimized to capture the graph-agnostic normal and abnormal patterns while keeping the pre-trained model $g$ frozen. In this way, the transferable knowledge of the pre-trained $g$ is maintained, while the neighborhood prompt learning helps learn the generalized normal and abnormal patterns.

Inference.
At the inference stage, given a test graph $\mathcal{G}_{\text{test}}^{(i)}\in\mathcal{T}_{\text{test}}$, the node attributes are first aligned with the proposed node attribute unification. Then, the test graph $\mathcal{G}_{\text{test}}^{(i)}$ is augmented with the corresponding neighborhood prompt $P$ learned during training and fed into the model $g$ and the transformation layer $h$ to obtain the neighborhood aggregated representations and the latent node attributes. Finally, the similarity defined in Eq.(5) is used as normal score for the test nodes for anomaly detection. Note that the inference does not require any further re-training and labeled nodes of $\mathcal{G}_{\text{test}}^{(i)}$.

The algorithms of the training and inference of UNPrompt are provided in Appendix C.

## 4 Experiments

### 4.1 Performance on Zero-shot Generalist GAD

#### Datasets.

We evaluate the proposed UNPrompt on seven real-world GAD datasets from diverse social networks and online shopping co-review networks. Specifically, the social networks include Facebook (Xu et al., ), Reddit (Kumar et al., ) and Weibo (Kumar et al., ). The co-review networks consist of Amazon (McAuley & Leskovec, ), YelpChi (Rayana & Akoglu, ), Amazon-all (McAuley & Leskovec, ) and YelpChi-all (Rayana & Akoglu, ). All the datasets contain real anomalous nodes (see Appendix F.1 for more dataset details).

#### Competing Methods.

Since there is no zero-shot generalist GAD method, a set of eight state-of-the-art (SotA) unsupervised and supervised competing methods are employed for comparison in our experiments. The unsupervised methods comprise reconstruction-based AnomalyDAE (Fan et al., ), contrastive learning-based CoLA (Liu et al., ), hop predictition-based HCM-A (Huang et al., ), and local affinity-based TAM (Qiao & Pang, ). Supervised methods include two conventional GNNs – GCN (Kipf & Welling, ) and GAT (Veličković et al., ) – and two SotA GAD GNNs – BWGNN (Tang et al., ) and GHRN (Gao et al., ).

Following (Liu et al., ; Qiao & Pang, ; Qiao et al., ), two widely-used metrics, AUROC and AUPRC, are used to evaluate the performance of all methods. For both metrics, the higher value denotes the better performance. Moreover, for each method, we report the average performance with standard deviations after 5 independent runs with different random seeds.

#### Implementation Details.

To ensure a fair comparison, the common dimensionality is set to eight to unify the node attribute across graphs for all methods, and SVD is used for feature projection. The number of layers in GNNs is set to one and the number of hidden units is 128. The transformation layer is also implemented via a one-layer MLP with the same number of hidden units. The size of the neighborhood prompt is set to one by default. For all baselines, we adopt their official code and follow the recommended optimization and hyperparameter settings to conduct the experiments. UNPrompt and all its competing methods are trained on Facebook and then directly tested on the other six GAD datasets without any further training or additional knowledge of the target graphs.

**Table 1: AUROC and AUPRC results on six real-world GAD datasets with the models trained on Facebook only. For each dataset, the best performance per column within each metric is boldfaced, with the second-best underlined. “Avg” denotes the averaged performance of each method.**
| Metric | Method | Dataset |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Amazon | Reddit | Weibo | YelpChi | Aamzon-all | YelpChi-all | Avg. |  |
| AUROC | Unsupervised Methods |  |  |  |  |  |  |
| AnomalyDAE | 0.5818±0.039 | 0.5016±0.032 | 0.7785±0.058 | 0.4837±0.094 | 0.7228±0.023 | 0.5002±0.018 | 0.5948 |
| CoLA | 0.4580±0.054 | 0.4623±0.005 | 0.3924±0.041 | 0.4907±0.017 | 0.4091±0.052 | 0.4879±0.010 | 0.4501 |
| HCM-A | 0.4784±0.005 | 0.5387±0.041 | 0.5782±0.048 | 0.5000±0.000 | 0.5056±0.059 | 0.5023±0.005 | 0.5172 |
| TAM | 0.4720±0.005 | 0.5725±0.004 | 0.4867±0.028 | 0.5035±0.014 | 0.7543±0.002 | 0.4216±0.002 | 0.5351 |
| Supervised Methods |  |  |  |  |  |  |  |
| GCN | 0.5988±0.016 | 0.5645±0.000 | 0.2232±0.074 | 0.5366±0.019 | 0.7195±0.002 | 0.5486±0.001 | 0.5319 |
| GAT | 0.4981±0.008 | 0.5000±0.025 | 0.4521±0.101 | 0.5871±0.016 | 0.5005±0.012 | 0.4802±0.004 | 0.5030 |
| BWGNN | 0.4769±0.020 | 0.5208±0.016 | 0.4815±0.108 | 0.5538±0.027 | 0.3648±0.050 | 0.5282±0.015 | 0.4877 |
| GHRN | 0.4560±0.033 | 0.5253±0.006 | 0.5318±0.038 | 0.5524±0.020 | 0.3382±0.085 | 0.5125±0.016 | 0.4860 |
| UNPrompt (Ours) | 0.7525±0.016 | 0.5337±0.002 | 0.8860±0.007 | 0.5875±0.016 | 0.7962±0.022 | 0.5558±0.012 | 0.6853 |
| AUPRC | Unsupervised Methods |  |  |  |  |  |  |
| AnomalyDAE | 0.0833±0.015 | 0.0327±0.004 | 0.6064±0.031 | 0.0624±0.017 | 0.1921±0.026 | 0.1484±0.009 | 0.1876 |
| CoLA | 0.0669±0.002 | 0.0391±0.004 | 0.1189±0.014 | 0.0511±0.000 | 0.0861±0.019 | 0.1466±0.003 | 0.0848 |
| HCM-A | 0.0669±0.002 | 0.0391±0.004 | 0.1189±0.014 | 0.0511±0.000 | 0.0861±0.019 | 0.1466±0.003 | 0.0848 |
| TAM | 0.0666±0.001 | 0.0413±0.001 | 0.1240±0.014 | 0.0524±0.002 | 0.1736±0.004 | 0.1240±0.001 | 0.0970 |
| Supervised Methods |  |  |  |  |  |  |  |
| GCN | 0.0891±0.007 | 0.0439±0.000 | 0.1109±0.020 | 0.0648±0.009 | 0.1536±0.002 | 0.1735±0.000 | 0.1060 |
| GAT | 0.0688±0.002 | 0.0329±0.002 | 0.1009±0.017 | 0.0810±0.005 | 0.0696±0.001 | 0.1400±0.002 | 0.0822 |
| BWGNN | 0.0652±0.002 | 0.0389±0.003 | 0.2241±0.046 | 0.0708±0.018 | 0.0586±0.003 | 0.1605±0.005 | 0.1030 |
| GHRN | 0.0633±0.003 | 0.0407±0.002 | 0.1965±0.059 | 0.0661±0.010 | 0.0569±0.006 | 0.1505±0.005 | 0.0957 |
| UNPrompt (Ours) | 0.1602±0.013 | 0.0351±0.000 | 0.6406±0.026 | 0.0712±0.008 | 0.2430±0.028 | 0.1810±0.012 | 0.2219 |

#### Main Results.

The AUROC and AUPRC results of all methods are presented in Table 1. From the table, we can have the following observations. (1) Under the proposed generalist GAD scenario where a model is trained on a single dataset and evaluated on six other datasets, all the competing baselines fail to work well, demonstrating that it is very challenging to build a generalist GAD model that generalizes across different datasets under zero-shot setting. (2) For supervised methods, the simple GCN achieves better performance than the specially designed GAD GNNs. This can be attributed to more dataset-specific knowledge being captured in these specialized GAD models, limiting their generalization capacity to the unseen testing graphs. (3) Unsupervised methods perform more stable than supervised methods across the target graphs and generally outperform supervised ones. This is because the unsupervised objectives are closer to the shared anomaly patterns across graphs compared to the supervised ones, especially for TAM which employs a fairly generalized local affinity-based objective to train the model. (4) The proposed method UNPrompt demonstrates strong and stable generalist GAD capacity across graphs from different distributions and domains. Specifically, UNPrompt achieves the best AUROC performance on 5 out of 6 datasets and the average performance outperforms the best-competing method by over 9%. In terms of AUPRC, UNPrompt outperforms all baselines on 4 out of 6 datasets and also achieves the best average performance. The superiority of UNPrompt is attributed to the fact that i) the proposed coordinate-wise normalization effectively aligns the features across graphs, and ii) the shared generalized normal and abnormal patterns are well captured in the neighborhood prompts.

**Table 2: AUROC results of the proposed method UNPrompt and its four variants.**
| Method | Amazon | Reddit | Weibo | YelpChi | Aamzon-all | YelpChi-all | Avg. |
| --- | --- | --- | --- | --- | --- | --- | --- |
| UNPrompt | 0.7525 | 0.5337 | 0.8860 | 0.5875 | 0.7962 | 0.5558 | 0.6853 |
| w/o Normalization | 0.4684 | 0.5006 | 0.1889 | 0.5620 | 0.3993 | 0.5466 | 0.4443 |
| w/o Pre-training | 0.5400 | 0.5233 | 0.5658 | 0.4672 | 0.3902 | 0.4943 | 0.4968 |
| w/o Prompt | 0.5328 | 0.5500 | 0.4000 | 0.4520 | 0.4096 | 0.4894 | 0.4723 |
| w/o Transformation | 0.7331 | 0.5556 | 0.7406 | 0.5712 | 0.7691 | 0.5545 | 0.6540 |

#### Ablation Study.

To evaluate the importance of each component in UNPrompt, we design four variants by discarding one of its corresponding component, i.e., w/o coordinate-wise normalization, w/o graph contrastive learning-based pre-training, without neighborhood prompts, and w/o transformation layer. The results of these variants are reported in the Table 2. From the table, we can see that all four components contribute to the overall superior performance of UNPrompt. More specifically, (1) without the coordinate-wise normalization, the method fails to calibrate the distributions of diverse node attributes into a common space, leading to large performance drop across all datasets. (2) Besides the semantics alignment, the graph contrastive learning-based pre-training ensures our GNN network is transferable to other graphs instead of overfitting to the training graph. As expected, the performance of the variant without pre-training also drops significantly. (3) If the neighborhood prompts are removed, the learning of latent node attribute prediction is ineffective for capturing generalized normal and abnormal patterns. (4) The variant without the transformation layer achieves inferior performance on nearly all the datasets, demonstrating the importance of mapping the features into a more anomaly-discriminative space.

#### Sensitivity w.r.t the Neighborhood Prompt Size.

We evaluate the sensitivity of UNPrompt w.r.t the size of the neighborhood prompts, i.e., the number of tokens $K$. We vary $K$ in the range of $[1,9]$ and report the results in Figure 3. It is clear that the performances on Reddit, Weibo and YelpChi-all remain stable with varying sizes of neighborhood prompts while the other datasets show slight fluctuation, demonstrating that the generalized normal and abnormal patterns can be effectively captured in our neighborhood prompts even with a small size.

#### Prompt learning using latent attribute prediction vs. alternative graph anomaly measures.

To further justify the effectiveness of latent attribute predictability on learning generalized GAD patterns in our prompt learning module, we compare this proposed learnable anomaly measure to the recently proposed anomaly measure, local node affinity in TAM (Qiao & Pang, ). All modules of UNPrompt are fixed with only the latent attribute prediction task replaced as the maximization of local affinity as in TAM. The results are presented in Figure 3. We can see that the latent attribute predictability consistently and significantly outperforms the local affinity-based measure across all graphs, demonstrating its superiority in learning generalized patterns for generalist GAD.

### 4.2 Performance on Conventional Unsupervised GAD

We also evaluate the applicability of UNPrompt under the conventional unsupervised GAD setting to further verify the effectiveness of the latent note attribute prediction-based anomaly scores using our proposed neighborhood prompt learning. Specifically, we adopt the same pipeline as in the generalist GAD setting, i.e., graph contrastive-based pre-training and neighborhood prompt learning. Different from the training process in the generalist setting, there is no label information available in unsupervised GAD since models are trained and evaluated on the same graph data. To address this issue, we employ the pseudo-labeling technique to provide supervision for neighborhood prompt learning. In a nutshell, we enforce the neighborhood prompts to maximize the latent attribute predictability of high-score nodes. More details on unsupervised GAD are provided in Appendix D.

#### Experimental Setup.

In this experiment, six datasets from different distributions and domains are used, including Amazon, Facebook, Reddit, YelpCHi, Amazon-all, and YelpChi-all. Following (Qiao & Pang, ), eight SotA unsupervised baselines are used for comparison, i.e., iForest (Liu et al., ), ANOMALOUS (Peng et al., ), CoLA (Liu et al., ), SL-GAD (Zheng et al., ), HCM-A (Huang et al., ), DOMINANT (Ding et al., ), ComGA (Luo et al., ) and TAM (Qiao & Pang, ). For each method, we also report the average performance with standard deviations after 5 independent runs with different random seeds. The implementation details of UNPrompt remain the same as in the generalist GAD setting. More experimental details on unsupervised GAD are in Appendix F.2.

#### Main Results.

The AUROC and AUPRC results of all methods are presented in Table 3. As shown in the table, despite being a generalist GAD method, UNPrompt works very well as a specialized GAD model too. UNPrompt substantially outperforms all the competing methods on all datasets in terms of both AUROC and AUPRC. Particularly, the average performance of UNPrompt surpasses the best-competing method TAM by over 2% in both metrics. Moreover, UNPrompt outperforms the best-competing method by 2%-6% in AUROC on most of the datasets. The superior performance shows that the latent node attribute predictability can be a generalized GAD measure that holds for different graphs, and this property can be effectively learned by the proposed neighborhood prompting method.

Figure: Figure 3: (a) AUROC and AUPRC results of UNPrompt w.r.t. varying neighborhood prompt size. (b). The AUROC performance of generalist GAD with different prompt learning objectives.
Refer to caption: x3.png

**Table 3: AUROC and AUPRC results of unsupervised GAD methods on six real-world GAD datasets. The best performance per column within each metric is boldfaced, with the second-best underlined. “Avg” denotes the averaged performance of each method.**
| Metric | Method | Dataset |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Amazon | Facebook | Reddit | YelpChi | Amazon-all | YelpChi-all | Avg. |  |  |
| AUROC | iForest | 0.5621±0.008 | 0.5382±0.015 | 0.4363±0.020 | 0.4120±0.040 | 0.1914±0.002 | 0.3617±0.001 | 0.4169 |
| ANOMALOUS | 0.4457±0.003 | 0.9021±0.005 | 0.5387±0.012 | 0.4956±0.003 | 0.3230±0.021 | 0.3474±0.018 | 0.5087 |  |
| DOMINANT | 0.5996±0.004 | 0.5677±0.002 | 0.5555±0.011 | 0.4133±0.010 | 0.6937±0.028 | 0.5390±0.014 | 0.5615 |  |
| CoLA | 0.5898±0.008 | 0.8434±0.011 | 0.6028±0.007 | 0.4636±0.001 | 0.2614±0.021 | 0.4801±0.016 | 0.5402 |  |
| SL-GAD | 0.5937±0.011 | 0.7936±0.005 | 0.5677±0.005 | 0.3312±0.035 | 0.2728±0.012 | 0.5551±0.015 | 0.5190 |  |
| HCM-A | 0.3956±0.014 | 0.7387±0.032 | 0.4593±0.011 | 0.4593±0.005 | 0.4191±0.011 | 0.5691±0.018 | 0.5069 |  |
| ComGA | 0.5895±0.008 | 0.6055±0.000 | 0.5453±0.003 | 0.4391±0.000 | 0.7154±0.014 | 0.5352±0.006 | 0.5716 |  |
| TAM | 0.7064±0.010 | 0.9144±0.008 | 0.6023±0.004 | 0.5643±0.007 | 0.8476±0.028 | 0.5818±0.033 | 0.7028 |  |
|  | UNPrompt (Ours) | 0.7335±0.020 | 0.9379±0.006 | 0.6067±0.006 | 0.6223±0.007 | 0.8516±0.004 | 0.6084±0.001 | 0.7267 |
| AUPRC | iForest | 0.1371±0.002 | 0.0316±0.003 | 0.0269±0.001 | 0.0409±0.000 | 0.0399±0.001 | 0.1092±0.001 | 0.0643 |
| ANOMALOUS | 0.0558±0.001 | 0.1898±0.004 | 0.0375±0.004 | 0.0519±0.002 | 0.0321±0.001 | 0.0361±0.005 | 0.0672 |  |
| DOMINANT | 0.1424±0.002 | 0.0314±0.041 | 0.0356±0.002 | 0.0395±0.020 | 0.1015±0.018 | 0.1638±0.007 | 0.0857 |  |
| CoLA | 0.0677±0.001 | 0.2106±0.017 | 0.0449±0.002 | 0.0448±0.002 | 0.0516±0.001 | 0.1361±0.015 | 0.0926 |  |
| SL-GAD | 0.0634±0.005 | 0.1316±0.020 | 0.0406±0.004 | 0.0350±0.000 | 0.0444±0.001 | 0.1711±0.011 | 0.0810 |  |
| HCM-A | 0.0527±0.015 | 0.0713±0.004 | 0.0287±0.005 | 0.0287±0.012 | 0.0565±0.003 | 0.1154±0.004 | 0.0589 |  |
| ComGA | 0.1153±0.005 | 0.0354±0.001 | 0.0374±0.001 | 0.0423±0.000 | 0.1854±0.003 | 0.1658±0.003 | 0.0969 |  |
| TAM | 0.2634±0.008 | 0.2233±0.016 | 0.0446±0.001 | 0.0778±0.009 | 0.4346±0.021 | 0.1886±0.017 | 0.2054 |  |
|  | UNPrompt (Ours) | 0.2688±0.060 | 0.2622±0.028 | 0.0450±0.001 | 0.0895±0.004 | 0.6094±0.014 | 0.2068±0.004 | 0.2470 |

## 5 Conclusion

In this paper, we propose a novel zero-shot generalist GAD method, UNPrompt, that trains one detector on a single dataset and can effectively generalize to other unseen target graphs without any further re-training or labeled nodes of target graphs during inference. The attribute inconsistency and the absence of generalized anomaly patterns are the main obstacles for generalist GAD. To address these issues, two main modules are proposed in UNPrompt, i.e., coordinate-wise normalization-based node attribute unification and neighborhood prompt learning. The first module aligns node attribute dimensionality and semantics, while the second module captures generalized normal and abnormal patterns via the neighborhood-based latent node attribute prediction. Extensive experiments on various real-world GAD datasets from different distributions and domains demonstrate the effectiveness of UNPrompt for generalist GAD. Besides, the experiments conducted on the unsupervised GAD with UNPrompt further support the rationality of the learned anomaly patterns in the generalist model.

## Appendix A Graph Similarity

In addition to the visualization results presented in Figure 1, we further provide the distributional similarity of various graphs in this section. Specifically, for dimension-aligned graphs across different distributions and domains, we measure their distributional similarity to analyze their diverse semantics.

Given a graph $\mathcal{G}^{(i)}=(A^{(i)},\tilde{X}^{(i)})$, the coordinate-wise mean $\bm{\mu}^{(i)}=[{\mu}^{(i)}_{1},\ldots,{\mu}^{(i)}_{d^{{}^{\prime}}}]$ and variance $\bm{\sigma}^{(i)}=[{\sigma}^{(i)}_{1},\ldots,{\sigma}^{(i)}_{d^{{}^{\prime}}}]$ of $\tilde{X}^{(i)}$ are calculated and concatenated to form the distributional vector of $\mathcal{G}^{(i)}$, i.e., $\mathbf{d}_{i}=[\bm{\mu}^{(i)},\bm{\sigma}^{(i)}]$. Then, the distribution similarity between $\mathcal{G}^{(i)}$ and $\mathcal{G}^{(j)}$ is measured via the cosine similarity,

$$ $s_{ij}=\text{sim}(\mathbf{d}_{i},\mathbf{d}_{j})\,.$ (9) $$

The distributional similarities between graphs from different domains or distributions are shown in Figure 4.. From the figure, we can see that the distributional similarities are typically small, demonstrating the diverse semantics of node features across graphs. Noth that, for Amazon & Amazon-all and YelpChi & YelpChi-all, their distribution similarity is one, which can be attributed to the fact that they are from the same distributions respectively but with different numbers of nodes and structures.

To reduce the semantic gap among graphs for generalist GAD, we propose to calibrate the distributions of all graphs into the same frame with coordinate-wise normalization. The distributional similarity with normalization is illustrated in Figure 4. It is clear that the node attributes share the same distribution after the normalization. In this way, the generalist model can better capture the shared GAD patterns and generalize to different target graphs, as demonstrated in our experimental results.

Figure: Figure 4: (a) Distributional similarity between different graphs without coordinate-wise normalization. (b) Distributional similarity between different graphs with the coordinate-wise normalization.
Refer to caption: x5.png

## Appendix B Details on Pre-training of Neighborhood Aggregation Networks

We pre-train the neighborhood aggregation network $g$ via graph contrastive learning (Zhu et al., ) for subsequent graph prompt learning so that the generic normality and abnormality can be captured in the prompts.

Specifically, given the training graph $\mathcal{G}=(A,X)$, to construct contrastive views for graph contrastive learning, two widely used graph augmentations are employed, i.e., edge removal and attribute masking (Zhu et al., ). The edge removal randomly drops a certain portion of existing edges in $\mathcal{G}$ and the attribute masking randomly masks a fraction of dimensions with zeros in node attributes, i.e.,

$$ $\hat{A}=A\circ R\,,\ \ \ \hat{X}=[\mathbf{x}_{1}\circ\mathbf{m},\ldots,\mathbf {x}_{N}\circ\mathbf{m}]^{T}\,,$ (10) $$

where $R\in\{0,1\}^{N\times N}$ is the edge masking matrix whose entry is drawn from a Bernoulli distribution controlled by the edge removal probability, $\mathbf{m}\in\{0,1\}^{d}$ is the attribute masking vector whose entry is independently drawn from a Bernoulli distribution with the attribute masking ratio, and $\circ$ denotes the Hadamard product.

By applying the graph augmentations to the original graph, the corrupted graph $\hat{\mathcal{G}}=(\hat{A},\hat{X})$ forms the contrastive view for the original graph $\mathcal{G}=(A,X)$. Then, $\hat{\mathcal{G}}$ and $\mathcal{G}$ are fed to the shared model $g$ followed by the non-linear projection to obtain the corresponding node embeddings, i.e., $\hat{Z}^{\prime}$ and $Z^{\prime}$. For graph contrastive learning, the embeddings of the same node in different views are pulled closer while the embeddings of other nodes are pushed apart. The pairwise objective for each node pair $(\hat{\mathbf{z}}^{\prime}_{i},\mathbf{z}^{\prime}_{i})$ can be formulated as:

$$ $\ell(\hat{\mathbf{z}}^{\prime}_{i},\mathbf{z}^{\prime}_{i})=-\log\frac{e^{ \text{sim}(\hat{\mathbf{z}}^{\prime}_{i},\mathbf{z}^{\prime}_{i})/\tau}}{e^{ \text{sim}(\hat{\mathbf{z}}^{\prime}_{i},\mathbf{z}^{\prime}_{i})/\tau}+\sum_{ j\neq i}^{N}e^{\text{sim}(\hat{\mathbf{z}}^{\prime}_{i},\mathbf{z}^{\prime}_{j })/\tau}+\sum_{j\neq i}^{N}e^{\text{sim}(\hat{\mathbf{z}}^{\prime}_{i},\hat{ \mathbf{z}}^{\prime}_{j})/\tau}}\,,$ (11) $$

where $\text{sim}(\cdot)$ represents the cosine similarity and $\tau$ is a temperature hyperparameter. Therefore, the overall objective can be defined as follows:

$$ $\mathcal{L}_{\text{contrast}}=\frac{1}{2N}\sum_{i=1}^{N}(\ell(\hat{\mathbf{z}} ^{\prime}_{i},\mathbf{z}^{\prime}_{i})+\ell(\mathbf{z}^{\prime}_{i},\hat{ \mathbf{z}}^{\prime}_{i}))\,.$ (12) $$

With the objective Eq.(12), the model $g$ is optimized to learn transferable discriminative representations of nodes.

## Appendix C Algorithms

The training and inference processes of UNPrompt are summarized in Algorithms 1 and Algorithm 2, respectively.

Figure: Algorithm 1 Training of UNPrompt

Figure: Algorithm 2 Inference of UNPrompt

## Appendix D Unsupervised GAD with UNPrompt

To demonstrate the wide applicability of the proposed method UNPrompt, we further perform unsupervised GAD with UNPrompt which focuses on detecting anomalous nodes within one graph and does not have access to any node labels during training. Specifically, we adopt the same pipeline in the generalist GAD setting, i.e., graph contrastive pertaining and neighborhood prompt learning. Since we focus on anomaly detection on each graph separately, the node attribute unification is discarded for unsupervised GAD. However, the absence of node labels poses a challenge to learning meaningful neighborhood prompts for anomaly detection. To overcome this issue, we propose to utilize the pseudo-labeling technique to guide the prompt learning. Specifically, the normal score of each node is calculated by the neighborhood-based latent attribute predictability after the graph contrastive learning process:

$$ $s_{i}=\text{sim}(\mathbf{z}_{i},\tilde{\mathbf{z}}_{i})\,,$ (13) $$

where $\mathbf{z}_{i}$ is the node representation learned by graph contrastive learning and $\tilde{\mathbf{z}}_{i}$ is the corresponding aggregated neighborhood representation. Higher $s_{i}$ of node $v_{i}$ typically indicates a higher probability of $v_{i}$ being normal nodes. Therefore, more emphasis should be put on high-score nodes when learning neighborhood prompts. To achieve this, the normal score $s_{i}$ is transformed into the loss weight $w_{i}=\text{Sigmoid}(\alpha(s_{i}-t))$
where $t$ is a threshold and $\alpha$ is the scaling parameter. In this way, $w_{i}$ would approach 1 if $s_{i}>t$ and 0 otherwise. Overall, the objective for unsupervised GAD using UNPrompt can be formulated as follows:

$$ $\mathcal{L}=\sum_{i}^{N}(-w_{i}\text{sim}(\mathbf{z}_{i},\tilde{\mathbf{z}}_{i })+\lambda\sum_{j,j\neq i}^{N}\text{sim}(\mathbf{z}_{i},\tilde{\mathbf{z}}_{j} ))\,,$ (14) $$

where the second term is a regularization term employed to prevent the node embeddings from being collapsed into the same and $\lambda$ is a trade-off hyperparameter.

Note that, we only focus on maximizing the latent attribute predictability of high-score nodes without minimizing the predictability of low-score nodes in the above objective. These low-score nodes could also be normal nodes with high probability as the score from Eq.(13) is only obtained from the pre-trained model, resulting in the score not being fully reliable. If the predictability is also minimized for these nodes, conflicts would be induced for neighborhood prompt learning, limiting the performance of unsupervised GAD. After optimization, the latent attribute predictability is also directly used as the normal score for the final unsupervised GAD.

## Appendix E Time Complexity Analysis

#### Theoretical Analysis.

In this section, we analyze the time complexity of training UNPrompt. As discussed in the main paper, UNPrompt first pre-trains the aggregation network with graph contrastive learning. Then, the model remains frozen when optimizing neighborhood graph prompts and the transformation layer to capture the generalized normal and abnormal graph patterns. In the experimental section, we employ a one-layer aggregation network, denoting the number of hidden units as $d_{h}$. The time complexity of the graph contrastive learning is $\mathcal{O}(4E_{1}(|A|d_{h}+Nd_{h}d^{{}^{\prime}}+6Nd_{h}^{2}))$, where $|A|$ returns of the number of edges of the $\mathcal{G}_{\text{train}}$, $N$ is the number of nodes, $d^{{}^{\prime}}$ represents the predefined dimensionality of node attributes, and $E_{1}$ is the number of training epoch. After that, we freeze the learned model and learn the learnable neighborhood prompt tokens and the transformation layer to capture the shared anomaly patterns. In our experiments, we set the size of each graph prompt to $K$ and implement the classification head as a single-layer MLP with the same hidden units $d_{h}$. Given the number of the training epoch $E_{2}$, the time complexity of optimizing the graph prompt and the transformation layer is $\mathcal{O}((4KNd^{{}^{\prime}}+2Nd_{h}^{2})E_{2})$, which includes both the forward and backward propagation. Note that, despite the neighborhood aggregation model being frozen, the forward and backward propagations of the model are still needed to optimize the task-specific graph prompts and the transformation layer. Therefore, the overall time complexity of UNPrompt is $\mathcal{O}(4E_{1}(|A|d_{h}+Nd_{h}d^{{}^{\prime}}+6Nd_{h}^{2})+2E_{2}(|A|d_{h}
+Nd_{h}d^{{}^{\prime}}+2KNd^{{}^{\prime}}+Nd_{h}^{2}))$, which is linear to the number of nodes, the number of edges, and the number of node attributes of the training graph. Note that, after the training, the learned generalist model is directly utilized to perform anomaly detection on various target graphs without any further training.

**Table 4: Training time and inference time (seconds) for different methods.**
| Methods | AnomalyDAE | TAM | GAT | BWGNN | UNPrompt (Ours) |
| --- | --- | --- | --- | --- | --- |
| Training Time | 86.04 | 479.70 | 2.43 | 4.86 | 2.08 |
| Inference Time | 264.29 | 521.92 | 300.90 | 330.99 | 58.95 |

#### Empirical Computational Complexity Analysis.

In Table 4, we report the training time and inference time of different methods, where two representative unsupervised methods (AnomalyDAE and TAM) and two supervised methods (GAT and BWGNN) are used for comparison to our method UNPrompt. The results show that the proposed method requires much less training and inference time compared to other baselines, demonstrating the efficiency of the proposed UNPrompt. Note that, TAM has the highest time consumption, which can be attributed to that it performs multiple graph truncations and learns multiple local affinity maximization networks.

## Appendix F Experimental Setup

### F.1 Details on Datasets

We conduct the experiments using seven real-world with genuine anomalies in diverse online shopping services and social networks, including Facebook (Xu et al., ), Reddit (Kumar et al., ), Weibo (Zhao et al., ), Amazon (McAuley & Leskovec, ) and YelpChi (Rayana & Akoglu, ) as well as two large-scale graph datasets including Amazon-all (McAuley & Leskovec, ) and YelpChi-all (Rayana & Akoglu, ). The statistical information including the number of nodes, edge, the dimension of the feature, and the anomaly rate of the datasets can be found in Table 5. The more detailed description of each dataset is given as follows

- •
Facebook (Xu et al., ). Facebook is a social network where each node represents a user, and edges signify relationships between users. Ground truth anomalies are nodes that either connect to randomly selected circles or exhibit abnormal attributes, as described in (Ding et al., ; Liu et al., ).
- •
Reddit (Kumar et al., ). Reddit is a forum-based network derived from the social media platform Reddit, where nodes represent users, and the embeddings of post texts serve as attributes. Users who have been banned from the platform are labeled as anomalies.
- •
Weibo (Kumar et al., ). Weibo is a social network and their associated hashtags are obtained from the Tencent Weibo platform. Users who engaged in at least five of these activities are labeled as anomalies while the others are classified as normal samples. Suspicious activities are defined as two posts made within a specific timeframe, such as 60 seconds. The attributes of each node include the location of a micro-blog post and bag-of-words features.
- •
Amazon (McAuley & Leskovec, ). Amazon is a graph dataset that captures the relations between users and product reviews. There are 25 handcrafted features used as the node attribute (Zhang et al., ). The users with more than 80% helpful votes are labeled as normal entities and users with less than 20% helpful votes as anomalies. Amazon is constructed by extracting the Amazon-UPU dataset that connects the users who give reviews to at least one common product.
- •
YelpChi (Rayana & Akoglu, ). YelpChi includes hotel and restaurant reviews filtered (spam) and recommended (legitimate) by Yelp. There are 32 handcrafted features used as node attributes (Rayana & Akoglu, ). The users with more than 80% helpful votes are labeled as benign entities and users with less than 20% helpful votes as fraudulent entities. The YelpChi is constructed by extracting YelpChi-RUR which connects reviews posted by the same user.
- •
Amazon-all (McAuley & Leskovec, ).
Amazon-all includes three types of relations: U-P-U (users reviewing at least one same product), U-S-U (users giving at least one same star rating within one week), and U-V-U (users with top-5% mutual review similarities).
Amazon-all is formed by treating the different relations as a single relation following Chen et al. (); Qiao & Pang ().
- •
YelpChi-all (Rayana & Akoglu, ). Similar to Amazon-all, YelpChi-all includes three types of edges: R-U-R (reviews posted by the same user), R-S-R (reviews for the same product with the same star rating), and R-T-R (reviews for the same product posted in the same month). YelpChi-all is formed by treating the different relations as a single relation following Chen et al. (); Qiao & Pang () .

**Table 5: Key statistics of the real-world GAD datasets with real anomalies.**
| Data set | Type | Nodes | Edges | Attributes | Anomalies(Rate) |
| --- | --- | --- | --- | --- | --- |
| Facebook | Social Networks | 1,081 | 55,104 | 576 | 27(2.49%) |
| Reddit | Social Networks | 10,984 | 168,016 | 64 | 366(3.33%) |
| Weibo | Social Networks | 8,405 | 407,963 | 400 | 868(10.30%) |
| Amazon | Co-review | 10,244 | 175,608 | 25 | 693(6.66%) |
| YelpChi | Co-review | 24,741 | 49,315 | 32 | 1,217(4.91%) |
| Amazon-all | Co-review | 11,944 | 4,398,392 | 25 | 821(6.87%) |
| YelpChi-all | Co-review | 45,941 | 3,846,979 | 32 | 6,674(14.52%) |

### F.2 More Implementation Details

#### Generalist GAD.

For the graph contrastive learning-based pre-training, the probabilities of edge removal and attribute masking are by default set to 0.2 and 0.3 respectively. Besides, the learning rate is set to 0.001 with the Adam optimizer, the training epoch is set to 200 and the temperature $\tau$ is 0.5.

For the neighborhood prompt learning, the learning rate is also set to 0.001 with the Adam optimizer, and the training epoch is set to 900. Note that, since we focus on generalist GAD, we do not perform any hyperparameter search for specific target graphs. Instead, the results of all target graphs are obtained with the same hyperparameter settings.

#### Unsupervised GAD.

Similar to the generalist GAD setting, the hidden units of the neighborhood aggregation network and the transformation layer are set to 128 for all graphs. The threshold $t$ is determined by the 40th percentile of the normal scores obtained by the pre-trained model $g$, and the scaling parameter $\alpha$ is set to 10 for all graphs. Besides, we utilize random search to find the optimal hyperparameters of the size of neighborhood prompts $K$ and the trade-off parameter $\lambda$.

For both generalist and unsupervised GAD, the code is implemented with Pytorch (version: 1.13.1), DGL (version: 1.0.1), OGB (version: 1.3.6), and Python 3.8.19. All experiments are conducted on a Linux server with an Intel CPU (Intel Xeon Gold 6346 3.1GHz) and a Nvidia A40 GPU.

## Peer Reviews

confidence: 4
contribution: 1
initial_rating: 3
presentation: 2
questions: Can the authors clarify the specific differences between the "ZERO-SHOT" methodology presented in this paper and established inductive settings in graph neural networks?
soundness: 2
strengths: 1. The focus on graph anomaly detection is timely and relevant, as it addresses an important area within machine learning and data analysis.

2. The approach of training on one graph and testing on others is interesting.
summary: The paper proposes a method for Graph Anomaly Detection (GAD), which aims to identify nodes in a graph that significantly deviate from normal patterns. The GAD framework is trained on one graph and tested on other graphs, addressing a critical challenge in the detection of anomalies in graph-structured data.
weaknesses: 1-The authors acknowledge in their rebuttal that the reported baseline results are suboptimal, which undermines the overall findings. They justify their choice of dimensionality by claiming it is heuristic: 'For all datasets used in our paper, the minimum dimensionality is 25 for the Amazon dataset. Therefore, any number that is smaller than 25 can be used as the common dimensionality. In our experiments, we chose a relatively medium size, eight, as the common dimensionality.'  However, this explanation is unconvincing, as the choice of eight seems arbitrary and indistinguishable from random.
It is important to note that this hyperparameter has a significant impact on the results (as mentioned in their rebuttal). Furthermore, the authors rely excessively on heuristic-based experimental settings for other baselines, which undermines the credibility of their comparative results.

2- The authors have not thoroughly reviewed the related work, which obscures the clarity of the novelty.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: The authors are expected to answer the questions listed in Weaknesses. Apart from these, I have the following questions:
1. As ARC (Liu et al 2024) is another generalist GAD method, can you further discuss the difference between UNPrompt and ARC? Is that possible to compare them together (even though their settings are slightly different)?
2. The "attribute predictability" looks similar to the "local affinity" in TAM (Qiao and Pang 2023). In this case, will the performance drop significantly if we replace this design with local affinity?
soundness: 3
strengths: 1. The research problem of zero-shot generalist GAD is both challenging and intriguing, offering the potential to inspire further innovation within the GAD research community.
2. The proposed method is thoughtfully designed with a balance of sophistication and simplicity, making it accessible for future researchers to build upon.
3. Extensive experiments conducted across diverse scenarios demonstrate the practical effectiveness and versatility of the proposed approach.
summary: This paper investigates the zero-shot generalist graph anomaly detection (GAD) problem, aiming to train a one-for-all model that works on all potential datasets. A new method termed UNPrompt with several designs (including prompt tuning, attribute predictability, etc.) is provided. Experiments on both generalist and traditional settings are conducted to show the effectiveness of the proposed method.
weaknesses: 1. The experimental details are not given clearly in the paper. Which graph datasets are used to train the model (for pre-training and/or prompt tuning)? 
2. In the experiments, only 4 different datasets are used for evaluation (Amazon-all and YelpChi-all can be regarded as an extended version of the original ones). In this case, the generalized ability of the proposed method can't be fully verified. In this case, more datasets from different domains are expected in the experiments.
3. Why coordinate-wise normalization plays a critical role in the performance of UNPrompt? More explanation is expected.

---

confidence: 4
contribution: 2
initial_rating: 3
presentation: 3
questions: Q1. Can the pre-trained model use a different dataset other than Facebook to train and still get good performance? 

Q2. Can the framework be used for large-scale datasets, like Elliptic[1]? 

Q3. Can UNPrompt still outperform other baselines after they use the Coordinate-wise Normalization technique? 


Reference: 

1. Jianheng Tang, Fengrui Hua, Ziqi Gao, Peilin Zhao, Jia Li. GADBench: Revisiting and Benchmarking Supervised Graph Anomaly Detection. NeurIPS 2023. 
2. Jingyan Chen, Guanghui Zhu, Chunfeng Yuan, Yihua Huang. Boosting Graph Anomaly Detection with Adaptive Message Passing. ICLR 2024.
soundness: 2
strengths: S1. The paper is easy to follow. 

S2. The authors propose a zero-shot generalist GAD approach including two main components, Coordinate-wise Normalization and neighborhood prompt learning. 

S3. Experiments show their framework can outperform baselines on datasets included in this paper.
summary: The authors propose a zero-shot generalist GAD approach, UNPrompt. Specifically, they introduce two components: coordinate-wise normalization to unify node attributes across different graphs, and neighborhood prompt learning, which leverages latent node attribute predictability as an anomaly measure. Experiments show their framework can outperform baselines on datasets included in this paper.
weaknesses: W1. The Coordinate-wise Normalization component is hardly considered as a contribution in this paper. As stated in the paper, the authors simply follow the previous work in the related areas to apply the Coordinate-wise Normalization, so the authors need to explain the differences between their design and framework from others. Otherwise, this component can only be considered as an implementation, not a contribution. 

W2. The Latent Node Attribute Predictability is similar to Local Affinitiy in TAM. This anomalous score function shares a similar form of Local Affinitiy in TAM. Although the authors provide a comparison in Figure 3(b), they need to further explain the result. To be specific, changing the objective function in an unsupervised learning framework but not tuning hyperparameters carefully is hard to lead to optimal results. The authors need to illustrate whether they use the same hyperparameters as Latent Node Attribute Predictability for Local Affinitiy or they fine-tune optimal hyperparameters for Local Affinitiy in the comparison. 
W3. The Neighborhood Prompting Learning follows the previous framework. Graph prompt learning has been utilized in several downstream applications, but the authors still follow the typical design of it. They need to further explain the differences between their design and other graph prompt learning frameworks to show their contributions. Otherwise, this key component can have the same issue as W1. 

W4. The setting of the hyperparameters is not explained well. For example, for the unsupervised setting of UNPrompt, the authors use the "40th percentile of the normal scores" as the threshold to generate pseudo labels. However, the real anomalous rate is far less than this, which leads to many false pseudo-labels in this setting. They need to explain why they chose such a hyperparameter. Besides, they only provide the hyperparameter sensitivity of the number of prompts. It would be better to include the analysis of other hyperparameters. 

W5. The datasets and baselines are not diverse enough. For datasets, the authors only include "social networks" and "co-review", which may share similar structural information. It would be better to include financial networks, like T-Finance[1]. For baselines, the most recent supervised work included in this paper is GHRN and unsupervised work is TAM, but XGBGraph[1] and GADAM[2] are two novel works in this area, separately. In addition, since Coordinate-wise Normalization is a very common design when compared with baselines, it would be better to include such a technique for baseline models.

---

confidence: 4
contribution: 1
initial_rating: 3
presentation: 2
questions: 1. What are the unique challenges of prompt learning in Graph Anomaly Detection (GAD)?
2.  In Formula 2, the mean value will also be large when the difference in features between the two datasets is large. So, how can the two data be projected to the same space?
3. How are potential negative values from Formula 2 handled?
4. Formulas 4 and 5 suggest that the authors only consider graph uniformity or high node connectivity as criteria for determining anomalies. This design seems somewhat superficial, as anomalous nodes may also be related to node attributes.
5. Does Neighborhood Prompting involve learning a prompt for each node's neighbours? If the added prompts alter the neighbour features of *x*, could this affect the detection of anomalies?
soundness: 3
strengths: 1. The experiments are detailed and demonstrate strong performance.
2. The paper is well-organized.
3. The work addresses a novel problem in a new context: zero-shot Graph Anomaly Detection (GAD).
summary: This paper proposes a novel zero-shot generalist Graph Anomaly Detection (GAD) approach called UNPrompt, which aims to train a unified detection model. The approach achieves generalist GAD through two key modules: the first module aligns the dimensionality and semantics of node attributes across different graphs by employing coordinate-wise normalization in a projected space. The second module focuses on learning generalized neighborhood prompts that leverage the predictability of latent node attributes as an anomaly score across various datasets.
weaknesses: 1. The theoretical innovation is insufficient. The concept of Neighborhood Prompting appears to encompass an all-in-one method in [1], and the method of coordinate-wise normalization is not novel. The paper does not sufficiently address the unique challenges associated with applying these methods to GAD.
2. The consideration of graph anomalies is inadequate. The evaluation focuses primarily on graph uniformity or high node connectivity as criteria for determining anomalies, while neglecting the importance of attribute features.
3. The writing needs improvement; the paper contains too many lengthy sentences, making it difficult to read and understand.
4. No code provided

   [1] Sun, Xiangguo, et al. "All in one: Multi-task prompting for graph neural networks." *Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining*. 2023.

Meta-review: This paper aims to solve the one-model-for-one-dataset drawback in graph anomaly detection. It devises a zero-shot generalist method in which one module aligns the dimensionality and semantics of node attributes across different graphs while another module learns generalized neighborhood prompts. The predictability of latent node attributes is used as a generalized anomaly measure, and latent node attribute prediction is used to learn the generalized normal and abnormal graph patterns   in a properly normalized node attribute space. Experimental results demonstrate the effectiveness. 


After rebuttal, three out of four reviewers are still negative about this manuscript, and concern the comparative result credibility and experimental details as well as theoretical innovation.  The experimental setting and related works are also not detailed in the paper. So, more efforts could be needed.

Decision: Reject