alonmiron commited on
Commit
3ec575d
1 Parent(s): 6e04a1e

Upload 3 files

Browse files
Files changed (3) hide show
  1. README (2).md +3 -0
  2. data-03.tar +3 -0
  3. mmlu_560_iter_3.py +196 -0
README (2).md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
data-03.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04e221bb3197375af6efd230469a32ec6f24258d15aa2d4cdeaf741438735827
3
+ size 1064960
mmlu_560_iter_3.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ import csv
18
+ import os
19
+
20
+ import datasets
21
+ import tarfile
22
+
23
+ _CITATION = """\
24
+ @article{hendryckstest2021,
25
+ title={Measuring Massive Multitask Language Understanding},
26
+ author={Dan Hendrycks and Collin Burns and Steven Basart and Andy Zou and Mantas Mazeika and Dawn Song and Jacob Steinhardt},
27
+ journal={Proceedings of the International Conference on Learning Representations (ICLR)},
28
+ year={2021}
29
+ }
30
+ """
31
+
32
+ _DESCRIPTION = """\
33
+ This is a massive multitask test consisting of multiple-choice questions from various branches of knowledge, covering 57 tasks including elementary mathematics, US history, computer science, law, and more.
34
+ """
35
+
36
+ _HOMEPAGE = "https://huggingface.co/datasets/alonmiron/mmlu_hinted_huggingface"
37
+
38
+ _URL = "https://huggingface.co/datasets/alonmiron/mmlu_560_iter_3/resolve/main/data-03.tar"
39
+ # _URL = "https://huggingface.co/datasets/cais/mmlu/resolve/main/data.tar"
40
+
41
+ _SUBJECTS = [
42
+ "all",
43
+ "abstract_algebra",
44
+ "anatomy",
45
+ "astronomy",
46
+ "business_ethics",
47
+ "clinical_knowledge",
48
+ "college_biology",
49
+ "college_chemistry",
50
+ "college_computer_science",
51
+ "college_mathematics",
52
+ "college_medicine",
53
+ "college_physics",
54
+ "computer_security",
55
+ "conceptual_physics",
56
+ "econometrics",
57
+ "electrical_engineering",
58
+ "elementary_mathematics",
59
+ "formal_logic",
60
+ "global_facts",
61
+ "high_school_biology",
62
+ "high_school_chemistry",
63
+ "high_school_computer_science",
64
+ "high_school_european_history",
65
+ "high_school_geography",
66
+ "high_school_government_and_politics",
67
+ "high_school_macroeconomics",
68
+ "high_school_mathematics",
69
+ "high_school_microeconomics",
70
+ "high_school_physics",
71
+ "high_school_psychology",
72
+ "high_school_statistics",
73
+ "high_school_us_history",
74
+ "high_school_world_history",
75
+ "human_aging",
76
+ "human_sexuality",
77
+ "international_law",
78
+ "jurisprudence",
79
+ "logical_fallacies",
80
+ "machine_learning",
81
+ "management",
82
+ "marketing",
83
+ "medical_genetics",
84
+ "miscellaneous",
85
+ "moral_disputes",
86
+ "moral_scenarios",
87
+ "nutrition",
88
+ "philosophy",
89
+ "prehistory",
90
+ "professional_accounting",
91
+ "professional_law",
92
+ "professional_medicine",
93
+ "professional_psychology",
94
+ "public_relations",
95
+ "security_studies",
96
+ "sociology",
97
+ "us_foreign_policy",
98
+ "virology",
99
+ # "world_religions",
100
+ ]
101
+
102
+
103
+ def check_archive_contents(archive_path):
104
+ # Try to open the tar archive
105
+ try:
106
+ with tarfile.open(archive_path, 'r') as tar:
107
+ # Get the list of members
108
+ members = tar.getmembers()
109
+ if not members:
110
+ print("The archive is empty.")
111
+ else:
112
+ print("The archive contains files. Number of files:", len(members))
113
+ except tarfile.ReadError as e:
114
+ print("There was an error opening the tar file:", e)
115
+ except Exception as e:
116
+ print("An unexpected error occurred:", e)
117
+
118
+
119
+ class Mmlu(datasets.GeneratorBasedBuilder):
120
+ """Measuring Massive Multitask Language Understanding, consisting of 57 tasks"""
121
+
122
+ BUILDER_CONFIGS = [
123
+ datasets.BuilderConfig(
124
+ name=sub, version=datasets.Version("1.0.0"), description=f"MMLU Subject {sub}"
125
+ )
126
+ for sub in _SUBJECTS
127
+ ]
128
+
129
+ def _info(self):
130
+ features = datasets.Features(
131
+ {
132
+ "question": datasets.Value("string"),
133
+ "subject": datasets.Value("string"),
134
+ "choices": datasets.features.Sequence(datasets.Value("string")),
135
+ "answer": datasets.features.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
136
+ }
137
+ )
138
+ return datasets.DatasetInfo(
139
+ description=_DESCRIPTION,
140
+ features=features,
141
+ homepage=_HOMEPAGE,
142
+ citation=_CITATION,
143
+ )
144
+
145
+ def _split_generators(self, dl_manager):
146
+ print("split_generators got called")
147
+ """Returns SplitGenerators."""
148
+ archive = dl_manager.download(_URL)
149
+ check_archive_contents(archive)
150
+ if os.path.exists(archive):
151
+ print("Download successful, archive is present at:", archive)
152
+ else:
153
+ print("Download failed, archive not found.")
154
+ return [
155
+ # datasets.SplitGenerator(
156
+ # name=datasets.Split("auxiliary_train"),
157
+ # gen_kwargs={
158
+ # "iter_archive": dl_manager.iter_archive(archive),
159
+ # "split": "auxiliary_train",
160
+ # },
161
+ # ),
162
+ datasets.SplitGenerator(
163
+ name=datasets.Split.TEST,
164
+ gen_kwargs={"iter_archive": dl_manager.iter_archive(archive), "split": "test"},
165
+ ),
166
+ datasets.SplitGenerator(
167
+ name=datasets.Split.VALIDATION,
168
+ gen_kwargs={
169
+ "iter_archive": dl_manager.iter_archive(archive),
170
+ "split": "val",
171
+ },
172
+ ),
173
+ datasets.SplitGenerator(
174
+ name=datasets.Split("dev"),
175
+ gen_kwargs={
176
+ "iter_archive": dl_manager.iter_archive(archive),
177
+ "split": "dev",
178
+ },
179
+ ),
180
+ ]
181
+
182
+ def _generate_examples(self, iter_archive, split):
183
+ """Yields examples as (key, example) tuples."""
184
+ n_yielded_files = 0
185
+ for id_file, (path, file) in enumerate(iter_archive):
186
+ if f"data/{split}/" in path:
187
+ if split == "auxiliary_train" or f"{self.config.name}_{split}.csv" in path or self.config.name == "all":
188
+ subset = path.split("/")[-1].rsplit("_",1)[0] if split != "auxiliary_train" else ""
189
+ n_yielded_files += 1
190
+ lines = (line.decode("utf-8") for line in file)
191
+ reader = csv.reader(lines)
192
+ for id_line, data in enumerate(reader):
193
+ yield f"{id_file}_{id_line}", {"question": data[0], "choices": data[1:5], "answer": data[5], "subject": subset}
194
+ if (n_yielded_files == 8 or split != "auxiliary_train") and self.config.name != "all":
195
+ break
196
+