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

fixing issues in node prop pred task #52

Merged
merged 4 commits into from
Aug 6, 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
14 changes: 7 additions & 7 deletions examples/nodeproppred/tgbn-genre/dyrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def train():

total_loss = 0
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0
for batch in train_loader:
batch = batch.to(device)
Expand Down Expand Up @@ -118,7 +118,7 @@ def train():
result_dict = evaluator.eval(input_dict)
score = result_dict[metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

loss.backward()
optimizer.step()
Expand All @@ -129,9 +129,9 @@ def train():
model['memory'].detach()

metric_dict = {
"ce": total_loss / num_labels,
"ce": total_loss / num_label_ts,
}
metric_dict[metric] = total_score / num_labels
metric_dict[metric] = total_score / num_label_ts
return metric_dict


Expand All @@ -143,7 +143,7 @@ def test(loader):

total_score = 0
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0

for batch in tqdm(loader):
batch = batch.to(device)
Expand Down Expand Up @@ -211,12 +211,12 @@ def test(loader):
result_dict = evaluator.eval(input_dict)
score = result_dict[metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

process_edges(src, dst, t, msg)

metric_dict = {}
metric_dict[metric] = total_score / num_labels
metric_dict[metric] = total_score / num_label_ts
return metric_dict

# ==========
Expand Down
6 changes: 3 additions & 3 deletions examples/nodeproppred/tgbn-genre/moving_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def test_n_upate(loader):
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0

for batch in loader:
Expand Down Expand Up @@ -82,10 +82,10 @@ def test_n_upate(loader):
score = result_dict[eval_metric]

total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

metric_dict = {}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand Down
11 changes: 8 additions & 3 deletions examples/nodeproppred/tgbn-genre/persistant_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
from torch_geometric.loader import TemporalDataLoader
from tqdm import tqdm
import torch

# local imports
from tgb.nodeproppred.dataset_pyg import PyGNodePropPredDataset
Expand All @@ -21,6 +22,10 @@
data = dataset.get_TemporalData()
data = data.to(device)

all_nodes = torch.cat((data.src, data.dst), 0)
all_nodes = all_nodes.unique()
print (all_nodes.shape[0])

eval_metric = dataset.eval_metric
forecaster = PersistantForecaster(num_classes)
evaluator = Evaluator(name=name)
Expand All @@ -46,7 +51,7 @@

def test_n_upate(loader):
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0

for batch in tqdm(loader):
Expand Down Expand Up @@ -87,10 +92,10 @@ def test_n_upate(loader):
result_dict = evaluator.eval(input_dict)
score = result_dict[eval_metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

metric_dict = {}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand Down
14 changes: 7 additions & 7 deletions examples/nodeproppred/tgbn-genre/tgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def train():
total_loss = 0
label_t = dataset.get_label_time() # check when does the first label start
total_score = 0
num_labels = 0
num_label_ts = 0

for batch in tqdm(train_loader):
batch = batch.to(device)
Expand Down Expand Up @@ -194,7 +194,7 @@ def train():
result_dict = evaluator.eval(input_dict)
score = result_dict[eval_metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

loss.backward()
optimizer.step()
Expand All @@ -205,9 +205,9 @@ def train():
memory.detach()

metric_dict = {
"ce": total_loss / num_labels,
"ce": total_loss / num_label_ts,
}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand All @@ -218,7 +218,7 @@ def test(loader):
node_pred.eval()

label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0

for batch in tqdm(loader):
Expand Down Expand Up @@ -287,12 +287,12 @@ def test(loader):
result_dict = evaluator.eval(input_dict)
score = result_dict[eval_metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

process_edges(src, dst, t, msg)

metric_dict = {}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand Down
14 changes: 7 additions & 7 deletions examples/nodeproppred/tgbn-reddit/dyrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def train():

total_loss = 0
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0
for batch in train_loader:
batch = batch.to(device)
Expand Down Expand Up @@ -120,7 +120,7 @@ def train():
result_dict = evaluator.eval(input_dict)
score = result_dict[metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

loss.backward()
optimizer.step()
Expand All @@ -131,9 +131,9 @@ def train():
model['memory'].detach()

metric_dict = {
"ce": total_loss / num_labels,
"ce": total_loss / num_label_ts,
}
metric_dict[metric] = total_score / num_labels
metric_dict[metric] = total_score / num_label_ts
return metric_dict


Expand All @@ -145,7 +145,7 @@ def test(loader):

total_score = 0
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0

for batch in tqdm(loader):
batch = batch.to(device)
Expand Down Expand Up @@ -213,12 +213,12 @@ def test(loader):
result_dict = evaluator.eval(input_dict)
score = result_dict[metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

process_edges(src, dst, t, msg)

metric_dict = {}
metric_dict[metric] = total_score / num_labels
metric_dict[metric] = total_score / num_label_ts
return metric_dict

# ==========
Expand Down
6 changes: 3 additions & 3 deletions examples/nodeproppred/tgbn-reddit/moving_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def test_n_upate(loader):
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0

for batch in loader:
Expand Down Expand Up @@ -82,10 +82,10 @@ def test_n_upate(loader):
score = result_dict[eval_metric]

total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

metric_dict = {}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand Down
11 changes: 8 additions & 3 deletions examples/nodeproppred/tgbn-reddit/persistant_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
from torch_geometric.loader import TemporalDataLoader
from tqdm import tqdm
import torch

# local imports
from tgb.nodeproppred.dataset_pyg import PyGNodePropPredDataset
Expand All @@ -21,6 +22,10 @@
data = dataset.get_TemporalData()
data = data.to(device)

all_nodes = torch.cat((data.src, data.dst), 0)
all_nodes = all_nodes.unique()
print (all_nodes.shape[0])

eval_metric = dataset.eval_metric
forecaster = PersistantForecaster(num_classes)
evaluator = Evaluator(name=name)
Expand All @@ -46,7 +51,7 @@

def test_n_upate(loader):
label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0

for batch in tqdm(loader):
Expand Down Expand Up @@ -87,10 +92,10 @@ def test_n_upate(loader):
result_dict = evaluator.eval(input_dict)
score = result_dict[eval_metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

metric_dict = {}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand Down
15 changes: 7 additions & 8 deletions examples/nodeproppred/tgbn-reddit/tgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def train():
total_loss = 0
label_t = dataset.get_label_time() # check when does the first label start
total_score = 0
num_labels = 0
num_label_ts = 0

for batch in tqdm(train_loader):
batch = batch.to(device)
Expand Down Expand Up @@ -195,8 +195,7 @@ def train():
result_dict = evaluator.eval(input_dict)
score = result_dict[eval_metric]
total_score += score
num_labels += label_ts.shape[0]

num_label_ts += 1
loss.backward()
optimizer.step()
total_loss += float(loss)
Expand All @@ -206,9 +205,9 @@ def train():
memory.detach()

metric_dict = {
"ce": total_loss / num_labels,
"ce": total_loss / num_label_ts,
}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand All @@ -219,7 +218,7 @@ def test(loader):
node_pred.eval()

label_t = dataset.get_label_time() # check when does the first label start
num_labels = 0
num_label_ts = 0
total_score = 0

for batch in tqdm(loader):
Expand Down Expand Up @@ -288,12 +287,12 @@ def test(loader):
result_dict = evaluator.eval(input_dict)
score = result_dict[eval_metric]
total_score += score
num_labels += label_ts.shape[0]
num_label_ts += 1

process_edges(src, dst, t, msg)

metric_dict = {}
metric_dict[eval_metric] = total_score / num_labels
metric_dict[eval_metric] = total_score / num_label_ts
return metric_dict


Expand Down
Loading