Datasets:

Modalities:
Text
Languages:
English
ArXiv:
Tags:
code
Libraries:
Datasets
License:
gabeorlanski commited on
Commit
855893f
1 Parent(s): 87dc8cb

Update bc-transcoder.py

Browse files
Files changed (1) hide show
  1. bc-transcoder.py +78 -80
bc-transcoder.py CHANGED
@@ -2,7 +2,6 @@ import json
2
 
3
  import datasets
4
 
5
-
6
  _DESCRIPTION = """The Transcoder dataset in BabelCode format. Currently supports translation from C++ and Python."""
7
 
8
  _URL = "https://raw.githubusercontent.com/google-research/babelcode/main/data/hf_datasets/transcoder.jsonl"
@@ -47,87 +46,86 @@ _LICENSE = "CC-BY-4.0"
47
 
48
  _VERSION = "1.0.0"
49
 
50
- _KEYS_REMOVE = {
51
- "header", "text", "signature_with_docstring"
52
- }
53
 
54
- class BCTranscoder(datasets.GeneratorBasedBuilder):
55
- """BC-Transcoder"""
56
 
57
- VERSION = datasets.Version(_VERSION)
58
-
59
- BUILDER_CONFIGS = [
60
- datasets.BuilderConfig(
61
- name="all",
62
- version=datasets.Version(_VERSION),
63
- description=_DESCRIPTION,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  ),
65
- ] + [
66
- datasets.BuilderConfig(
67
- name=lang,
68
- version=datasets.Version(_VERSION),
69
- description=_DESCRIPTION + f" Examples are only in {lang}.",
70
- )
71
- for lang in _LANGUAGES
72
  ]
73
 
74
- DEFAULT_CONFIG_NAME = "all"
75
-
76
- def _info(self):
77
- features = datasets.Features(
78
- {
79
- "qid": datasets.Value("string"),
80
- "title": datasets.Value("string"),
81
- "language": datasets.Value("string"),
82
- "signature": datasets.Value("string"),
83
- "arguments": datasets.Sequence(datasets.Value("string")),
84
- "entry_fn_name": datasets.Value("string"),
85
- "entry_cls_name": datasets.Value("string"),
86
- "test_code": datasets.Value("string"),
87
- "source_py":datasets.Value("string"),
88
- "source_cpp":datasets.Value("string")
89
- }
90
- )
91
- description = _DESCRIPTION
92
- if self.config.name != 'all':
93
- description = _DESCRIPTION + f" Examples are only in {self.config.name}."
94
- return datasets.DatasetInfo(
95
- description=description,
96
- features=features,
97
- supervised_keys=None,
98
- homepage=_HOMEPAGE,
99
- license=_LICENSE,
100
- citation=_CITATION,
101
- )
102
-
103
- def _split_generators(self, dl_manager):
104
- """Returns SplitGenerators."""
105
- data_dir = dl_manager.download_and_extract(_URL)
106
- return [
107
- datasets.SplitGenerator(
108
- name=datasets.Split.TEST,
109
- gen_kwargs={"filepath": data_dir},
110
- ),
111
- ]
112
-
113
- def _generate_examples(self, filepath):
114
- """ Yields the examples from the dataset"""
115
- with open(filepath, encoding='utf-8') as file:
116
- id_ = 0
117
- for l in file:
118
- if not l.strip():
119
- continue
120
- d = json.loads(l)
121
-
122
- if self.config.name != 'all' and d['language'] != self.config.name:
123
- continue
124
-
125
- d['source_py'] = d.pop('solution_python')
126
- d['source_cpp'] = d.pop('solution_cpp')
127
-
128
- for k in _KEYS_REMOVE:
129
- d.pop(k)
130
- yield id_, d
131
- id_+=1
132
-
133
-
 
2
 
3
  import datasets
4
 
 
5
  _DESCRIPTION = """The Transcoder dataset in BabelCode format. Currently supports translation from C++ and Python."""
6
 
7
  _URL = "https://raw.githubusercontent.com/google-research/babelcode/main/data/hf_datasets/transcoder.jsonl"
 
46
 
47
  _VERSION = "1.0.0"
48
 
49
+ _KEYS_REMOVE = {"text", "signature_with_docstring"}
 
 
50
 
 
 
51
 
52
+ class BCTranscoder(datasets.GeneratorBasedBuilder):
53
+ """BC-Transcoder"""
54
+
55
+ VERSION = datasets.Version(_VERSION)
56
+
57
+ BUILDER_CONFIGS = [
58
+ datasets.BuilderConfig(
59
+ name="all",
60
+ version=datasets.Version(_VERSION),
61
+ description=_DESCRIPTION,
62
+ ),
63
+ ] + [
64
+ datasets.BuilderConfig(
65
+ name=lang,
66
+ version=datasets.Version(_VERSION),
67
+ description=_DESCRIPTION + f" Examples are only in {lang}.",
68
+ ) for lang in _LANGUAGES
69
+ ]
70
+
71
+ DEFAULT_CONFIG_NAME = "all"
72
+
73
+ def _info(self):
74
+ features = datasets.Features({
75
+ "qid": datasets.Value("string"),
76
+ "title": datasets.Value("string"),
77
+ "language": datasets.Value("string"),
78
+ "signature": datasets.Value("string"),
79
+ "arguments": datasets.Sequence(datasets.Value("string")),
80
+ "entry_fn_name": datasets.Value("string"),
81
+ "entry_cls_name": datasets.Value("string"),
82
+ "test_code": datasets.Value("string"),
83
+ "source_py": datasets.Value("string"),
84
+ "source_cpp": datasets.Value("string"),
85
+ "test_list": datasets.Value("string"),
86
+ "test_case_ids":datasets.Sequence(datasets.Value("string"))
87
+ })
88
+ description = _DESCRIPTION
89
+ if self.config.name != 'all':
90
+ description = _DESCRIPTION + f" Examples are only in {self.config.name}."
91
+ return datasets.DatasetInfo(
92
+ description=description,
93
+ features=features,
94
+ supervised_keys=None,
95
+ homepage=_HOMEPAGE,
96
+ license=_LICENSE,
97
+ citation=_CITATION,
98
+ )
99
+
100
+ def _split_generators(self, dl_manager):
101
+ """Returns SplitGenerators."""
102
+ data_dir = dl_manager.download_and_extract(_URL)
103
+ return [
104
+ datasets.SplitGenerator(
105
+ name=datasets.Split.TEST,
106
+ gen_kwargs={"filepath": data_dir},
107
  ),
 
 
 
 
 
 
 
108
  ]
109
 
110
+ def _generate_examples(self, filepath):
111
+ """ Yields the examples from the dataset"""
112
+ with open(filepath, encoding='utf-8') as file:
113
+ id_ = 0
114
+ for l in file:
115
+ if not l.strip():
116
+ continue
117
+ d = json.loads(l)
118
+
119
+ if self.config.name != 'all' and d['language'] != self.config.name:
120
+ continue
121
+
122
+
123
+ d['test_list'] = json.dumps(d['test_list'])
124
+
125
+ d['source_py'] = d.pop('solution_python')
126
+ d['source_cpp'] = d.pop('solution_cpp')
127
+
128
+ for k in _KEYS_REMOVE:
129
+ d.pop(k)
130
+ yield id_, d
131
+ id_ += 1