skgouda commited on
Commit
6041021
·
verified ·
1 Parent(s): e3adead

Create mxeval.py

Browse files
Files changed (1) hide show
  1. mxeval.py +323 -0
mxeval.py ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import requests
4
+ import datasets
5
+
6
+ import os
7
+ from collections import defaultdict
8
+
9
+ _CITATION = """\
10
+ @article{mbxp_athiwaratkun2022,
11
+ title = {Multi-lingual Evaluation of Code Generation Models},
12
+ author = {Athiwaratkun, Ben and
13
+ Gouda, Sanjay Krishna and
14
+ Wang, Zijian and
15
+ Li, Xiaopeng and
16
+ Tian, Yuchen and
17
+ Tan, Ming
18
+ and Ahmad, Wasi Uddin and
19
+ Wang, Shiqi and
20
+ Sun, Qing and
21
+ Shang, Mingyue and
22
+ Gonugondla, Sujan Kumar and
23
+ Ding, Hantian and
24
+ Kumar, Varun and
25
+ Fulton, Nathan and
26
+ Farahani, Arash and
27
+ Jain, Siddhartha and
28
+ Giaquinto, Robert and
29
+ Qian, Haifeng and
30
+ Ramanathan, Murali Krishna and
31
+ Nallapati, Ramesh and
32
+ Ray, Baishakhi and
33
+ Bhatia, Parminder and
34
+ Sengupta, Sudipta and
35
+ Roth, Dan and
36
+ Xiang, Bing},
37
+ doi = {10.48550/ARXIV.2210.14868},
38
+ url = {https://arxiv.org/abs/2210.14868},
39
+ keywords = {Machine Learning (cs.LG), Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
40
+ publisher = {arXiv},
41
+ year = {2022},
42
+ copyright = {Creative Commons Attribution 4.0 International}
43
+ }"""
44
+
45
+ VERSION=f"1.1.0"
46
+
47
+ _HOMEPAGE = "https://github.com/amazon-science/mxeval"
48
+
49
+ _LICENSE = "Apache License 2.0"
50
+
51
+ _DESCRIPTION = """\
52
+ A collection of execution-based multi-lingual benchmark for code generation.
53
+ """
54
+
55
+ _LICENSES = defaultdict(lambda: _LICENSE)
56
+ _LICENSES["humaneval_python"] = "MIT License"
57
+ _LICENSES["mbxp_python"] = "CC-BY-4.0"
58
+
59
+ _CITATIONS = defaultdict(lambda: _CITATION)
60
+
61
+ _CITATIONS["multi-humaneval"] = """\
62
+ @article{mbxp_athiwaratkun2022,
63
+ title = {Multi-lingual Evaluation of Code Generation Models},
64
+ author = {Athiwaratkun, Ben and
65
+ Gouda, Sanjay Krishna and
66
+ Wang, Zijian and
67
+ Li, Xiaopeng and
68
+ Tian, Yuchen and
69
+ Tan, Ming
70
+ and Ahmad, Wasi Uddin and
71
+ Wang, Shiqi and
72
+ Sun, Qing and
73
+ Shang, Mingyue and
74
+ Gonugondla, Sujan Kumar and
75
+ Ding, Hantian and
76
+ Kumar, Varun and
77
+ Fulton, Nathan and
78
+ Farahani, Arash and
79
+ Jain, Siddhartha and
80
+ Giaquinto, Robert and
81
+ Qian, Haifeng and
82
+ Ramanathan, Murali Krishna and
83
+ Nallapati, Ramesh and
84
+ Ray, Baishakhi and
85
+ Bhatia, Parminder and
86
+ Sengupta, Sudipta and
87
+ Roth, Dan and
88
+ Xiang, Bing},
89
+ doi = {10.48550/ARXIV.2210.14868},
90
+ url = {https://arxiv.org/abs/2210.14868},
91
+ keywords = {Machine Learning (cs.LG), Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
92
+ publisher = {arXiv},
93
+ year = {2022},
94
+ copyright = {Creative Commons Attribution 4.0 International}
95
+ }
96
+ @misc{chen2021evaluating,
97
+ title={Evaluating Large Language Models Trained on Code},
98
+ author={Mark Chen and Jerry Tworek and Heewoo Jun and Qiming Yuan and Henrique Ponde de Oliveira Pinto and Jared Kaplan and Harri Edwards and Yuri Burda and Nicholas Joseph and Greg Brockman and Alex Ray and Raul Puri and Gretchen Krueger and Michael Petrov and Heidy Khlaaf and Girish Sastry and Pamela Mishkin and Brooke Chan and Scott Gray and Nick Ryder and Mikhail Pavlov and Alethea Power and Lukasz Kaiser and Mohammad Bavarian and Clemens Winter and Philippe Tillet and Felipe Petroski Such and Dave Cummings and Matthias Plappert and Fotios Chantzis and Elizabeth Barnes and Ariel Herbert-Voss and William Hebgen Guss and Alex Nichol and Alex Paino and Nikolas Tezak and Jie Tang and Igor Babuschkin and Suchir Balaji and Shantanu Jain and William Saunders and Christopher Hesse and Andrew N. Carr and Jan Leike and Josh Achiam and Vedant Misra and Evan Morikawa and Alec Radford and Matthew Knight and Miles Brundage and Mira Murati and Katie Mayer and Peter Welinder and Bob McGrew and Dario Amodei and Sam McCandlish and Ilya Sutskever and Wojciech Zaremba},
99
+ year={2021},
100
+ eprint={2107.03374},
101
+ archivePrefix={arXiv},
102
+ primaryClass={cs.LG}
103
+ }"""
104
+
105
+ _CITATIONS["mbxp"] = """\
106
+ @article{mbxp_athiwaratkun2022,
107
+ title = {Multi-lingual Evaluation of Code Generation Models},
108
+ author = {Athiwaratkun, Ben and
109
+ Gouda, Sanjay Krishna and
110
+ Wang, Zijian and
111
+ Li, Xiaopeng and
112
+ Tian, Yuchen and
113
+ Tan, Ming
114
+ and Ahmad, Wasi Uddin and
115
+ Wang, Shiqi and
116
+ Sun, Qing and
117
+ Shang, Mingyue and
118
+ Gonugondla, Sujan Kumar and
119
+ Ding, Hantian and
120
+ Kumar, Varun and
121
+ Fulton, Nathan and
122
+ Farahani, Arash and
123
+ Jain, Siddhartha and
124
+ Giaquinto, Robert and
125
+ Qian, Haifeng and
126
+ Ramanathan, Murali Krishna and
127
+ Nallapati, Ramesh and
128
+ Ray, Baishakhi and
129
+ Bhatia, Parminder and
130
+ Sengupta, Sudipta and
131
+ Roth, Dan and
132
+ Xiang, Bing},
133
+ doi = {10.48550/ARXIV.2210.14868},
134
+ url = {https://arxiv.org/abs/2210.14868},
135
+ keywords = {Machine Learning (cs.LG), Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
136
+ publisher = {arXiv},
137
+ year = {2022},
138
+ copyright = {Creative Commons Attribution 4.0 International}
139
+ }
140
+ @article{austin2021program,
141
+ title={Program Synthesis with Large Language Models},
142
+ author={Austin, Jacob and Odena, Augustus and Nye, Maxwell and Bosma, Maarten and Michalewski, Henryk and Dohan, David and Jiang, Ellen and Cai, Carrie and Terry, Michael and Le, Quoc and others},
143
+ journal={arXiv preprint arXiv:2108.07732},
144
+ year={2021}
145
+ }"""
146
+
147
+ _CITATIONS["mathqa-x"] = """\
148
+ @article{mbxp_athiwaratkun2022,
149
+ title = {Multi-lingual Evaluation of Code Generation Models},
150
+ author = {Athiwaratkun, Ben and
151
+ Gouda, Sanjay Krishna and
152
+ Wang, Zijian and
153
+ Li, Xiaopeng and
154
+ Tian, Yuchen and
155
+ Tan, Ming
156
+ and Ahmad, Wasi Uddin and
157
+ Wang, Shiqi and
158
+ Sun, Qing and
159
+ Shang, Mingyue and
160
+ Gonugondla, Sujan Kumar and
161
+ Ding, Hantian and
162
+ Kumar, Varun and
163
+ Fulton, Nathan and
164
+ Farahani, Arash and
165
+ Jain, Siddhartha and
166
+ Giaquinto, Robert and
167
+ Qian, Haifeng and
168
+ Ramanathan, Murali Krishna and
169
+ Nallapati, Ramesh and
170
+ Ray, Baishakhi and
171
+ Bhatia, Parminder and
172
+ Sengupta, Sudipta and
173
+ Roth, Dan and
174
+ Xiang, Bing},
175
+ doi = {10.48550/ARXIV.2210.14868},
176
+ url = {https://arxiv.org/abs/2210.14868},
177
+ keywords = {Machine Learning (cs.LG), Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
178
+ publisher = {arXiv},
179
+ year = {2022},
180
+ copyright = {Creative Commons Attribution 4.0 International}
181
+ }
182
+ @inproceedings{amini-etal-2019-mathqa,
183
+ title={MathQA: Towards Interpretable Math Word Problem Solving with Operation-Based Formalisms},
184
+ author={Amini, Aida and
185
+ Gabriel, Saadia and
186
+ Lin, Shanchuan and
187
+ Koncel-Kedziorski, Rik and
188
+ Choi, Yejin and
189
+ Hajishirzi, Hannaneh},
190
+ booktitle={Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers)},
191
+ month={jun},
192
+ year= {2019},
193
+ address = {Minneapolis, Minnesota},
194
+ publisher = {Association for Computational Linguistics},
195
+ url={https://aclanthology.org/N19-1245}
196
+ doi={10.18653/v1/N19-1245},
197
+ pages={2357--2367},
198
+ }
199
+ """
200
+
201
+ _DATASET_NAME_MAPPER = {
202
+ "mbxp": "mbxp",
203
+ "multi-humaneval": "multilingual_humaneval",
204
+ "mathqa-x": "multilingual_mathqa"
205
+ }
206
+
207
+ _GITHUB_ROOT = "https://raw.githubusercontent.com/amazon-science/mxeval/main/data/"
208
+
209
+
210
+ def get_metadata_dict(dataset):
211
+ metadata_dict_path = requests.get(os.path.join(_GITHUB_ROOT, dataset, "metadata.json"))
212
+ metadata = json.loads(metadata_dict_path.text)
213
+ return metadata
214
+
215
+
216
+ MBXP_LANGUAGES = get_metadata_dict("mbxp")
217
+
218
+ MATHQA_LANGUAGES = get_metadata_dict("multilingual_mathqa")
219
+
220
+ HUMANEVAL_LANGUAGES = get_metadata_dict("multilingual_humaneval")
221
+
222
+ _DATASET_LANGS = {
223
+ "multi-humaneval": HUMANEVAL_LANGUAGES,
224
+ "mathqa-x": MATHQA_LANGUAGES,
225
+ "mbxp": MBXP_LANGUAGES
226
+ }
227
+
228
+ _INTERNAL_DATASET_NAMES = {
229
+ "multi-humaneval": "multilingual_humaneval",
230
+ "mathqa-x": "multilingual_mathqa",
231
+ "mbxp": "mbxp"
232
+ }
233
+
234
+ _URL_DICT = {
235
+ f"{dataset.lower()}_{language.lower()}": os.path.join(
236
+ _GITHUB_ROOT,
237
+ _INTERNAL_DATASET_NAMES[dataset],
238
+ _DATASET_LANGS[dataset][language]
239
+ )
240
+ for dataset, languages in _DATASET_LANGS.items() for language in languages
241
+ }
242
+
243
+
244
+ class MxEvalConfig(datasets.BuilderConfig):
245
+ """BuilderConfig for MxEval."""
246
+
247
+ def __init__(
248
+ self,
249
+ dataset,
250
+ citation,
251
+ version,
252
+ **kwargs,
253
+ ):
254
+ super(MxEvalConfig, self).__init__(version=datasets.Version(f"{version}", ""), **kwargs)
255
+ self.dataset_name = dataset
256
+ self.data_dir = os.path.join(_GITHUB_ROOT, dataset)
257
+ self.citation = citation
258
+
259
+
260
+ class MxEval(datasets.GeneratorBasedBuilder):
261
+ """MxEval: An execution-based multiLingual benchmark for code generation."""
262
+
263
+ BUILDER_CONFIGS = [
264
+ MxEvalConfig(
265
+ name=f"{dataset}",
266
+ version=VERSION,
267
+ citation=_CITATIONS[f"{dataset}"],
268
+ dataset=_DATASET_NAME_MAPPER[dataset],
269
+ description=f"Benchmark for {dataset}",
270
+ ) for dataset in _DATASET_LANGS
271
+ ]
272
+
273
+ def _info(self):
274
+ self.build_name = self.name
275
+ features = datasets.Features(
276
+ {
277
+ "task_id": datasets.Value("string"),
278
+ "language": datasets.Value("string"),
279
+ "prompt": datasets.Value("string"),
280
+ "description": datasets.Value("string"),
281
+ "test": datasets.Value("string"),
282
+ "entry_point": datasets.Value("string"),
283
+ "canonical_solution": datasets.Value("string"),
284
+ }
285
+ )
286
+
287
+ return datasets.DatasetInfo(
288
+ description=_DESCRIPTION,
289
+ features=features,
290
+ supervised_keys=None,
291
+ homepage=_HOMEPAGE,
292
+ license=_LICENSES[self.config.name],
293
+ citation=_CITATIONS[self.config.name],
294
+ )
295
+
296
+
297
+ def _split_generators(
298
+ self, dl_manager
299
+ ):
300
+ """Returns SplitGenerators."""
301
+ return [
302
+ datasets.SplitGenerator(
303
+ name=datasets.Split(lang),
304
+ gen_kwargs={
305
+ "filepath": dl_manager.download_and_extract(
306
+ url_or_urls=_URL_DICT[f"{self.config.name}_{lang}"]
307
+ ),
308
+ },
309
+ ) for lang in _DATASET_LANGS[self.config.name]
310
+ ]
311
+
312
+
313
+ def _generate_examples(self, filepath):
314
+ """Yields examples."""
315
+ with open(filepath) as file:
316
+ data = []
317
+ for line in file:
318
+ jd = json.loads(line)
319
+ data.append(jd)
320
+ id_ = 0
321
+ for sample in data:
322
+ yield id_, sample
323
+ id_ += 1