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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摽 馃З Support disconnected nodes in the Relation tokenizer #1064

Merged
merged 8 commits into from
Aug 11, 2022

Conversation

migalkin
Copy link
Member

@migalkin migalkin commented Aug 10, 2022

A quick fix for the sampler in relation tokenizer to support graphs where num_entities is larger than pool size.

A script to reproduce the error before/after the fix

import torch.nn
from pykeen.models import NodePiece
from pykeen.triples import CoreTriplesFactory

edges = torch.tensor([
    [0, 0, 1],
    [1, 1, 0],
    [3, 1, 0],
    [3, 2, 1]
], dtype=torch.long)  # node ID 2 is missing as a disconnected node

factory = CoreTriplesFactory.create(mapped_triples=edges, num_entities=4, num_relations=3, create_inverse_triples=True)
model = NodePiece(triples_factory=factory, num_tokens=2)

Generally, taking care of disconnected nodes in NodePiece in more complex scenarios might take much more effort

@migalkin migalkin requested a review from mberr August 10, 2022 15:52
@migalkin migalkin changed the title Sampling in the Relation tokenizer now supports disconnected nodes Support disconnected nodes in the Relation tokenizer Aug 10, 2022
@migalkin migalkin changed the title Support disconnected nodes in the Relation tokenizer 馃摽 馃З Support disconnected nodes in the Relation tokenizer Aug 10, 2022
Copy link
Member

@mberr mberr left a comment

Choose a reason for hiding this comment

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

lgtm

could you add the small snippet from the PR description as a test?

@migalkin
Copy link
Member Author

lgtm

could you add the small snippet from the PR description as a test?

To test_nn/test_node_piece or cases? This test would require a different triples factory than the current default NodePieceTestCase

@mberr
Copy link
Member

mberr commented Aug 10, 2022

lgtm
could you add the small snippet from the PR description as a test?

To test_nn/test_node_piece or cases? This test would require a different triples factory than the current default NodePieceTestCase

maybe like this? 59e829f

@migalkin
Copy link
Member Author

Cool, works as intended! Thank you :)

@mberr
Copy link
Member

mberr commented Aug 10, 2022

Cool, works as intended! Thank you :)

thanks for writing the tests in the first place 馃槈

@mberr mberr self-requested a review August 10, 2022 18:55
@cthoyt cthoyt self-requested a review August 10, 2022 22:02
@migalkin migalkin requested review from mberr and removed request for mberr August 10, 2022 22:02
@cthoyt cthoyt enabled auto-merge (squash) August 10, 2022 22:03
@cthoyt cthoyt disabled auto-merge August 10, 2022 22:03
@cthoyt cthoyt merged commit 9eba30f into master Aug 11, 2022
@cthoyt cthoyt deleted the nodepiece-fix-disconnected-node-rel-tok branch August 11, 2022 00:09
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