pminervini commited on
Commit
b7d562b
1 Parent(s): db18e72
Files changed (1) hide show
  1. cli/shroom-upload-cli.py +34 -0
cli/shroom-upload-cli.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ import json
4
+ from datasets import Dataset, DatasetDict
5
+
6
+ file_path = "shroom-data/val.model-agnostic.json"
7
+ ds_path = 'pminervini/shroom'
8
+
9
+ with open(file_path, 'r') as file:
10
+ data = json.load(file)
11
+
12
+
13
+ def convert(list_of_dicts):
14
+ dict_of_lists = {}
15
+ for d in list_of_dicts:
16
+ for key, value in d.items():
17
+ dict_of_lists.setdefault(key, []).append(value)
18
+ return dict_of_lists
19
+
20
+
21
+ task_to_data_map = {}
22
+
23
+ for entry in data:
24
+ task_name = entry["task"]
25
+ del entry["task"]
26
+ if task_name not in task_to_data_map:
27
+ task_to_data_map[task_name] = []
28
+ task_to_data_map[task_name] += [entry]
29
+
30
+ task_to_ds_map = {k: Dataset.from_dict(convert(data)) for k, data in task_to_data_map.items()}
31
+
32
+ ds_dict = DatasetDict(task_to_ds_map)
33
+
34
+ ds_dict.push_to_hub(ds_path)