-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
馃悕 馃専 Hyper-Relational Statement Factory #1117
Open
migalkin
wants to merge
4
commits into
master
Choose a base branch
from
hyper-relational-data
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a076efe
First draft of the StatementFactory and WD50K datasets
migalkin e12135a
Lint and improve class inheritance for hyperrelational dataset
cthoyt 245995f
Reorganize base code
cthoyt d842a2e
Merge branch 'master' into hyper-relational-data
mberr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,30 @@ | |
from docdata import parse_docdata | ||
from more_click import verbose_option | ||
|
||
from .base import UnpackedRemoteDataset | ||
from .base import UnpackedRemoteDataset, HyperRelationalUnpackedRemoteDataset | ||
|
||
BASE_URL = "https://raw.githubusercontent.com/migalkin/StarE/master/data/clean/wd50k/" | ||
TRIPLES_VALID_URL = f"{BASE_URL}/triples/valid.txt" | ||
TRIPLES_TEST_URL = f"{BASE_URL}/triples/test.txt" | ||
TRIPLES_TRAIN_URL = f"{BASE_URL}/triples/train.txt" | ||
|
||
HYPER_RELATIONAL_BASE_URL = "https://raw.githubusercontent.com/migalkin/StarE/master/data/clean/" | ||
HYPER_RELATIONAL_MAIN_TRAIN_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k/statements/train.txt" | ||
HYPER_RELATIONAL_MAIN_VALID_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k/statements/valid.txt" | ||
HYPER_RELATIONAL_MAIN_TEST_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k/statements/test.txt" | ||
|
||
HYPER_RELATIONAL_33_TRAIN_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_33/statements/train.txt" | ||
HYPER_RELATIONAL_33_VALID_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_33/statements/valid.txt" | ||
HYPER_RELATIONAL_33_TEST_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_33/statements/test.txt" | ||
|
||
HYPER_RELATIONAL_66_TRAIN_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_66/statements/train.txt" | ||
HYPER_RELATIONAL_66_VALID_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_66/statements/valid.txt" | ||
HYPER_RELATIONAL_66_TEST_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_66/statements/test.txt" | ||
|
||
HYPER_RELATIONAL_100_TRAIN_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_100/statements/train.txt" | ||
HYPER_RELATIONAL_100_VALID_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_100/statements/valid.txt" | ||
HYPER_RELATIONAL_100_TEST_URL = f"{HYPER_RELATIONAL_BASE_URL}/wd50k_100/statements/test.txt" | ||
|
||
|
||
@parse_docdata | ||
class WD50KT(UnpackedRemoteDataset): | ||
|
@@ -55,10 +72,152 @@ def __init__(self, **kwargs): | |
) | ||
|
||
|
||
|
||
@parse_docdata | ||
class WD50K(HyperRelationalUnpackedRemoteDataset): | ||
"""The hyper-relational version of WD50K. | ||
|
||
--- | ||
name: WD50K (hyper-relational) | ||
citation: | ||
author: Galkin | ||
year: 2020 | ||
link: https://www.aclweb.org/anthology/2020.emnlp-main.596/ | ||
arxiv: 2009.10847 | ||
github: migalkin/StarE | ||
statistics: | ||
entities: 47,156 (5,460 qualifier-only) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cthoyt do we rely somewhere on parsing these statistics to integers? If yes, we should store the second number under a different key |
||
relations: 532 (45 qualifier-only) | ||
training: 166,435 | ||
testing: 46,159 | ||
validation: 23,913 | ||
statements: 236,507 | ||
statements w/ qualifiers: 32,167 (13.6%) | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the WD50K (hyper-relational) dataset from [galkin2020]_. | ||
|
||
:param kwargs: keyword arguments passed to :class:`pykeen.datasets.base.UnpackedRemoteDataset`. | ||
""" | ||
super().__init__( | ||
training_url=HYPER_RELATIONAL_MAIN_TRAIN_URL, | ||
testing_url=HYPER_RELATIONAL_MAIN_TEST_URL, | ||
validation_url=HYPER_RELATIONAL_MAIN_VALID_URL, | ||
load_triples_kwargs={"delimiter": ","}, | ||
**kwargs, | ||
) | ||
|
||
@parse_docdata | ||
class WD50K_33(HyperRelationalUnpackedRemoteDataset): | ||
"""The hyper-relational version of WD50K where 33% of statements have at lease one qualifier pair. | ||
|
||
--- | ||
name: WD50K (hyper-relational) | ||
citation: | ||
author: Galkin | ||
year: 2020 | ||
link: https://www.aclweb.org/anthology/2020.emnlp-main.596/ | ||
arxiv: 2009.10847 | ||
github: migalkin/StarE | ||
statistics: | ||
entities: 38,124 (6,463 qualifier-only) | ||
relations: 475 (47 qualifier-only) | ||
training: 73,406 | ||
testing: 18,133 | ||
validation: 10,568 | ||
statements: 102,107 | ||
statements w/ qualifiers: 31,866 (31.2%) | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the WD50K (33) (hyper-relational) dataset from [galkin2020]_. | ||
|
||
:param kwargs: keyword arguments passed to :class:`pykeen.datasets.base.UnpackedRemoteDataset`. | ||
""" | ||
super().__init__( | ||
training_url=HYPER_RELATIONAL_33_TRAIN_URL, | ||
testing_url=HYPER_RELATIONAL_33_TEST_URL, | ||
validation_url=HYPER_RELATIONAL_33_VALID_URL, | ||
load_triples_kwargs={"delimiter": ","}, | ||
**kwargs, | ||
) | ||
|
||
@parse_docdata | ||
class WD50K_66(HyperRelationalUnpackedRemoteDataset): | ||
"""The hyper-relational version of WD50K where 66% of statements have at lease one qualifier pair. | ||
|
||
--- | ||
name: WD50K (hyper-relational) | ||
citation: | ||
author: Galkin | ||
year: 2020 | ||
link: https://www.aclweb.org/anthology/2020.emnlp-main.596/ | ||
arxiv: 2009.10847 | ||
github: migalkin/StarE | ||
statistics: | ||
entities: 27,347 (7,167 qualifier-only) | ||
relations: 494 (53 qualifier-only) | ||
training: 35,968 | ||
testing: 8,045 | ||
validation: 5,154 | ||
statements: 49,167 | ||
statements w/ qualifiers: 31,696 (64.5%) | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the WD50K (66) (hyper-relational) dataset from [galkin2020]_. | ||
|
||
:param kwargs: keyword arguments passed to :class:`pykeen.datasets.base.UnpackedRemoteDataset`. | ||
""" | ||
super().__init__( | ||
training_url=HYPER_RELATIONAL_66_TRAIN_URL, | ||
testing_url=HYPER_RELATIONAL_66_TEST_URL, | ||
validation_url=HYPER_RELATIONAL_66_VALID_URL, | ||
load_triples_kwargs={"delimiter": ","}, | ||
**kwargs, | ||
) | ||
|
||
@parse_docdata | ||
class WD50K_100(HyperRelationalUnpackedRemoteDataset): | ||
"""The hyper-relational version of WD50K where 100% of statements have at lease one qualifier pair. | ||
|
||
--- | ||
name: WD50K (hyper-relational) | ||
citation: | ||
author: Galkin | ||
year: 2020 | ||
link: https://www.aclweb.org/anthology/2020.emnlp-main.596/ | ||
arxiv: 2009.10847 | ||
github: migalkin/StarE | ||
statistics: | ||
entities: 18,792 (7,862 qualifier-only) | ||
relations: 279 (75 qualifier-only) | ||
training: 22,738 | ||
testing: 5,297 | ||
validation: 3,279 | ||
statements: 31,314 | ||
statements w/ qualifiers: 31,314 (100%) | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the WD50K (100) (hyper-relational) dataset from [galkin2020]_. | ||
|
||
:param kwargs: keyword arguments passed to :class:`pykeen.datasets.base.UnpackedRemoteDataset`. | ||
""" | ||
super().__init__( | ||
training_url=HYPER_RELATIONAL_100_TRAIN_URL, | ||
testing_url=HYPER_RELATIONAL_100_TEST_URL, | ||
validation_url=HYPER_RELATIONAL_100_VALID_URL, | ||
load_triples_kwargs={"delimiter": ","}, | ||
**kwargs, | ||
) | ||
|
||
|
||
@click.command() | ||
@verbose_option | ||
def _main(): | ||
for cls in [WD50KT]: | ||
for cls in [WD50KT, WD50K, WD50K_33, WD50K_66, WD50K_100]: | ||
click.secho(f"Loading {cls.__name__}", fg="green", bold=True) | ||
d = cls() | ||
d.summarize() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we need a different base class mixin for this kind of dataset to note that the triples factories have to be SatementFactories