Upload load_dataset.py
Browse files- load_dataset.py +46 -59
load_dataset.py
CHANGED
|
@@ -1,62 +1,49 @@
|
|
| 1 |
import json
|
| 2 |
-
import
|
| 3 |
-
from datasets import Dataset, DatasetDict
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
Args:
|
| 10 |
-
data_dir (str): Path to dataset directory
|
| 11 |
-
|
| 12 |
-
Returns:
|
| 13 |
-
DatasetDict: Hugging Face dataset
|
| 14 |
-
"""
|
| 15 |
-
# Load neural data
|
| 16 |
-
neural_data = []
|
| 17 |
-
with open(f"{data_dir}/neural_data.jsonl", 'r') as f:
|
| 18 |
-
for line in f:
|
| 19 |
-
if line.strip():
|
| 20 |
-
neural_data.append(json.loads(line))
|
| 21 |
-
|
| 22 |
-
# Load intent stream
|
| 23 |
-
intent_stream = []
|
| 24 |
-
with open(f"{data_dir}/intent_stream.jsonl", 'r') as f:
|
| 25 |
-
for line in f:
|
| 26 |
-
if line.strip():
|
| 27 |
-
intent_stream.append(json.loads(line))
|
| 28 |
-
|
| 29 |
-
# Create datasets
|
| 30 |
-
datasets = {
|
| 31 |
-
"neural_data": Dataset.from_list(neural_data),
|
| 32 |
-
"intent_stream": Dataset.from_list(intent_stream)
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
# Load handwriting samples if exists
|
| 36 |
-
try:
|
| 37 |
-
with open(f"{data_dir}/handwriting_samples.json", 'r') as f:
|
| 38 |
-
handwriting = json.load(f)
|
| 39 |
-
datasets["handwriting"] = Dataset.from_list(handwriting)
|
| 40 |
-
except:
|
| 41 |
-
pass
|
| 42 |
-
|
| 43 |
-
# Load metadata
|
| 44 |
-
with open(f"{data_dir}/metadata.json", 'r') as f:
|
| 45 |
-
metadata = json.load(f)
|
| 46 |
-
|
| 47 |
-
dataset_dict = DatasetDict(datasets)
|
| 48 |
-
dataset_dict.info.metadata = metadata
|
| 49 |
-
|
| 50 |
-
return dataset_dict
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
+
import datasets
|
|
|
|
| 3 |
|
| 4 |
+
_DESCRIPTION = "Neural data with intent context"
|
| 5 |
+
_CITATION = ""
|
| 6 |
+
_HOMEPAGE = ""
|
| 7 |
+
_LICENSE = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
class NeuralData(datasets.GeneratorBasedBuilder):
|
| 10 |
+
VERSION = datasets.Version("1.0.0")
|
| 11 |
+
|
| 12 |
+
def _info(self):
|
| 13 |
+
return datasets.DatasetInfo(
|
| 14 |
+
description=_DESCRIPTION,
|
| 15 |
+
features=datasets.Features({
|
| 16 |
+
"timestamp": datasets.Value("int64"),
|
| 17 |
+
"session_time": datasets.Value("int64"),
|
| 18 |
+
"channels": {
|
| 19 |
+
f"channel_{i}": datasets.Value("float64") for i in range(32)
|
| 20 |
+
},
|
| 21 |
+
"intent_context": {
|
| 22 |
+
"mouse_movement": datasets.Sequence(datasets.Value("int64")),
|
| 23 |
+
"keyboard_state": {
|
| 24 |
+
"mouse": datasets.Value("bool")
|
| 25 |
+
},
|
| 26 |
+
"camera_rotation": datasets.Sequence(datasets.Value("float64")),
|
| 27 |
+
"active_targets": datasets.Value("int64")
|
| 28 |
+
}
|
| 29 |
+
}),
|
| 30 |
+
supervised_keys=None,
|
| 31 |
+
homepage=_HOMEPAGE,
|
| 32 |
+
citation=_CITATION,
|
| 33 |
+
license=_LICENSE,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
def _split_generators(self, dl_manager):
|
| 37 |
+
return [
|
| 38 |
+
datasets.SplitGenerator(
|
| 39 |
+
name=datasets.Split.TRAIN,
|
| 40 |
+
gen_kwargs={"filepath": "neural_data.txt"}
|
| 41 |
+
)
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
def _generate_examples(self, filepath):
|
| 45 |
+
with open(filepath, "r") as f:
|
| 46 |
+
for idx, line in enumerate(f):
|
| 47 |
+
if line.strip():
|
| 48 |
+
data = json.loads(line)
|
| 49 |
+
yield idx, data
|