Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ dataset/
logs/
models/
embeddings/
gat/dataset copy/
gat/ogbn-cora-submission/
__*
**/submission_ogbn_cora/*
121 changes: 119 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ cp ogbn-cora-submission/master.csv /Users/samdatta/miniconda/envs/gmlpipe/lib/py
**NOTE**: The current version of the code does not aim to reproduce the paper exactly - while we use (inside `adapter.py`, which downloads Cora from DGL and packages it for a submission to OGB) the standard train-val-test split of 140:500:1000, the C&S paper reportedly used a 60:20:20 _random_ split (see Sec. 3).

### Experiments
- `python run_experiments.py --dataset cora --method lp` gives val/test accuracies of 0.698/0.707.
- `python gen_models.py --dataset arxiv --model mlp --use_embeddings` gives val/test accuracies of 76.6600 ± 0.8796/76.9600 ± 1.0384.
- `python run_experiments.py --dataset cora --method lp` gives val/test accuracies of 0.698/0.707. ->D
- `python gen_models.py --dataset arxiv --model mlp --use_embeddings` gives val/test accuracies of 76.6600 ± ->D 0.8796/76.9600 ± 1.0384.

**NOTE** Other models (e.g., GAT+C&S) have not been tested yet. Most likely, those pathways will throw errors (the original code has quite a bit of code-duplication - not all pathways were modified to accept Cora). However, fixing them should be routine.

Expand All @@ -53,11 +53,19 @@ cp ogbn-cora-submission/master.csv /Users/samdatta/miniconda/envs/gmlpipe/lib/py
### Label Propagation (0 params):
```
python run_experiments.py --dataset arxiv --method lp
Valid acc: 0.7018356320681902
Test acc: 0.683496903483324


Valid acc: 0.7013658176448874
Test acc: 0.6832294302820814
```
```
python run_experiments.py --dataset cora --method lp ->DONE

Valid acc: 0.968
Test acc: 0.707
```
### Plain Linear + C&S (5160 params, 52.5% base accuracy)
```
python gen_models.py --dataset arxiv --model plain --epochs 1000
Expand All @@ -67,13 +75,62 @@ Valid acc -> Test acc
Args []: 73.00 ± 0.01 -> 71.26 ± 0.01
```

```
python gen_models.py --dataset cora --model plain --epochs 1000 D
python run_experiments.py --dataset cora --method plain D

All runs:
Highest Train: 100.0000 ± 0.0000
Highest Valid: 51.2600 ± 0.3893
Final Train: 100.0000 ± 0.0000
Final Test: 47.4400 ± 0.5641


Valid acc -> Test acc
Args []: 74.34 ± 0.21 -> 75.17 ± 0.09



_________________________________________________________________________

python run_experiments.py --dataset cora --method plain_gen_bound D

Valid acc -> Test acc
Args []: 71.84 ± 0.67 -> 74.18 ± 0.62

```

### Linear + C&S (15400 params, 70.11% base accuracy)
```
python gen_models.py --dataset arxiv --model linear --use_embeddings --epochs 1000
python run_experiments.py --dataset arxiv --method linear

Valid acc -> Test acc
Args []: 73.68 ± 0.04 -> 72.22 ± 0.02;
```
```
python gen_models.py --dataset cora --model linear --use_embeddings --epochs 1000 D
python run_experiments.py --dataset cora --method linear D



All runs:
Highest Train: 100.0000 ± 0.0000
Highest Valid: 72.9600 ± 0.4695
Final Train: 99.7857 ± 0.3450
Final Test: 71.7000 ± 0.3055

Valid acc -> Test acc
Args []: 75.78 ± 0.06 -> 75.36 ± 0.08

_________________________________________________________________________

python run_experiments.py --dataset cora --method linear_gen_bound D

Valid acc -> Test acc
Args []: 74.18 ± 0.82 -> 75.29 ± 0.40


```

### MLP + C&S (175656 params, 71.44% base accuracy)
Expand All @@ -83,17 +140,77 @@ python run_experiments.py --dataset arxiv --method mlp

Valid acc -> Test acc
Args []: 73.91 ± 0.15 -> 73.12 ± 0.12
```

```
python gen_models.py --dataset cora --model mlp --use_embeddings D
python run_experiments.py --dataset cora --method mlp


All runs:
Highest Train: 100.0000 ± 0.0000
Highest Valid: 76.8800 ± 1.2300
Final Train: 100.0000 ± 0.0000
Final Test: 76.9000 ± 1.0965

Valid acc -> Test acc
Args []: 78.50 ± 1.33 -> 79.10 ± 1.28

_________________________________________________________________________

python run_experiments.py --dataset cora --method mlp_gen_bound D

Valid acc -> Test acc
Args []: 78.50 ± 1.33 -> 79.10 ± 1.28



```

### GAT + C&S (1567000 params, 73.56% base accuracy)
```
cd gat && python gat.py --use-norm
Average epoch time: 21.718203401565553, Test acc: 0.6538896775919182
Runned 10 times
Val Accs: [0.6605255209906372, 0.6424376656934796, 0.6559951676230746, 0.6449880868485519, 0.6551562132957481, 0.6409275479042921, 0.6187120373166884, 0.6712976945535085, 0.6283432329943958, 0.6312292358803987]
Test Accs: [0.667160463345884, 0.6027817212929243, 0.6717075077670103, 0.6384791062280106, 0.6247145237948275, 0.6592597164784066, 0.578585684011275, 0.6555356665226426, 0.6484579141205276, 0.6538896775919182]
Average val accuracy: 0.6449612403100775 ± 0.015290282129320602
Average test accuracy: 0.6400571981153427 ± 0.02830663270099123
[768, 768, 98304, 768, 768, 589824, 120, 120, 92160, 98304, 589824, 92160, 768, 768, 768, 768, 40]
Number of params: 1567000



cd .. && python run_experiments.py --dataset arxiv --method gat
Valid acc -> Test acc
Args []: 67.27 ± 1.39 -> 66.25 ± 2.90


Valid acc -> Test acc
Args []: 74.84 ± 0.07 -> 73.86 ± 0.14
```

```
cd gat && python gat.py --use-norm --dataset cora
cd .. && python run_experiments.py --dataset cora --method gat


Average epoch time: 0.3995665550231934, Test acc: 0.262
Runned 10 times
**************************************************
Average epoch time: 0.39290672254562375, Test acc: 0.791
Runned 10 times
Val Accs: [0.772, 0.77, 0.768, 0.788, 0.78, 0.78, 0.79, 0.746, 0.774, 0.76]
Test Accs: [0.788, 0.775, 0.771, 0.804, 0.794, 0.802, 0.797, 0.772, 0.772, 0.791]
Average val accuracy: 0.7727999999999999 ± 0.012432216214336054
Average test accuracy: 0.7866000000000002 ± 0.012362847568420484
[768, 768, 1100544, 768, 768, 589824, 21, 21, 16128, 1100544, 589824, 16128, 768, 768, 768, 768, 7]
Number of params: 3419185

Valid acc -> Test acc
Args []: 78.18 ± 1.14 -> 80.38 ± 1.15
```

### Notes
As opposed to the paper's results, which only use spectral embeddings, here we use spectral *and* diffusion embeddings, which we find improves Arxiv performance.

Expand Down
65 changes: 64 additions & 1 deletion adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from curses.ascii import isspace
import torch_geometric.transforms as T
from ogb.nodeproppred import PygNodePropPredDataset
from ogb.nodeproppred import PygNodePropPredDataset , DglNodePropPredDataset
from ogb.io import DatasetSaver
import numpy as np
from dgl.data import *
Expand All @@ -11,6 +11,9 @@ def dgl_to_ogbn(dataset_name, mapping_path, is_sparse=False):
dataset = CoraGraphDataset()
dataset_name = 'ogbn-cora'

print("#### cora type initial = ",type(dataset))


saver = DatasetSaver(dataset_name=dataset_name, is_hetero=False, version=1)

g = dataset[0].to_networkx()
Expand All @@ -29,6 +32,16 @@ def dgl_to_ogbn(dataset_name, mapping_path, is_sparse=False):
split_idx['train'] = np.array(g.nodes)[dataset[0].ndata['train_mask']]
split_idx['valid'] = np.array(g.nodes)[dataset[0].ndata['val_mask']]
split_idx['test'] = np.array(g.nodes)[dataset[0].ndata['test_mask']]
# split_idx['train'] = np.load("cora_splits/cora_train_split.npy")
# split_idx['valid'] = np.load("cora_splits/cora_validate_split.npy")
# split_idx['test'] = np.load("cora_splits/cora_test_split.npy")

print("train len = ",len(split_idx['train']))

print("valid len = ",len(split_idx['valid']))
print("test len = ",len(split_idx['test']))
print("train type = ",type(split_idx['train']))
print("train = ",split_idx['train'])
saver.save_split(split_idx, split_name='std')

saver.copy_mapping_dir(mapping_path)
Expand All @@ -46,3 +59,53 @@ def dgl_to_ogbn(dataset_name, mapping_path, is_sparse=False):
saver.zip()

return pyg_dataset


def dgl_to_dgl_ogbn(dataset_name, mapping_path, is_sparse=False):
if 'cora' == dataset_name:
dataset = CoraGraphDataset()
dataset_name = 'ogbn-cora'
print("#### cora type initial = ",type(dataset))
saver = DatasetSaver(dataset_name=dataset_name, is_hetero=False, version=1)


print("dataset[0] = ",type(dataset[0]))
print("dataset[0] = ",dataset[0])

g = dataset[0].to_networkx()
print("cora g = ",g)
graph = dict()
graph['edge_index'] = np.array(
[(u, v) for (u, v, w) in g.edges]).transpose()
num_nodes = len(g.nodes)
graph['num_nodes'] = num_nodes
graph['node_feat'] = np.array(dataset[0].ndata['feat'])
saver.save_graph_list([graph])

saver.save_target_labels(
np.array(dataset[0].ndata['label']).reshape((num_nodes, 1)))

split_idx = dict()
split_idx['train'] = np.array(g.nodes)[dataset[0].ndata['train_mask']]
split_idx['valid'] = np.array(g.nodes)[dataset[0].ndata['val_mask']]
split_idx['test'] = np.array(g.nodes)[dataset[0].ndata['test_mask']]
print("train len = ",len(split_idx['train']))
print("valid len = ",len(split_idx['valid']))
print("test len = ",len(split_idx['test']))
saver.save_split(split_idx, split_name='std')

saver.copy_mapping_dir(mapping_path)

saver.save_task_info(task_type='classification',
eval_metric='acc', num_classes=dataset.num_classes)
meta_dict = saver.get_meta_dict()

if is_sparse:
pyg_dataset = DglNodePropPredDataset(
dataset_name, meta_dict=meta_dict, transform=T.ToSparseTensor())
else:
pyg_dataset = DglNodePropPredDataset(dataset_name, meta_dict=meta_dict)

saver.zip()

return pyg_dataset
Binary file added coraCSbounds-2.pkl
Binary file not shown.
Binary file added coraCSbounds.pkl
Binary file not shown.
Binary file added cora_splits/cora_test_split.npy
Binary file not shown.
Binary file added cora_splits/cora_train_split.npy
Binary file not shown.
Binary file added cora_splits/cora_validate_split.npy
Binary file not shown.
52 changes: 52 additions & 0 deletions cora_splits/new_added_train_idx.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
0
22
131
23
627
5
725
4
1984
924
68
478
0
2081
643
2
6
187
860
1174
66
947
1429
1422
491
902
1335
1321
8
2036
1453
1322
1
2105
51
1480
2411
1975
1602
2022
2104
1309
1486
1331
1648
1601
1937
1820
1848
2066
1940
1957
Loading