-
Hi! I am using pykeen for a study where I compare multiple datasets with several link prediction methods. Some of these are pykeen models, but some are not. I want to use the same evaluation for all methods for consistency. However, it seems that to use the pykeen evaluator (RankBasedEvaluator), it is required to input a pykeen model. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, you can directly use the import torch
from pykeen.evaluation import RankBasedEvaluator
from pykeen.datasets import get_dataset
from pykeen.typing import LABEL_TAIL
# instantiate an evaluator
evaluator = RankBasedEvaluator()
# process the scores
# todo: replace this by your way how to calculate scores
dataset = get_dataset(dataset="nations")
for hrt_batch in dataset.training.mapped_triples.split(16, dim=0):
scores = torch.rand(size=(hrt_batch.shape[0], dataset.num_entities))
true_score = torch.gather(scores, dim=-1, index=hrt_batch[:, 2:3])
evaluator.process_scores_(hrt_batch=hrt_batch, target=LABEL_TAIL, scores=scores, true_scores=true_score)
# calculate aggregation metrics
result = evaluator.finalize()
print(result.to_df()) |
Beta Was this translation helpful? Give feedback.
Yes, you can directly use the
RankBasedEvaluator
instance to process scores, e.g.: