Datasets:

Languages:
English
ArXiv:
Tags:
code
License:
File size: 5,277 Bytes
7843013
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcc5259
7843013
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0749511
 
 
 
 
 
5fc724b
 
 
0749511
7843013
 
0749511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fc724b
 
 
 
 
 
 
 
 
0749511
 
 
 
 
 
 
 
 
5fc724b
 
0749511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7843013
 
 
0749511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json

import datasets

_DESCRIPTION = """The MBPP dataset in BabelCode format."""

_URL = "https://raw.githubusercontent.com/google-research/babelcode/main/data/hf_datasets/mbpp.jsonl"

_LANGUAGES = {
    "C++",
    "CSharp",
    "Dart",
    "Go",
    "Haskell",
    "Java",
    "Javascript",
    "Julia",
    "Kotlin",
    "Lua",
    "PHP",
    "Python",
    "R",
    "Rust",
    "Scala",
    "TypeScript",
}

_CITATION = """\
@article{orlanski2023measuring,
  title={Measuring The Impact Of Programming Language Distribution},
  author={Orlanski, Gabriel and Xiao, Kefan and Garcia, Xavier and Hui, Jeffrey and Howland, Joshua and Malmaud, Jonathan and Austin, Jacob and Singh, Rishah and Catasta, Michele},
  journal={arXiv preprint arXiv:2302.01973},
  year={2023}
}
@article{Austin2021ProgramSW,
  title={Program Synthesis with Large Language Models},
  author={Jacob Austin and Augustus Odena and Maxwell Nye and Maarten Bosma and Henryk Michalewski and David Dohan and Ellen Jiang and Carrie J. Cai and Michael Terry and Quoc V. Le and Charles Sutton},
  journal={ArXiv},
  year={2021},
  volume={abs/2108.07732}
}"""

_HOMEPAGE = "https://github.com/google-research/babelcode"

_LICENSE = "CC-BY-4.0"

_VERSION = "1.0.0"

_QUESTION_INFO_KEYS = {
    "entry_fn_name",
    "entry_cls_name",
    "test_code",
    "test_list",
    "test_case_ids",
    "commands",
    "timeouts",
    "extension"
}

class BCMBPP(datasets.GeneratorBasedBuilder):
  """BC-MBPP"""

  VERSION = datasets.Version(_VERSION)

  BUILDER_CONFIGS = [
      datasets.BuilderConfig(
          name="all",
          version=datasets.Version(_VERSION),
          description=_DESCRIPTION,
      ),
  ] + [
      datasets.BuilderConfig(
          name=lang,
          version=datasets.Version(_VERSION),
          description=_DESCRIPTION + f" Examples are only in {lang}.",
      ) for lang in _LANGUAGES
  ]

  DEFAULT_CONFIG_NAME = "all"

  def _info(self):
    list_keys = ['timeouts', 'commands', 'test_case_ids']
    question_info_type = {
                k:datasets.Value(dtype="string")
                for k in _QUESTION_INFO_KEYS if k not in list_keys
            }
    question_info_type['test_case_ids'] = datasets.Sequence(datasets.Value('string'))
    question_info_type['commands'] = datasets.Sequence(datasets.Sequence(datasets.Value('string')))
    question_info_type['timeouts'] = datasets.Sequence(datasets.Value('int32'))
    
    features = datasets.Features({
        "qid": datasets.Value("string"),
        "title": datasets.Value("string"),
        "language": datasets.Value("string"),
        "text": datasets.Value("string"),
        "signature_with_docstring": datasets.Value("string"),
        "signature": datasets.Value("string"),
        "arguments": datasets.Sequence(datasets.Value("string")),
        "solution": datasets.Value("string"),
        "question_info": datasets.Features(question_info_type)
            
    })
    description = _DESCRIPTION
    if self.config.name != 'all':
      description = _DESCRIPTION + f" Examples are only in {self.config.name}."
    return datasets.DatasetInfo(
        description=description,
        features=features,
        supervised_keys=None,
        homepage=_HOMEPAGE,
        license=_LICENSE,
        citation=_CITATION,
    )

  def _split_generators(self, dl_manager):
    """Returns SplitGenerators."""
    data_dir = dl_manager.download_and_extract(_URL)
    return [
        datasets.SplitGenerator(
            name=datasets.Split.TRAIN,
            gen_kwargs={
                "filepath": data_dir,
                "split": "train"
            },
        ),
        datasets.SplitGenerator(
            name=datasets.Split.TEST,
            gen_kwargs={
                "filepath": data_dir,
                "split": "test"
            },
        ),
        datasets.SplitGenerator(
            name=datasets.Split.VALIDATION,
            gen_kwargs={
                "filepath": data_dir,
                "split": "validation"
            },
        ),
        datasets.SplitGenerator(
            name=datasets.Split("prompt"),
            gen_kwargs={
                "filepath": data_dir,
                "split": "prompt"
            },
        ),
    ]

  def _generate_examples(self, filepath, split):
    """ Yields the examples from the dataset"""
    with open(filepath, encoding='utf-8') as file:
      id_ = 0
      idx_range = None
      if split == 'test':
        idx_range = (11, 510)
      elif split == "train":
        idx_range = (601, 974)
      elif split == "validation":
        idx_range = (511, 600)
      else:
        idx_range = (1, 10)

      for l in file:
        if not l.strip():
          continue
        d = json.loads(l)

        if self.config.name != 'all' and d['language'] != self.config.name:
          continue

        idx = int(d['title'].split('/')[-1])
        if not (idx_range[0] <= idx <= idx_range[1]):
          continue
        
        question_info = {}
        for k in _QUESTION_INFO_KEYS:
          question_info[k] = d.pop(k)
        
        question_info['test_list'] = json.dumps(question_info['test_list'])

        d['question_info'] = question_info

        d['solution'] = d.pop('solution_python')
        yield id_, d
        id_ += 1