umwyf commited on
Commit
f43cd2e
1 Parent(s): 646b242

Upload Hi-ToM.py

Browse files
Files changed (1) hide show
  1. Hi-ToM.py +59 -0
Hi-ToM.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from datasets import DatasetBuilder, DatasetInfo, SplitGenerators, DownloadManager
3
+ from datasets.features import Features, Value
4
+ import datasets
5
+
6
+ class MyCustomDataset(DatasetBuilder):
7
+ VERSION = datasets.Version("1.0.0")
8
+
9
+ def _info(self):
10
+ # Ensure CITATION is a string containing the bibliographic citation for your dataset
11
+
12
+ return DatasetInfo(
13
+ description="My custom dataset for tracking objects.",
14
+ features=Features({
15
+ "prompting_type": Value("string"),
16
+ "deception": Value("bool"),
17
+ "story_length": Value("int32"),
18
+ "question_order": Value("int32"),
19
+ "sample_id": Value("int32"),
20
+ "story": Value("string"),
21
+ "question": Value("string"),
22
+ "choices": Value("string"),
23
+ "answer": Value("string"),
24
+ }),
25
+ supervised_keys=None,
26
+ homepage="https://github.com/ying-hui-he/Hi-ToM_dataset",
27
+ )
28
+
29
+ def _split_generators(self, dl_manager: DownloadManager):
30
+ # Using the raw content URL for GitHub
31
+ downloaded_files = dl_manager.download_and_extract({
32
+ "data_file": "https://raw.githubusercontent.com/ying-hui-he/Hi-ToM_dataset/main/Hi-ToM_data.json"
33
+ })
34
+
35
+ return [
36
+ datasets.SplitGenerator(
37
+ name=datasets.Split.TEST,
38
+ gen_kwargs={
39
+ "filepath": downloaded_files["data_file"],
40
+ },
41
+ ),
42
+ ]
43
+
44
+ def _generate_examples(self, filepath):
45
+ with open(filepath, encoding="utf-8") as f:
46
+ data = json.load(f)["data"] # Accessing the 'data' field directly
47
+ for id, item in enumerate(data):
48
+ yield id, {
49
+ "prompting_type": item["prompting_type"],
50
+ "deception": item["deception"],
51
+ "story_length": item["story_length"],
52
+ "question_order": item["question_order"],
53
+ "sample_id": item["sample_id"],
54
+ "story": item["story"],
55
+ "question": item["question"],
56
+ "choices": item["choices"],
57
+ "answer": item["answer"],
58
+ }
59
+ # Replace 'MyCustomDataset' with a suitable name that follows Python class naming conventions.