Adapting to the Unknown: AI Learns to Spot Anomalies in Any Graph

Author: Denis Avetisyan


A new framework uses the power of large language models to create adaptable anomaly detection systems that generalize across diverse and unseen graph datasets.

EvoFG’s performance is demonstrably sensitive to variations in its soft routing frequency, as evidenced by heatmaps detailing the impact of ablating specific components.
EvoFG’s performance is demonstrably sensitive to variations in its soft routing frequency, as evidenced by heatmaps detailing the impact of ablating specific components.

EvoFG leverages router feature engineering and mixture-of-experts to achieve zero-shot graph anomaly detection with enhanced generalization capabilities.

Despite advances in graph anomaly detection, existing methods struggle to generalize across diverse and unseen graph structures and anomaly types. This limitation motivates the development of ‘Evolutionary Router Feature Generation for Zero-Shot Graph Anomaly Detection with Mixture-of-Experts’, which introduces EvoFG, a novel framework leveraging large language models to evolve informative routing features for a mixture-of-experts model. By enhancing the router’s ability to discern relevant node semantics and capture domain-invariant patterns, EvoFG demonstrably improves zero-shot performance on graph anomaly detection tasks. Could this approach unlock truly generalizable graph anomaly detection capabilities, moving beyond the limitations of domain-specific training?


The Challenge of Generalizable Anomaly Detection

Conventional Graph Anomaly Detection (GAD) systems frequently falter when applied to graphs differing significantly from those used during training, hindering their practical deployment. These models often become overly specialized, learning to identify anomalies specific to a particular graph’s topology and feature distributions rather than the underlying principles of anomalous behavior. This limitation arises because many GAD techniques treat each graph as a unique entity, failing to extract and utilize transferable representations of graph structure and node relationships. Consequently, a model proficient at detecting fraudulent transactions within one social network might perform poorly when analyzing malicious activity in a different network with a distinct connection pattern or user base, necessitating costly and time-consuming retraining for each new graph domain.

The limitations of current graph anomaly detection (GAD) models often arise not from fundamental flaws in their algorithms, but from an excessive dependence on characteristics unique to the training dataset. These models frequently prioritize superficial patterns-specific node degrees, edge weights, or localized motifs-rather than the more fundamental, transferable properties that define a graph’s overall structure and behavior. Consequently, when confronted with a graph exhibiting even slight variations in topology or feature distribution, performance degrades significantly. This reliance on dataset-specific features hinders the model’s ability to abstract underlying graph principles, like community structure or network resilience, which are crucial for identifying anomalies across diverse domains. A truly generalizable GAD system must therefore move beyond memorizing training data and instead learn to recognize anomalous behavior based on deviations from these inherent, transferable graph properties.

A significant hurdle in graph anomaly detection lies in the development of models that can readily transfer to new, unseen graph structures. Current methodologies frequently demand substantial retraining when confronted with variations in graph topology or node characteristics, hindering their practical deployment in dynamic real-world scenarios. The ideal solution involves a paradigm shift towards models capable of extracting and leveraging fundamental graph properties – such as connectivity patterns and node roles – rather than memorizing dataset-specific quirks. This would allow for a generalized understanding of anomalous behavior, facilitating robust performance across diverse graph domains without the computational expense and data requirements of continuous retraining. Ultimately, the ability to adapt without extensive recalibration represents a critical step towards scalable and reliable anomaly detection in complex network systems.

Many contemporary graph anomaly detection methods treat graph structure as a secondary consideration, prioritizing node features or relying on simplistic centrality measures for anomaly scoring. This represents a significant limitation, as the intricate relationships between nodes often provide the most telling indicators of unusual behavior. Robust and transferable anomaly detection necessitates a deeper engagement with the graph’s topology – not just identifying isolated nodes, but understanding how patterns of connectivity deviate from expected norms. Approaches that fail to fully exploit this structural information often produce scores sensitive to specific graph instances, hindering their ability to generalize to new, unseen networks and ultimately limiting their practical utility in dynamic real-world scenarios.

Hyper-parameter analysis reveals optimal settings for robust feature generation.
Hyper-parameter analysis reveals optimal settings for robust feature generation.

EvoFG: A Mixture-of-Experts for Zero-Shot GAD

EvoFG utilizes a Mixture-of-Experts (MoE) framework to enhance graph anomaly detection (GAD) performance. This approach involves training multiple specialized Graph Neural Networks (GNNs), termed “Experts,” each designed to capture specific patterns or characteristics within graph data. Instead of a single, monolithic GNN, EvoFG leverages the collective intelligence of these Experts. During inference, an input graph is processed by a subset of these Experts, allowing the model to adapt to varying graph structures and feature distributions. The MoE architecture facilitates both specialization – enabling individual Experts to excel at identifying particular anomaly types – and generalization, as the combined output benefits from the diverse perspectives of multiple models. This contrasts with traditional GNNs, which may struggle with heterogeneous graphs or unseen anomaly patterns.

The Memory-Enhanced Router within EvoFG functions by assigning input graphs to GNN experts based on learned routing weights. These weights are determined through a gating network that considers both the input graph’s features and a memory module capturing the performance history of each expert. Specifically, the router utilizes a key-value memory bank to store representations of previously processed graphs and their corresponding expert assignments. During inference, the router computes a similarity score between the input graph and the keys in the memory bank, using this to modulate the gating network’s output and refine the assignment of input graphs to the most suitable GNN expert, thereby optimizing performance on unseen graph data.

EvoFG’s architecture is designed to accommodate variations in graph structure and feature distributions commonly observed across different datasets. The Mixture-of-Experts framework, combined with the Memory-Enhanced Router, enables the model to learn specialized representations for diverse graph characteristics, such as varying node degrees, edge densities, and feature types. This specialization allows EvoFG to effectively identify anomalous patterns that may manifest differently in each domain. By dynamically assigning inputs to the most relevant GNN expert, the model avoids a one-size-fits-all approach and improves its ability to generalize to unseen graphs without requiring domain-specific training or fine-tuning, thus addressing the challenges of zero-shot graph anomaly detection.

EvoFG’s Mixture-of-Experts (MoE) architecture facilitates both specialization and generalization in zero-shot Graph Anomaly Detection (GAD). The framework comprises multiple Graph Neural Network (GNN) experts, each trained to recognize specific anomaly patterns or graph characteristics. This specialization allows EvoFG to capture nuanced anomalies that a single, monolithic model might miss. Simultaneously, the routing mechanism, which dynamically assigns inputs to the most relevant expert, prevents overfitting to specific datasets and enables effective performance on unseen graphs, thus promoting generalization capability crucial for zero-shot learning scenarios. The balance between these two aspects allows EvoFG to adapt to diverse graph structures and anomaly types without requiring prior training on target domains.

EvoFG employs an iterative training pipeline, detailed below, to evolve functional graphs for enhanced performance.
EvoFG employs an iterative training pipeline, detailed below, to evolve functional graphs for enhanced performance.

Unveiling Anomalies: LLMs and Feature Engineering

EvoFG utilizes Large Language Models (LLMs) to generate novel features for graph routing. This process moves beyond reliance on manually designed features by employing LLMs to analyze node and edge attributes, as well as structural graph properties, and synthesize new feature representations. These LLM-generated features are designed to capture complex relationships within the graph that may not be readily apparent through traditional feature engineering. The resulting features are then incorporated into the routing process, allowing EvoFG to potentially identify more effective routing paths and improve overall performance by leveraging the LLM’s ability to understand and represent contextual information.

EvoFG employs Shapley Value Estimation to determine the contribution of each router feature to the overall performance of the expert selection process. Shapley Values, originating from cooperative game theory, provide a theoretically sound method for fairly distributing credit among features, accounting for all possible feature subsets. This approach quantifies the marginal contribution of each feature, allowing EvoFG to rank features by their impact on expert selection accuracy and subsequently prioritize the most informative features. By utilizing Shapley Values, EvoFG moves beyond simple feature importance metrics and gains a more nuanced understanding of feature interactions, enabling a more robust and effective feature selection process.

EvoFG’s departure from reliance on hand-engineered features enables the discovery of more generalized patterns within graph data. Traditional feature engineering requires substantial domain expertise and is often specific to the dataset at hand, limiting adaptability. By automatically generating features, EvoFG identifies relationships and characteristics that may not be immediately apparent to human analysts. This automated process yields features that demonstrate increased robustness across different datasets and graph structures, improving the model’s ability to generalize to unseen data and maintain performance in varying conditions. The resulting features are therefore more transferable, reducing the need for extensive retraining or feature re-engineering when applying EvoFG to new problem instances.

EvoFG utilizes Large Language Models (LLMs) to enhance feature representation by processing contextual information inherent in graph structures. Specifically, node and edge attributes, as well as relationships between nodes, are encoded as input to the LLM. The LLM then generates feature embeddings that capture these contextual dependencies, going beyond simple attribute values. These LLM-generated features are subsequently incorporated into the router feature set, enabling EvoFG to better discern complex patterns and relationships within the graph data and improve the accuracy of expert selection. This contextual awareness is particularly beneficial in scenarios where the meaning of a node or edge is dependent on its surrounding graph environment.

The invariant learning coefficient λ in EvoFG (Full) demonstrates consistent performance across diverse datasets.
The invariant learning coefficient λ in EvoFG (Full) demonstrates consistent performance across diverse datasets.

Robustness Through Invariance: A Foundation for Generalization

EvoFG addresses the challenge of generalization in graph anomaly detection by employing Invariant Learning, a technique designed to cultivate stable patterns within the routing mechanism. This approach actively minimizes variance in the router’s behavior as it encounters diverse graph environments – differing in structure, feature distributions, and anomaly characteristics. By focusing on identifying consistently relevant features, the model learns to make robust decisions independent of superficial graph-specific details. Consequently, the router isn’t simply memorizing patterns from training data but is instead extracting fundamental, transferable knowledge about anomalous behavior, leading to improved performance and reliability when applied to previously unseen graphs and datasets. This emphasis on stability ensures the framework’s adaptability and broad applicability across varied real-world scenarios.

A central strength of this approach lies in its ability to maintain a consistent and reliable decision-making process within the router, even when presented with entirely new and previously unseen data. By focusing on invariant learning, the framework encourages the development of stable patterns that are not overly sensitive to specific characteristics of the training environment. This robustness is achieved by minimizing variance in the router’s behavior across different graph structures, effectively allowing it to generalize beyond the limitations of its initial training. Consequently, the resulting model demonstrates enhanced adaptability and performance when applied to novel scenarios, offering a significant advantage in dynamic and unpredictable real-world applications where consistent and trustworthy operation is paramount.

Rigorous cross-dataset evaluation confirms EvoFG’s remarkable zero-shot generalization ability, showcasing its capacity to perform effectively on previously unseen graph structures without requiring retraining. This assessment involved subjecting the framework to diverse datasets, revealing consistently superior performance when contrasted with existing baseline models. Notably, EvoFG achieved an Area Under the Receiver Operating Characteristic curve (AUROC) of up to 92% on the BlogCatalog dataset, demonstrating a heightened capacity to distinguish between normal and anomalous nodes-a critical metric for effective graph anomaly detection. The results suggest that EvoFG’s inherent adaptability and robust learning mechanisms enable it to transcend dataset-specific biases and maintain high accuracy in novel environments.

The developed framework demonstrably improves anomaly detection performance, achieving an Area Under the Precision-Recall Curve (AUPRC) of up to 90% when tested across diverse datasets. This heightened accuracy isn’t solely a matter of statistical improvement; it translates to broader applicability of Graph Anomaly Detection (GAD) techniques to previously challenging real-world problems. Crucially, visualization through heatmap analysis reveals a dynamic expert selection process within the routing mechanism, actively preventing ‘expert collapse’ – a common failure mode in such systems where reliance on a single, potentially flawed, expert dominates decision-making. This adaptability ensures the framework remains robust and reliable even as data characteristics shift, paving the way for its deployment in complex and evolving environments.

The number of environments exhibiting invariant learning in EvoFG (Full) varies depending on the dataset used.
The number of environments exhibiting invariant learning in EvoFG (Full) varies depending on the dataset used.

The pursuit of generalizable anomaly detection, as demonstrated by EvoFG, echoes a fundamental principle of efficient design. It strives for minimal complexity in achieving maximal utility. This aligns with the observation of John von Neumann: “It is impossible to be precise about anything.” The framework doesn’t attempt exhaustive coverage of every conceivable anomaly, but instead focuses on generating robust router features via large language models – a parsimonious approach to feature engineering. By leveraging a mixture-of-experts, EvoFG effectively compartmentalizes complexity, allowing for adaptation across diverse graph domains without succumbing to overfitting. The elegance lies not in comprehensive modeling, but in strategic reduction.

What Remains to be Seen

The pursuit of a generalist graph anomaly detection system, as exemplified by EvoFG, inevitably exposes the fragility of ‘generalization’ itself. The framework rightly shifts focus to feature engineering via large language models, but this introduces a dependency-a delegation of problem-solving to a black box. The true test lies not in achieving zero-shot performance on existing benchmarks, but in graceful failure. A robust system will not merely detect anomalies, but will signal its own uncertainty, acknowledging the limits of its knowledge when faced with genuinely novel graph structures.

Future work should prioritize disentangling spurious correlations exploited by the language model. Current approaches treat the LLM as an oracle; a more rigorous examination of why certain router features prove effective-and, crucially, when they fail-is essential. The elegance of EvoFG risks being obscured by the complexity of the LLM itself. The ultimate simplification may not lie in adding more layers, but in distilling the LLM’s knowledge into a more interpretable, and therefore trustworthy, signal.

The question persists: can a machine truly ‘understand’ anomaly, or merely recognize deviation from a learned norm? The pursuit of zero-shot learning is, at its core, a search for invariant principles. However, the universe favors variation. A truly generalist system will not seek to eliminate surprise, but to embrace it as a fundamental property of complex systems.


Original article: https://arxiv.org/pdf/2602.11622.pdf

Contact the author: https://www.linkedin.com/in/avetisyan/

See also:

2026-02-14 22:56