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

[Feature] Small Changes #381

Merged
merged 1 commit into from
Aug 23, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import torch
import torch.nn as nn
import os
import json
import numpy as np
from .. import ModelWrapper

from cogdl.utils.link_prediction_utils import cal_mrr, DistMultLayer, ConvELayer
from cogdl.datasets.kg_data import BidirectionalOneShotIterator, TestDataset, TrainDataset
from tqdm import tqdm
import torch.nn.functional as F


Expand Down Expand Up @@ -89,12 +84,11 @@ def val_step(self, subgraph):
def eval_step(self, subgraph):
test_dataloader_head, test_dataloader_tail = subgraph
logs = []
step = 0
test_dataset_list = [test_dataloader_head, test_dataloader_tail]
total_steps = sum([len(dataset) for dataset in test_dataset_list])

for test_dataset in test_dataset_list:
for positive_sample, negative_sample, filter_bias, mode in test_dataset:
pbar = tqdm(test_dataset)
for positive_sample, negative_sample, filter_bias, mode in pbar:
pbar.set_description("Evaluating the model: Use mode({})".format(mode))
positive_sample = positive_sample.to(self.device)
negative_sample = negative_sample.to(self.device)
filter_bias = filter_bias.to(self.device)
Expand Down Expand Up @@ -131,11 +125,6 @@ def eval_step(self, subgraph):
}
)

if step % 1000 == 0:
print("Evaluating the model... (%d/%d)" % (step, total_steps))

step += 1

metrics = {}
for metric in logs[0].keys():
metrics[metric] = sum([log[metric] for log in logs]) / len(logs)
Expand Down