TL;DR
Graph In-Context Learning (GICL) allows graph neural networks to adapt to new tasks without fine-tuning, but current methods rely on randomly selected, noisy prompts. This paper introduces GraphPrompter, a multi-stage framework that optimizes how graph prompts are generated, selected, and augmented dynamically. By filtering noise and retrieving the most relevant examples, GraphPrompter boosts state-of-the-art GICL performance by an average of 8%, especially in complex, multi-class scenarios.
What Problem Does This Paper Address?
Large Language Models (LLMs) are famous for their In-Context Learning (ICL) abilities—give them a few examples in a prompt, and they can solve a new task without updating their weights. Researchers are actively trying to bring this paradigm to Graph Neural Networks (GNNs) so a single pre-trained model can handle diverse downstream tasks (like node or edge classification) using "graph prompts."
However, existing GICL frameworks (like Prodigy) build these prompts by randomly sampling subgraphs and randomly selecting which examples to show the model. This causes two major issues:
- Noise: Random subgraphs contain task-irrelevant nodes and edges that confuse the model.
- Domain Gap: If the downstream test graph has vastly more classes (e.g., 40-way classification) than the pre-training graph (e.g., 15 classes), the model's ability to generalize plummets because the random prompts aren't informative enough to bridge the gap.
Methods
GraphPrompter replaces the random baseline with a multi-stage, adaptive optimization pipeline consisting of three core modules:
- Prompt Generator (Generation): Instead of just using raw random walks to build a subgraph around a target node, this module uses a learnable reconstruction layer. It calculates weights for every edge, effectively filtering out irrelevant topological noise and highlighting the most informative connections before passing the subgraph to the GNN.
- Prompt Selector (Selection): To choose which examples to use as prompts for a specific query, GraphPrompter combines offline and online signals. It uses a pre-trained selection layer to score the general importance of a prompt, and combines it with a $k$-Nearest Neighbors (kNN) search at inference time to find prompts that are semantically similar to the specific query.
- Prompt Augmenter (Augmentation): To handle downstream tasks with many unseen classes, the authors introduce a test-time adaptation trick. They maintain a cache of high-confidence test predictions (pseudo-labels) using a Least Frequently Used (LFU) replacement strategy. These cached test samples are injected back into the prompt pool, dynamically expanding the model's knowledge base on the fly without gradient updates.
Datasets
The authors evaluate their model on large-scale benchmark datasets, specifically focusing on cross-domain setups (training on one graph, testing on a completely different one):
- Pre-training: MAG240M (a massive citation network with >200M nodes) and Wiki (a Wikipedia-derived knowledge graph).
- Downstream Evaluation: arXiv (node classification), ConceptNet, FB15K-237, and NELL (edge/relation classification).
Key Insights and Ideas
- Quality over Quantity in Graph Prompts: Just as the choice of few-shot examples matters immensely in NLP, it is critical in graphs. Random sampling leaves significant performance on the table; adaptive selection is required to unlock true GICL.
- Test-Time Caching Bridges the Domain Gap: The Prompt Augmenter is a clever workaround for the "too many new classes" problem. By caching high-confidence predictions and reusing them as prompts, the model essentially learns the new distribution on the fly. It proves that non-parametric memory can substitute for fine-tuning in low-resource graph tasks.
- Synergy of Offline and Online Selection: Relying solely on pre-trained selection layers fails on out-of-distribution graphs, while relying solely on kNN ignores the global importance of certain nodes. Combining them yields a highly robust selection mechanism.
Key Results
- Overall Performance: GraphPrompter surpasses state-of-the-art baselines (Prodigy, OFA, ProG) by an average of 8% across all settings.
- Massive Gains in Specific Tasks: On the arXiv dataset, it beat the best baseline (Prodigy) by up to 54.43% in certain multi-way settings. On Knowledge Graphs, it raised Prodigy's score from 68.4% to 81.82%.
- Multi-class Robustness: When scaling up to 50-way classification on FB15K-237, GraphPrompter achieved 62.7% accuracy compared to Prodigy's 55.3%, proving the effectiveness of the Prompt Augmenter.
- Trade-offs: The kNN and caching mechanisms do add inference time (e.g., increasing per-query time from 106ms to 280ms on a 40-way task), but the authors demonstrate that this computational cost is manageable and well worth the performance boost.
Limitations and Future Work
- Multi-hop Reasoning: The authors note that as the subgraph size (hop count) increases, performance degrades. This is a known limitation of standard GNNs, which struggle to capture long-range dependencies without over-smoothing.
- Inference Overhead: The retrieval and caching mechanisms increase inference time by a factor of 2 to 3 compared to random selection.
- Future Work: The authors suggest exploring alternative clustering methods for dynamic prompt selection (to replace or optimize the kNN step) and experimenting with different caching solutions beyond LFU to further streamline the Prompt Augmenter.
Summary updated