-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
233 lines (179 loc) · 7.42 KB
/
utils.py
File metadata and controls
233 lines (179 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import json
import sys
import pandas as pd
def clean_string(s):
"""
Returns a cleaned string
"""
s = s.replace('\n', '')
s = s.replace('\\n', '')
if s.endswith('$$$'):
s = s[:len(s) - 1]
return s
def clean_list(lst):
"""
Takes as input a list of strings, outputs cleaned strings
"""
lst = [clean_string(val) for val in lst]
return lst
def get_med_questions(existing_qs, include_all, as_df):
"""
Returns MedMCQA benchmark questions
"""
splits = {'train': 'data/train-00000-of-00001.parquet', 'test': 'data/test-00000-of-00001.parquet', 'validation': 'data/validation-00000-of-00001.parquet'}
benchmark_questions = pd.read_parquet("hf://datasets/openlifescienceai/medmcqa/" + splits["validation"])
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
question = f"{row['question']} Choices: {row['opa']}, {row['opb']}, {row['opc']}, {row['opd']}"
unanswered_questions[row['id']] = question
return unanswered_questions
def get_mmlu_questions(existing_qs, include_all, as_df):
"""
Returns MMLU benchmark questions
"""
benchmark_questions = pd.read_csv('benchmark_qs/mmlu.csv')
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
qid = row['id']
if qid in existing_qs:
continue
choices = row['choices']
question = row['question'] + " Choices: " + choices
unanswered_questions[row['id']] = question
return unanswered_questions
def get_arcc_questions(existing_qs, include_all, as_df):
"""
Returns ARC-Challenge benchmark questions
"""
splits = {'train': 'ARC-Challenge/train-00000-of-00001.parquet', 'test': 'ARC-Challenge/test-00000-of-00001.parquet', 'validation': 'ARC-Challenge/validation-00000-of-00001.parquet'}
benchmark_questions = pd.read_parquet("hf://datasets/allenai/ai2_arc/" + splits["train"])
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
qid = row['id']
if qid in existing_qs:
continue
choices = row['choices']
question = row['question'] + " Choices: " + choices
unanswered_questions[row['id']] = question
return unanswered_questions
def get_fever_questions(existing_qs, include_all, as_df):
"""
Returns FEVER 2024 benchmark questions
"""
file_path = "benchmark_qs/fever_2024.json"
with open(file_path, "r") as file:
benchmark_qs = json.load(file)
unanswered_questions = {}
for q in benchmark_qs:
id_val = q['id']
if include_all == False and id_val in existing_qs:
continue
unanswered_questions[id_val] = 'Claim: ' + q['claim'] + '\nWhich of these 4 categories should the claim be classified into: 1. supported, 2. refuted, 3. not enough evidence, 4. conflicting evidence?'
if as_df:
df = pd.DataFrame(list(unanswered_questions.items()), columns=["id", "question"])
return df
return unanswered_questions
def get_open_leaderboard_questions(existing_qs, include_all, as_df):
"""
Returns Open Leaderboard benchmark questions
"""
benchmark_questions = pd.read_csv("benchmark_qs/open_leaderboard.csv")
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
question = f"{row['question']}"
unanswered_questions[row['id']] = question
return unanswered_questions
def get_searchqa_questions(existing_qs, include_all, as_df):
"""
Returns SearchQA benchmark questions
"""
splits = {'train': 'data/train-00000-of-00001-55e7116bea868a35.parquet', 'validation': 'data/validation-00000-of-00001-2092e81367c2ca98.parquet'}
benchmark_questions = pd.read_parquet("hf://datasets/lucadiliello/searchqa/" + splits["train"])
benchmark_questions['id'] = benchmark_questions.index
print(benchmark_questions)
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
qid = row['id']
if qid in existing_qs:
continue
question = row['question']
unanswered_questions[row['id']] = question
return unanswered_questions
def get_web_questions(existing_qs, include_all, as_df):
"""
Returns Web Questions benchmark questions
"""
splits = {'train': 'data/train-00000-of-00001.parquet', 'test': 'data/test-00000-of-00001.parquet'}
benchmark_questions = pd.read_parquet("hf://datasets/Stanford/web_questions/" + splits["train"])
benchmark_questions['id'] = benchmark_questions.index
print(benchmark_questions)
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
qid = row['id']
if qid in existing_qs:
continue
question = row['question']
unanswered_questions[row['id']] = question
return unanswered_questions
def get_gpqa(existing_qs, include_all, as_df=False):
"""
Returns GPQA benchmark questions
"""
benchmark_questions = pd.read_csv("hf://datasets/Idavidrein/gpqa/gpqa_extended.csv")
benchmark_questions['id'] = benchmark_questions.index
print(benchmark_questions)
if not include_all:
benchmark_questions = benchmark_questions[~benchmark_questions['id'].isin(existing_qs)]
if as_df:
return benchmark_questions
unanswered_questions = {}
for ind, row in benchmark_questions.iterrows():
qid = row['id']
if qid in existing_qs:
continue
question = row['question']
unanswered_questions[row['id']] = question
return unanswered_questions
def get_qs(existing_qs, include_all, as_df=False):
"""
Returns benchmark questions based on command line argument
"""
benchmark = sys.argv[2]
if benchmark == "mmlu":
return get_mmlu_questions(existing_qs, include_all, as_df)
elif benchmark == "fever":
return get_fever_questions(existing_qs, include_all, as_df)
elif benchmark == "med":
return get_med_questions(existing_qs, include_all, as_df)
elif benchmark == "open":
return get_open_leaderboard_questions(existing_qs, include_all, as_df)
elif benchmark== "searchqa":
return get_searchqa_questions(existing_qs, include_all, as_df)
elif benchmark== "web":
return get_web_questions(existing_qs, include_all, as_df)
elif benchmark== "gpqa":
return get_gpqa(existing_qs, include_all, as_df)