-
Notifications
You must be signed in to change notification settings - Fork 87
Add TGB community datasets + official evaluation tasks #358
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4705d01
Add TGB (Temporal Graph Benchmark) datasets + tasks
pc0618 c51b389
Fix TGB task defs and add hashes
pc0618 b9b4fd7
Update TGB tasks and refresh hashes
pc0618 dcd63c4
Drop TGB *-next task registrations
pc0618 1dbb2ba
Trim comments in TGB modules
pc0618 80f57ed
Document TGB community datasets
pc0618 1b611f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 23b161c
Rename TGB slugs; drop README section
pc0618 ad9eef6
Merge branch 'main' into add-tgb-datasets
rishabh-ranjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from relbench.base import Database, Dataset | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class TGBCutoffs: | ||
| val_timestamp_s: int | ||
| test_timestamp_s: int | ||
|
|
||
|
|
||
| _TGB_CUTOFFS: dict[str, TGBCutoffs] = { | ||
| "tgbl-wiki": TGBCutoffs(val_timestamp_s=1862653, test_timestamp_s=2218300), | ||
| "tgbl-wiki-v2": TGBCutoffs(val_timestamp_s=1862653, test_timestamp_s=2218300), | ||
| "tgbl-review": TGBCutoffs(val_timestamp_s=1464912000, test_timestamp_s=1488844800), | ||
| "tgbl-review-v2": TGBCutoffs( | ||
| val_timestamp_s=1464912000, test_timestamp_s=1488844800 | ||
| ), | ||
| "tgbl-coin": TGBCutoffs(val_timestamp_s=1662096249, test_timestamp_s=1664482319), | ||
| "tgbl-comment": TGBCutoffs(val_timestamp_s=1282869285, test_timestamp_s=1288838725), | ||
| "tgbl-flight": TGBCutoffs(val_timestamp_s=1638162000, test_timestamp_s=1653796800), | ||
| "thgl-software": TGBCutoffs( | ||
| val_timestamp_s=1706003880, test_timestamp_s=1706315669 | ||
| ), | ||
| "thgl-forum": TGBCutoffs(val_timestamp_s=1390426563, test_timestamp_s=1390838358), | ||
| "thgl-github": TGBCutoffs(val_timestamp_s=1711075987, test_timestamp_s=1711482874), | ||
| "thgl-myket": TGBCutoffs(val_timestamp_s=1603724860, test_timestamp_s=1606341312), | ||
| "tgbn-trade": TGBCutoffs(val_timestamp_s=1262304000, test_timestamp_s=1388534400), | ||
| "tgbn-genre": TGBCutoffs(val_timestamp_s=1216427762, test_timestamp_s=1230448684), | ||
| "tgbn-reddit": TGBCutoffs(val_timestamp_s=1279485233, test_timestamp_s=1286653871), | ||
| "tgbn-token": TGBCutoffs(val_timestamp_s=1522889022, test_timestamp_s=1525386888), | ||
| } | ||
|
|
||
|
|
||
| class TGBDataset(Dataset): | ||
| r"""Temporal Graph Benchmark (TGB) datasets exported to RelBench format.""" | ||
|
|
||
| url = "https://tgb.complexdatalab.com/" | ||
|
|
||
| def __init__(self, *, tgb_name: str, cache_dir: Optional[str] = None) -> None: | ||
| if tgb_name not in _TGB_CUTOFFS: | ||
| raise ValueError( | ||
| f"Unknown tgb_name='{tgb_name}'. Known keys: {sorted(_TGB_CUTOFFS.keys())}" | ||
| ) | ||
| self.tgb_name = str(tgb_name) | ||
|
|
||
| cutoffs = _TGB_CUTOFFS[self.tgb_name] | ||
| self.val_timestamp = pd.to_datetime( | ||
| int(cutoffs.val_timestamp_s), unit="s", utc=True | ||
| ) | ||
| self.test_timestamp = pd.to_datetime( | ||
| int(cutoffs.test_timestamp_s), unit="s", utc=True | ||
| ) | ||
|
|
||
| super().__init__(cache_dir=cache_dir) | ||
|
|
||
| def make_db(self) -> Database: | ||
| if self.cache_dir is None: | ||
| raise RuntimeError("TGBDataset requires cache_dir to locate the cached db.") | ||
|
|
||
| db_dir = Path(self.cache_dir) / "db" | ||
| if db_dir.exists() and any(db_dir.glob("*.parquet")): | ||
| return Database.load(db_dir) | ||
|
|
||
| raise RuntimeError( | ||
| f"TGB dataset '{self.tgb_name}' not found at {db_dir}. " | ||
| "This dataset is distributed as a pre-built RelBench database (db.zip). " | ||
| "Please run `download_dataset(...)` or place `db/*.parquet` in the cache directory." | ||
| ) |
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.