Datasets:

Modalities:
Text
Languages:
English
ArXiv:
Tags:
code
Libraries:
Datasets
License:
gabeorlanski commited on
Commit
d621d88
·
1 Parent(s): 3105f7f

Update tp3.py

Browse files
Files changed (1) hide show
  1. tp3.py +72 -80
tp3.py CHANGED
@@ -2,7 +2,6 @@ import json
2
 
3
  import datasets
4
 
5
-
6
  _DESCRIPTION = """Translating Python Programming Puzzles (TP3) is a code translation benchmark created from the verification functions from the questions in the original Python Programming Puzzles dataset (Schuster et al., 2021) to create this dataset. These functions are hand-crafted by the authors and are used to check if an answer satisfies the constraints of the puzzle. These puzzles range in difficulty from basic character checking to competitive programming problems. Thus, each verification function is written by an expert python programmer and requires a significant understanding of programming to translate. In total, there are 370 python functions to translate."""
7
 
8
  _URL = "https://raw.githubusercontent.com/google-research/babelcode/main/data/hf_datasets/tp3.jsonl"
@@ -47,87 +46,80 @@ _LICENSE = "CC-BY-4.0"
47
 
48
  _VERSION = "1.0.0"
49
 
50
- _KEYS_REMOVE = {
51
- "header"
52
- }
53
 
54
  class TP3(datasets.GeneratorBasedBuilder):
55
- """TP3"""
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
- "text":datasets.Value("string"),
83
- "signature_with_docstring": datasets.Value("string"),
84
- "signature": datasets.Value("string"),
85
- "arguments": datasets.Sequence(datasets.Value("string")),
86
- "entry_fn_name": datasets.Value("string"),
87
- "entry_cls_name": datasets.Value("string"),
88
- "test_code": datasets.Value("string"),
89
- "source":datasets.Value("string")
90
- }
91
- )
92
- description = _DESCRIPTION
93
- if self.config.name != 'all':
94
- description = _DESCRIPTION + f" Examples are only in {self.config.name}."
95
- return datasets.DatasetInfo(
96
- description=description,
97
- features=features,
98
- supervised_keys=None,
99
- homepage=_HOMEPAGE,
100
- license=_LICENSE,
101
- citation=_CITATION,
102
- )
103
-
104
- def _split_generators(self, dl_manager):
105
- """Returns SplitGenerators."""
106
- data_dir = dl_manager.download_and_extract(_URL)
107
- return [
108
- datasets.SplitGenerator(
109
- name=datasets.Split.TEST,
110
- gen_kwargs={"filepath": data_dir},
111
- ),
112
- ]
113
-
114
- def _generate_examples(self, filepath):
115
- """ Yields the examples from the dataset"""
116
- with open(filepath, encoding='utf-8') as file:
117
- id_ = 0
118
- for l in file:
119
- if not l.strip():
120
- continue
121
- d = json.loads(l)
122
-
123
- if self.config.name != 'all' and d['language'] != self.config.name:
124
- continue
125
-
126
- d['source'] = d.pop('solution_python')
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 = """Translating Python Programming Puzzles (TP3) is a code translation benchmark created from the verification functions from the questions in the original Python Programming Puzzles dataset (Schuster et al., 2021) to create this dataset. These functions are hand-crafted by the authors and are used to check if an answer satisfies the constraints of the puzzle. These puzzles range in difficulty from basic character checking to competitive programming problems. Thus, each verification function is written by an expert python programmer and requires a significant understanding of programming to translate. In total, there are 370 python functions to translate."""
6
 
7
  _URL = "https://raw.githubusercontent.com/google-research/babelcode/main/data/hf_datasets/tp3.jsonl"
 
46
 
47
  _VERSION = "1.0.0"
48
 
 
 
 
49
 
50
  class TP3(datasets.GeneratorBasedBuilder):
51
+ """TP3"""
52
+
53
+ VERSION = datasets.Version(_VERSION)
54
+
55
+ BUILDER_CONFIGS = [
56
+ datasets.BuilderConfig(
57
+ name="all",
58
+ version=datasets.Version(_VERSION),
59
+ description=_DESCRIPTION,
60
+ ),
61
+ ] + [
62
+ datasets.BuilderConfig(
63
+ name=lang,
64
+ version=datasets.Version(_VERSION),
65
+ description=_DESCRIPTION + f" Examples are only in {lang}.",
66
+ ) for lang in _LANGUAGES
67
+ ]
68
+
69
+ DEFAULT_CONFIG_NAME = "all"
70
+
71
+ def _info(self):
72
+ features = datasets.Features({
73
+ "qid": datasets.Value("string"),
74
+ "title": datasets.Value("string"),
75
+ "language": datasets.Value("string"),
76
+ "text": datasets.Value("string"),
77
+ "signature_with_docstring": 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": datasets.Value("string"),
84
+ "test_list": datasets.Value("string"),
85
+ "test_case_ids": datasets.Sequence(datasets.Value("string"))
86
+ })
87
+ description = _DESCRIPTION
88
+ if self.config.name != 'all':
89
+ description = _DESCRIPTION + f" Examples are only in {self.config.name}."
90
+ return datasets.DatasetInfo(
91
+ description=description,
92
+ features=features,
93
+ supervised_keys=None,
94
+ homepage=_HOMEPAGE,
95
+ license=_LICENSE,
96
+ citation=_CITATION,
97
+ )
98
+
99
+ def _split_generators(self, dl_manager):
100
+ """Returns SplitGenerators."""
101
+ data_dir = dl_manager.download_and_extract(_URL)
102
+ return [
103
+ datasets.SplitGenerator(
104
+ name=datasets.Split.TEST,
105
+ gen_kwargs={"filepath": data_dir},
106
  ),
 
 
 
 
 
 
 
107
  ]
108
 
109
+ def _generate_examples(self, filepath):
110
+ """ Yields the examples from the dataset"""
111
+ with open(filepath, encoding='utf-8') as file:
112
+ id_ = 0
113
+ for l in file:
114
+ if not l.strip():
115
+ continue
116
+ d = json.loads(l)
117
+
118
+ if self.config.name != 'all' and d['language'] != self.config.name:
119
+ continue
120
+
121
+ d['test_list'] = json.dumps(d['test_list'])
122
+ d['source'] = d.pop('solution_python')
123
+
124
+ yield id_, d
125
+ id_ += 1