-
Notifications
You must be signed in to change notification settings - Fork 100
EdgePrompt #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
EdgePrompt #247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # EdgePrompt / EdgePrompt+ | ||
|
|
||
| - Paper link: [https://arxiv.org/abs/2503.00750](https://arxiv.org/abs/2503.00750) | ||
| - Author's code repo: [https://github.com/xbfu/EdgePrompt](https://github.com/xbfu/EdgePrompt) | ||
|
|
||
| ## Dataset Statics | ||
|
|
||
| | Dataset | # Nodes | # Edges | # Classes | | ||
| |----------|---------|---------|-----------| | ||
| | Cora | 2,708 | 10,556 | 7 | | ||
| | Citeseer | 3,327 | 9,228 | 6 | | ||
| | PubMed | 19,717 | 88,651 | 3 | | ||
|
|
||
| Refer to [Planetoid](https://gammagl.readthedocs.io/en/latest/api/gammagl.datasets.html#gammagl.datasets.Planetoid). | ||
|
|
||
| ### Optional pretraining | ||
|
|
||
| ```bash | ||
| cd examples/edgeprompt | ||
| TL_BACKEND=torch python node_edgeprompt_pretrain.py --dataset Cora --epochs 100 --seed 0 | ||
| ``` | ||
|
|
||
| ### Downstream EdgePrompt | ||
|
|
||
| ```bash | ||
| cd examples/edgeprompt | ||
| TL_BACKEND=torch python node_edgeprompt_finetune.py --dataset Cora --method edgeprompt --num_shots 5 --pretrained_path ./cora_ep_gppt_backbone.npz --epochs 100 --seed 0 | ||
| ``` | ||
|
|
||
| ### Downstream EdgePrompt+ | ||
|
|
||
| ```bash | ||
| cd examples/edgeprompt | ||
| TL_BACKEND=torch python node_edgeprompt_finetune.py --dataset Cora --method edgeprompt_plus --num_shots 5 --pretrained_path ./cora_ep_gppt_backbone.npz --epochs 100 --seed 0 | ||
| ``` | ||
|
|
||
| ## Results | ||
|
|
||
| | Dataset | Method | Paper | Our(Torch) | | ||
| |----------|--------------|-------|------------| | ||
| | Cora | EdgePrompt | 37.26 | 73.20 | | ||
| | Cora | EdgePrompt+ | 56.41 | 73.94 | | ||
| | CiteSeer | EdgePrompt | 29.83 | 46.77 | | ||
| | CiteSeer | EdgePrompt+ | 43.49 | 47.37 | | ||
| | PubMed | EdgePrompt | 47.20 | 51.05 | | ||
| | PubMed | EdgePrompt+ | 61.51 | 55.62 | | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # EdgePrompt example package. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,185 @@ | ||||||
| import argparse | ||||||
| import os | ||||||
| import random | ||||||
|
|
||||||
| os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" | ||||||
|
|
||||||
| import numpy as np | ||||||
| import tensorlayerx as tlx | ||||||
| from gammagl.datasets import Planetoid | ||||||
| from gammagl.loader import DataLoader | ||||||
| from gammagl.models import EdgePromptGCNModel, EdgePromptNodeClassifier | ||||||
| from gammagl.utils import get_few_shot_split, node_subgraph | ||||||
| from tensorlayerx.model import TrainOneStep, WithLoss | ||||||
|
|
||||||
|
|
||||||
| HIDDEN_DIM = 128 | ||||||
| NUM_LAYERS = 2 | ||||||
| DROP_RATE = 0.5 | ||||||
| NUM_ANCHORS = 10 | ||||||
| BATCH_SIZE = 32 | ||||||
| LR = 0.001 | ||||||
| WEIGHT_DECAY = 0.0 | ||||||
| NUM_HOPS = 2 | ||||||
| TEST_RATIO = 0.2 | ||||||
| DATA_ROOT = "Planetoid" | ||||||
|
|
||||||
|
|
||||||
| def set_random_seed(seed): | ||||||
| random.seed(seed) | ||||||
| np.random.seed(seed) | ||||||
| tlx.set_seed(seed) | ||||||
|
|
||||||
|
|
||||||
| class NodeClsLoss(WithLoss): | ||||||
| def __init__(self, net, loss_fn): | ||||||
| super().__init__(backbone=net, loss_fn=loss_fn) | ||||||
|
|
||||||
| def forward(self, data, y): | ||||||
| del y | ||||||
| logits = forward_subgraph_batch(self.backbone_network, data) | ||||||
| return self._loss_fn(logits, tlx.reshape(data.y, (-1,))) | ||||||
|
|
||||||
|
|
||||||
| def forward_subgraph_batch(model, graph_batch): | ||||||
| graph_emb = model.backbone( | ||||||
| graph_batch, | ||||||
| prompt_type=model.prompt_type, | ||||||
| prompt=model.prompt, | ||||||
| pooling="mean", | ||||||
|
||||||
| pooling="mean", | |
| pooling="target", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: “Dataset Statics” should be “Dataset Statistics”.