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

🚀🫀 Extend scoring, evaluation, and inference for relation side #728

Open
wants to merge 54 commits into
base: master
Choose a base branch
from

Conversation

cthoyt
Copy link
Member

@cthoyt cthoyt commented Jan 16, 2022

Most of the PyKEEN pipeline was built around the scoring and evaluation of head/tail corruptions. However, there were a few places where we added in functionality for training where the relations are corrupted. This PR uses the pre-existing templates for handling of heads and tails in the pykeen.models.Model and pykeen.evaluation.Evaluator classes to enable these things. This PR is missing a few things:

  • An implementation of pykeen.models.Model.score_r_inverse
  • Should pykeen.models.Model.predict_r be updated to use pykeen.models.Model.score_r_inverse similarly to how pykeen.models.Model.predict_h uses pykeen.models.Model.score_h_inverse?
  • Should there be an actual implementation of the dummy evaluator's process_relation_scores_ function?

Dependencies

@cthoyt cthoyt changed the title 🚀 🫀 Extend scoring, evaluation, and inference for relation side 🚀🫀 Extend scoring, evaluation, and inference for relation side Jan 16, 2022
src/pykeen/models/base.py Outdated Show resolved Hide resolved
src/pykeen/models/base.py Outdated Show resolved Hide resolved
@cthoyt cthoyt requested a review from mberr January 16, 2022 17:32
@cthoyt cthoyt marked this pull request as ready for review January 16, 2022 17:37
src/pykeen/models/base.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/classification_evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/classification_evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
src/pykeen/models/base.py Show resolved Hide resolved
src/pykeen/models/base.py Outdated Show resolved Hide resolved
tests/cases.py Outdated Show resolved Hide resolved
tests/test_models.py Outdated Show resolved Hide resolved
cthoyt and others added 4 commits January 23, 2022 01:32
Co-authored-by: Max Berrendorf <berrendorf@dbs.ifi.lmu.de>
Co-authored-by: Max Berrendorf <berrendorf@dbs.ifi.lmu.de>
tests/cases.py Outdated Show resolved Hide resolved
tests/cases.py Outdated
elif target == LABEL_TAIL:
sel_col, start_col = 2, 0
elif target == LABEL_RELATION:
raise NotImplementedError(target)
else:
raise ValueError(target)
stop_col = start_col + 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to adjust this one, too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this one resolved? from the code below it looks like the range start_col:stop_col is not working for all but the first case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk. I just added the relation one with what seemed to fit the pattern 🤷

@cthoyt
Copy link
Member Author

cthoyt commented Jan 31, 2022

@mberr everything here is done - I marked the SampledRankingEvaluator with a NotImplementedError since it seems like it might not make sense to process relation scores for that one

src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/classification_evaluator.py Outdated Show resolved Hide resolved
src/pykeen/evaluation/evaluator.py Outdated Show resolved Hide resolved
Comment on lines +396 to +398
# Checking for self.inverse is not necessary since we have score_h_inverse.
# Since we have inverse triples, where the order of entities is inverted,
# and the relation replaced by an inverse relation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment seems to be outdated

@@ -523,6 +529,19 @@ def score_t_inverse(self, hr_batch: torch.LongTensor, slice_size: Optional[int]
r_inv_h = self._prepare_inverse_batch(batch=hr_batch, index_relation=1)
return self.score_h(rt_batch=r_inv_h, slice_size=slice_size)

def score_r_inverse(self, ht_batch: torch.LongTensor, slice_size: Optional[int] = None):
"""Score all rels for a batch of (h,t)-pairs using the rel predictions for the inverses $(t,*_{inv},h)$."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is described in the docstring does make sense from my point of view: We compute scores for all relations, but this time, using the inverse representation and flipped head & tail.

score[i] = score(t, r_i_inv, h)

implementing seems to depend on fixing what score_r computes, which currently is equal to scores for normal and inverse relations (cf. #752 )

tests/cases.py Outdated Show resolved Hide resolved
tests/cases.py Outdated
elif target == LABEL_TAIL:
sel_col, start_col = 2, 0
elif target == LABEL_RELATION:
raise NotImplementedError(target)
else:
raise ValueError(target)
stop_col = start_col + 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this one resolved? from the code below it looks like the range start_col:stop_col is not working for all but the first case

tests/test_evaluators.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants