-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Max Berrendorf <berrendorf@dbs.ifi.lmu.de>
Co-authored-by: Max Berrendorf <berrendorf@dbs.ifi.lmu.de>
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🤷
@mberr everything here is done - I marked the SampledRankingEvaluator with a |
# 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. |
There was a problem hiding this comment.
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)$.""" |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
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
andpykeen.evaluation.Evaluator
classes to enable these things. This PR is missing a few things:pykeen.models.Model.score_r_inverse
pykeen.models.Model.predict_r
be updated to usepykeen.models.Model.score_r_inverse
similarly to howpykeen.models.Model.predict_h
usespykeen.models.Model.score_h_inverse
?process_relation_scores_
function?Dependencies