File size: 2,748 Bytes
1f47868
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Odex dataset."""

import json
import datasets


_CITATION = """\
@article{wang2022execution,
  title={Execution-Based Evaluation for Open-Domain Code Generation},
  author={Wang, Zhiruo and Zhou, Shuyan and Fried, Daniel and Neubig, Graham},
  journal={arXiv preprint arXiv:2212.10481},
  year={2022}
}
"""

_DESCRIPTION = """\
ODEX is an Open-Domain EXecution-based NL-to-Code generation data benchmark. 
It contains 945 samples with a total of 1,707 human-written test cases, 
covering intents in four different natural languages -- 439 in English, 90 in Spanish, 164 in Japanese, and 252 in Russian.
"""

_HOMEPAGE = "https://github.com/zorazrw/odex"
_URLs = {
    "en": "en_test.jsonl",
    "es": "es_test.jsonl",
    "ja": "ja_test.jsonl",
    "ru": "ru_test.jsonl",
}

class Odex(datasets.GeneratorBasedBuilder):
    """ODEX Code dataset."""

    VERSION = datasets.Version("1.0.0")


    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=lang,
            version=datasets.Version("1.0.0"),
            description=_DESCRIPTION,
        ) for lang in _URLs.keys()
    ]

    DEFAULT_CONFIG_NAME = "en"
    
    
    def _info(self):
        features = datasets.Features({"task_id": datasets.Value("int64"),
                                        "prompt": datasets.Value("string"),
                                        "suffix": datasets.Value("string"),
                                        "canonical_solution": datasets.Value("string"),
                                        "test_start": datasets.Value("string"),
                                        "test": datasets.Sequence(datasets.Value("string")),
                                        "entry_point": datasets.Value("string"),
                                        "intent": datasets.Value("string"),
                                        "library": datasets.Sequence(datasets.Value("string")),
                                        })
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            citation=_CITATION,
            homepage=_HOMEPAGE)

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        config_urls = _URLs[self.config.name]
        data_dir = dl_manager.download_and_extract(config_urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"filepath": data_dir, "split": "train"},
            ),
            ]


    def _generate_examples(self, filepath, split):
        key = 0
        for line in open(filepath, encoding="utf-8"):
            line = json.loads(line)
            yield key, line   
            key += 1