Skip to content

🌯 🌪️ Encapsulate inverse relations #752

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

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

Conversation

mberr
Copy link
Member

@mberr mberr commented Jan 25, 2022

Fixes #749

Tasks:

  • remove inverse_triples flags from TriplesFactory and Datasets.
  • add inverse triples handling to Model
  • update training loop / instances

Dependencies

New Structure

  • abstract:
    • score_hrt(h, r, t)
    • score_h(r, t, slice_size)
    • score_r(h, t, slice_size)
    • score_t(h, r, slice_size)
  • wrapper (abstract + inverse relation handling):
    • score_hrt_extended(h, r, t, invert_relation)
    • score_h_extended(r, t, slice_size, invert_relation)
    • score_r_extended(h, t, slice_size, invert_relation)
    • score_t_extended(h, r, slice_size, invert_relation)
  • predict (eval + wrapper + switch to score_h):
    • predict_hrt(h, r, t, invert_relation)
    • predict_h(r, t, slice_size, invert_relation)
    • predict_r(h, t, slice_size, invert_relation)
    • predict_t(h, r, slice_size, invert_relation)
  • score_{hrt,h,t}_inverse -> move to prediction workflows?

@cthoyt
Copy link
Member

cthoyt commented Jan 30, 2022

What's the roadmap for this PR?

I think that it's fine to keep score_{hrt,h,t}_inverse inside the model - it would only appear in the base Model class, right?

@cthoyt cthoyt removed their request for review February 14, 2025 16:51
Comment on lines -188 to -190
if dataset_instance.create_inverse_triples and not create_inverse_triples:
assert dataset_instance.training.num_relations % 2 == 0
dataset_instance.training.num_relations //= 2
Copy link
Member Author

Choose a reason for hiding this comment

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

We might need to keep that, if we want to be able to load from old cache files.

@@ -112,18 +115,18 @@ def __init__(
else:
self.loss = loss_resolver.make(loss, pos_kwargs=loss_kwargs)

self.use_inverse_triples = triples_factory.create_inverse_triples
self.use_inverse_triples = create_inverse_triples
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should agree on some consistent naming

Copy link
Member

Choose a reason for hiding this comment

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

let's do that in a follow-up PR, since the diff is already so big

tests/cases.py Outdated
@@ -1083,6 +1084,7 @@ def test_score_r(self) -> None:
self._test_score(
score=self.instance.score_r,
columns=[0, 2],
# switch to effective_num_relations?
Copy link
Member

Choose a reason for hiding this comment

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

TODO - either switch to self.instance.effective_num_relations or update the tests to new have parameters

Copy link
Member

Choose a reason for hiding this comment

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

in 3104af9 I witched it to self.instance.effective_num_relations and this made the tests pass again, except inductive GNN nodepiece

@cthoyt cthoyt self-requested a review February 15, 2025 14:14

# FIXME do these need to get passed the relation inverter? or how should
# this math get updated
inverse_edge_index = edge_index.flip(0)
Copy link
Member

Choose a reason for hiding this comment

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

@mberr I also tracked down some issues in GNN - do you have an idea how to update the CompGCN layer to work better with the new way of doing inverses?

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.

Encapsulate inverse relations inside Model
2 participants