Skip to content
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

Pulling examples of baselines #42

Merged
merged 8 commits into from
Jun 13, 2023
Merged
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
7 changes: 5 additions & 2 deletions examples/linkproppred/amazonreview/dyrep_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -306,6 +307,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -334,7 +336,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
9 changes: 6 additions & 3 deletions examples/linkproppred/amazonreview/tgn_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()


val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -294,6 +295,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -322,7 +324,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
7 changes: 5 additions & 2 deletions examples/linkproppred/opensky/dyrep_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -306,6 +307,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -334,7 +336,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
7 changes: 5 additions & 2 deletions examples/linkproppred/opensky/tgn_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -294,6 +295,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -322,7 +324,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
7 changes: 5 additions & 2 deletions examples/linkproppred/redditcomments/dyrep_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -306,6 +307,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -334,7 +336,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
7 changes: 5 additions & 2 deletions examples/linkproppred/redditcomments/tgn_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -294,6 +295,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -322,7 +324,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
8 changes: 5 additions & 3 deletions examples/linkproppred/stablecoin/dyrep_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import torch
from sklearn.metrics import average_precision_score, roc_auc_score
from torch.nn import Linear
from torch_geometric.datasets import JODIEDataset
from torch_geometric.loader import TemporalDataLoader
from torch_geometric.nn import TransformerConv

Expand Down Expand Up @@ -284,14 +283,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -306,6 +306,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -334,7 +335,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
7 changes: 5 additions & 2 deletions examples/linkproppred/stablecoin/tgn_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -294,6 +295,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -322,7 +324,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
6 changes: 4 additions & 2 deletions examples/linkproppred/wikipedia/dyrep_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand Down Expand Up @@ -334,7 +335,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
7 changes: 5 additions & 2 deletions examples/linkproppred/wikipedia/tgn_early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ def test_one_vs_many(loader, neg_sampler, split_mode):

# define an early stopper
save_model_dir = f'{osp.dirname(osp.abspath(__file__))}/saved_models/'
save_model_id = f'{MODEL_NAME}_{DATA}_{run_idx}'
save_model_id = f'{MODEL_NAME}_{DATA}_{SEED}_{run_idx}'
early_stopper = EarlyStopMonitor(save_model_dir=save_model_dir, save_model_id=save_model_id,
tolerance=TOLERANCE, patience=PATIENCE)

# ==================================================== Train & Validation
# loading the validation negative samples
dataset.load_val_ns()

val_perf_list = []
start_train_val = timeit.default_timer()
for epoch in range(1, NUM_EPOCH + 1):
# training
Expand All @@ -293,6 +294,7 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
perf_metric_val = test_one_vs_many(val_loader, neg_sampler, split_mode="val")
print(f"\tValidation {metric}: {perf_metric_val: .4f}")
print(f"\tValidation: Elapsed time (s): {timeit.default_timer() - start_val: .4f}")
val_perf_list.append(perf_metric_val)

# check for early stopping
if early_stopper.step_check(perf_metric_val, model):
Expand Down Expand Up @@ -321,7 +323,8 @@ def test_one_vs_many(loader, neg_sampler, split_mode):
'data': DATA,
'run': run_idx,
'seed': SEED,
metric: perf_metric_test,
f'val {metric}': val_perf_list,
f'test {metric}': perf_metric_test,
'test_time': test_time,
'tot_train_val_time': train_val_time
},
Expand Down
File renamed without changes.
Loading