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
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EventXBench dataset loading script for Hugging Face `datasets` library.
|
| 2 |
+
|
| 3 |
+
This script is auto-detected by HF when the repo contains a .py file with the
|
| 4 |
+
same name as the repo. It defines dataset configs for each task (t1--t6) and
|
| 5 |
+
for the auxiliary data (posts, markets, ohlcv).
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
from datasets import load_dataset
|
| 9 |
+
|
| 10 |
+
# Load a specific task
|
| 11 |
+
ds = load_dataset("mlsys-io/EventXBench", "t1")
|
| 12 |
+
train_df = ds["train"].to_pandas()
|
| 13 |
+
|
| 14 |
+
# Load all configs
|
| 15 |
+
ds = load_dataset("mlsys-io/EventXBench", "t4")
|
| 16 |
+
"""
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
import json
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
_DESCRIPTION = (
|
| 26 |
+
"EventX: A multimodal benchmark linking Twitter/X posts to "
|
| 27 |
+
"Polymarket prediction market dynamics across seven tasks."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
_HOMEPAGE = "https://github.com/mlsys-io/EventXBench"
|
| 31 |
+
_LICENSE = "cc-by-nc-4.0"
|
| 32 |
+
|
| 33 |
+
_URLS = {
|
| 34 |
+
"t1_train": "data/t1/train.jsonl",
|
| 35 |
+
"t1_test": "data/t1/test.jsonl",
|
| 36 |
+
"t2_train": "data/t2/t2_train.jsonl",
|
| 37 |
+
"t2_validation": "data/t2/t2_val.jsonl",
|
| 38 |
+
"t2_test": "data/t2/t2_test.jsonl",
|
| 39 |
+
"t3_test": "data/t3/test.jsonl",
|
| 40 |
+
"t4_train": "data/t4/train.jsonl",
|
| 41 |
+
"t4_validation": "data/t4/validation.jsonl",
|
| 42 |
+
"t4_test": "data/t4/test.jsonl",
|
| 43 |
+
"t5_train": "data/t5/train.jsonl",
|
| 44 |
+
"t5_validation": "data/t5/validation.jsonl",
|
| 45 |
+
"t5_test": "data/t5/test.jsonl",
|
| 46 |
+
"t6_train": "data/t6/train.jsonl",
|
| 47 |
+
"t6_validation": "data/t6/validation.jsonl",
|
| 48 |
+
"t6_test": "data/t6/test.jsonl",
|
| 49 |
+
"t7_train": "data/t7/train.jsonl",
|
| 50 |
+
"t7_test": "data/t7/test.jsonl",
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class EventXBenchConfig(datasets.BuilderConfig):
|
| 55 |
+
"""BuilderConfig for EventXBench."""
|
| 56 |
+
|
| 57 |
+
def __init__(self, **kwargs):
|
| 58 |
+
super().__init__(**kwargs)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class EventXBench(datasets.GeneratorBasedBuilder):
|
| 62 |
+
"""EventXBench dataset."""
|
| 63 |
+
|
| 64 |
+
VERSION = datasets.Version("1.0.0")
|
| 65 |
+
|
| 66 |
+
BUILDER_CONFIGS = [
|
| 67 |
+
EventXBenchConfig(
|
| 68 |
+
name="t1",
|
| 69 |
+
version=VERSION,
|
| 70 |
+
description="T1: Conditional Market Volume Prediction (3-class)",
|
| 71 |
+
),
|
| 72 |
+
EventXBenchConfig(
|
| 73 |
+
name="t2",
|
| 74 |
+
version=VERSION,
|
| 75 |
+
description="T2: Post-to-Market Linking",
|
| 76 |
+
),
|
| 77 |
+
EventXBenchConfig(
|
| 78 |
+
name="t3",
|
| 79 |
+
version=VERSION,
|
| 80 |
+
description="T3: Evidence Grading (ordinal 0-5)",
|
| 81 |
+
),
|
| 82 |
+
EventXBenchConfig(
|
| 83 |
+
name="t4",
|
| 84 |
+
version=VERSION,
|
| 85 |
+
description="T4: Market Movement Prediction (direction x magnitude)",
|
| 86 |
+
),
|
| 87 |
+
EventXBenchConfig(
|
| 88 |
+
name="t5",
|
| 89 |
+
version=VERSION,
|
| 90 |
+
description="T5: Volume & Price Impact (decay classification)",
|
| 91 |
+
),
|
| 92 |
+
EventXBenchConfig(
|
| 93 |
+
name="t6",
|
| 94 |
+
version=VERSION,
|
| 95 |
+
description="T6: Cross-Market Propagation (3-class)",
|
| 96 |
+
),
|
| 97 |
+
EventXBenchConfig(
|
| 98 |
+
name="t7",
|
| 99 |
+
version=VERSION,
|
| 100 |
+
description="T7: Impact Persistence / Decay classification (3-class)",
|
| 101 |
+
),
|
| 102 |
+
]
|
| 103 |
+
|
| 104 |
+
DEFAULT_CONFIG_NAME = "t1"
|
| 105 |
+
|
| 106 |
+
def _info(self):
|
| 107 |
+
# Use generic features since each task has different schemas.
|
| 108 |
+
# HF will infer the schema from the first batch of examples.
|
| 109 |
+
return datasets.DatasetInfo(
|
| 110 |
+
description=_DESCRIPTION,
|
| 111 |
+
features=None, # auto-inferred from data
|
| 112 |
+
homepage=_HOMEPAGE,
|
| 113 |
+
license=_LICENSE,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
def _split_generators(self, dl_manager):
|
| 117 |
+
config = self.config.name
|
| 118 |
+
|
| 119 |
+
# Determine which files to download
|
| 120 |
+
files_to_dl = {}
|
| 121 |
+
for key, url in _URLS.items():
|
| 122 |
+
if key.startswith(config + "_"):
|
| 123 |
+
files_to_dl[key] = url
|
| 124 |
+
|
| 125 |
+
downloaded = dl_manager.download_and_extract(files_to_dl)
|
| 126 |
+
|
| 127 |
+
splits = []
|
| 128 |
+
train_key = f"{config}_train"
|
| 129 |
+
validation_key = f"{config}_validation"
|
| 130 |
+
test_key = f"{config}_test"
|
| 131 |
+
|
| 132 |
+
if train_key in downloaded:
|
| 133 |
+
splits.append(
|
| 134 |
+
datasets.SplitGenerator(
|
| 135 |
+
name=datasets.Split.TRAIN,
|
| 136 |
+
gen_kwargs={"filepath": downloaded[train_key]},
|
| 137 |
+
)
|
| 138 |
+
)
|
| 139 |
+
if validation_key in downloaded:
|
| 140 |
+
splits.append(
|
| 141 |
+
datasets.SplitGenerator(
|
| 142 |
+
name=datasets.Split.VALIDATION,
|
| 143 |
+
gen_kwargs={"filepath": downloaded[validation_key]},
|
| 144 |
+
)
|
| 145 |
+
)
|
| 146 |
+
if test_key in downloaded:
|
| 147 |
+
splits.append(
|
| 148 |
+
datasets.SplitGenerator(
|
| 149 |
+
name=datasets.Split.TEST,
|
| 150 |
+
gen_kwargs={"filepath": downloaded[test_key]},
|
| 151 |
+
)
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
return splits
|
| 155 |
+
|
| 156 |
+
def _generate_examples(self, filepath):
|
| 157 |
+
with open(filepath, "r", encoding="utf-8") as f:
|
| 158 |
+
for idx, line in enumerate(f):
|
| 159 |
+
line = line.strip()
|
| 160 |
+
if line:
|
| 161 |
+
yield idx, json.loads(line)
|