Datasets:

Modalities:
Text
Languages:
English
ArXiv:
Tags:
code
Libraries:
Datasets
License:
gabeorlanski commited on
Commit
0713411
1 Parent(s): d9b4a3c

Upload tp3.py

Browse files
Files changed (1) hide show
  1. tp3.py +133 -0
tp3.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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"
9
+
10
+ _LANGUAGES = {
11
+ "C++",
12
+ "CSharp",
13
+ "Dart",
14
+ "Go",
15
+ "Haskell",
16
+ "Java",
17
+ "Javascript",
18
+ "Julia",
19
+ "Kotlin",
20
+ "Lua",
21
+ "PHP",
22
+ "R",
23
+ "Rust",
24
+ "Scala",
25
+ "TypeScript",
26
+ }
27
+
28
+ _CITATION = """\
29
+ @article{orlanski2023measuring,
30
+ title={Measuring The Impact Of Programming Language Distribution},
31
+ 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},
32
+ journal={arXiv preprint arXiv:2302.01973},
33
+ year={2023}
34
+ }
35
+ @inproceedings{
36
+ schuster2021programming,
37
+ title={Programming Puzzles},
38
+ author={Tal Schuster and Ashwin Kalyan and Alex Polozov and Adam Tauman Kalai},
39
+ booktitle={Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track},
40
+ year={2021},
41
+ url={https://arxiv.org/abs/2106.05784}
42
+ }"""
43
+
44
+ _HOMEPAGE = "https://github.com/google-research/babelcode"
45
+
46
+ _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
+