webxos commited on
Commit
02e4da5
·
verified ·
1 Parent(s): 35423ab

Upload load_dataset.py

Browse files
Files changed (1) hide show
  1. load_dataset.py +46 -59
load_dataset.py CHANGED
@@ -1,62 +1,49 @@
1
  import json
2
- import pandas as pd
3
- from datasets import Dataset, DatasetDict
4
 
5
- def load_bci_fps_dataset(data_dir):
6
- """
7
- Load BCI-FPS dataset for Hugging Face.
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
- # Example usage for Neuralink research
53
- if __name__ == "__main__":
54
- dataset = load_bci_fps_dataset("./bci_data")
55
-
56
- print(f"Dataset keys: {list(dataset.keys())}")
57
- print(f"Neural data samples: {len(dataset['neural_data'])}")
58
- print(f"Intent stream samples: {len(dataset['intent_stream'])}")
59
-
60
- # Example: Extract motor imagery trials
61
- motor_trials = [d for d in dataset['neural_data'] if d.get('type') == 'motor_imagery_trial']
62
- print(f"Motor imagery trials: {len(motor_trials)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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