0n1xus commited on
Commit
66232cd
1 Parent(s): 85f05fc

Add code-to-code-trans task

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. code-to-code-trans.zip +3 -0
  3. codexglue.py +166 -0
.gitattributes CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ code-to-code-trans.zip filter=lfs diff=lfs merge=lfs -text
code-to-code-trans.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91000596399aee3367aab5068452e1560ab131e2c0311f3ea367e692f46fb8ac
3
+ size 1169662
codexglue.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Wrapper for datasets in CodeXGLUE benchmark."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ _CITATION = """\
26
+ @article{Lu2021,
27
+ author = {Lu, Shuai and Guo, Daya and Ren, Shuo and Huang, Junjie and Svyatkovskiy, Alexey and Blanco, Ambrosio and Clement, Colin B. and Drain, Dawn and Jiang, Daxin and Tang, Duyu and Li, Ge and Zhou, Lidong and Shou, Linjun and Zhou, Long and Tufano, Michele and Gong, Ming and Zhou, Ming and Duan, Nan and Sundaresan, Neel and Deng, Shao Kun and Fu, Shengyu and Liu, Shujie},
28
+ year = {2021},
29
+ booktitle = {arXiv},
30
+ title = {CodeXGLUE - A Machine Learning Benchmark Dataset for Code Understanding and Generation}
31
+ }
32
+ """
33
+
34
+ _DESCRIPTION = """\
35
+ CodeXGLUE is a benchmark dataset to foster machine learning research for program understanding and generation.
36
+ CodeXGLUE includes a collection of 10 tasks across 14 datasets and a platform for model evaluation and comparison.
37
+ """
38
+
39
+ _HOMEPAGE = "https://microsoft.github.io/CodeXGLUE/"
40
+
41
+ _LICENSE = ""
42
+
43
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
44
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
45
+ _URLs = {
46
+ 'code-to-code-trans': "code-to-code-trans.zip"
47
+ }
48
+
49
+
50
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
51
+ class CodeXGLUE(datasets.GeneratorBasedBuilder):
52
+ """TODO: Short description of my dataset."""
53
+
54
+ VERSION = datasets.Version("1.0.0")
55
+
56
+ # This is an example of a dataset with multiple configurations.
57
+ # If you don't want/need to define several sub-sets in your dataset,
58
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
59
+
60
+ # If you need to make complex sub-parts in the datasets with configurable options
61
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
62
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
63
+
64
+ # You will be able to load one or the other configurations in the following list with
65
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
66
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
67
+ BUILDER_CONFIGS = [
68
+ datasets.BuilderConfig(name="code-to-code-trans", version=VERSION, description="Code-to-code/code-to-code-trans"),
69
+ ]
70
+
71
+ def _info(self):
72
+ if self.config.name == "code-to-code-trans": # This is the name of the configuration selected in BUILDER_CONFIGS above
73
+ features = datasets.Features(
74
+ {
75
+ "java_code": datasets.Value("string"),
76
+ "cs_code": datasets.Value("string")
77
+ }
78
+ )
79
+ else: # This is an example to show how to have different features for "first_domain" and "second_domain"
80
+ features = datasets.Features(
81
+ {
82
+ "sentence": datasets.Value("string"),
83
+ "option2": datasets.Value("string"),
84
+ "second_domain_answer": datasets.Value("string")
85
+ # These are the features of your dataset like images, labels ...
86
+ }
87
+ )
88
+ return datasets.DatasetInfo(
89
+ # This is the description that will appear on the datasets page.
90
+ description=_DESCRIPTION,
91
+ # This defines the different columns of the dataset and their types
92
+ features=features, # Here we define them above because they are different between the two configurations
93
+ # If there's a common (input, target) tuple from the features,
94
+ # specify them here. They'll be used if as_supervised=True in
95
+ # builder.as_dataset.
96
+ supervised_keys=None,
97
+ # Homepage of the dataset for documentation
98
+ homepage=_HOMEPAGE,
99
+ # License for the dataset if available
100
+ license=_LICENSE,
101
+ # Citation for the dataset
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(self, dl_manager):
106
+ """Returns SplitGenerators."""
107
+ # If several configurations are possible (listed in BUILDER_CONFIGS),
108
+ # the configuration selected by the user is in self.config.name
109
+
110
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
111
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with
112
+ # path to local files. By default the archives will be extracted and a path to a cached folder where they are
113
+ # extracted is returned instead of the archive
114
+ my_urls = _URLs[self.config.name]
115
+ data_dir = dl_manager.download_and_extract(my_urls)
116
+
117
+ if self.config.name == 'code-to-code-trans':
118
+ data_dir = os.path.join(data_dir, 'code-to-code-trans')
119
+ def get_kwargs(split_name: str):
120
+ return {
121
+ "data_paths": {
122
+ "java": os.path.join(data_dir, f'{split_name}.java-cs.txt.java'),
123
+ "cs": os.path.join(data_dir, f'{split_name}.java-cs.txt.cs'),
124
+ },
125
+ "split": split_name
126
+ }
127
+
128
+ return [
129
+ datasets.SplitGenerator(
130
+ name=datasets.Split.TRAIN,
131
+ # These kwargs will be passed to _generate_examples
132
+ gen_kwargs=get_kwargs('train')
133
+ ),
134
+ datasets.SplitGenerator(
135
+ name=datasets.Split.TEST,
136
+ # These kwargs will be passed to _generate_examples
137
+ gen_kwargs=get_kwargs('test')
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.VALIDATION,
141
+ # These kwargs will be passed to _generate_examples
142
+ gen_kwargs=get_kwargs('valid')
143
+ ),
144
+ ]
145
+
146
+ def _generate_examples(
147
+ self, data_paths, split
148
+ ):
149
+ """ Yields examples as (key, example) tuples. """
150
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
151
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
152
+
153
+ if self.config.name == 'code-to-code-trans':
154
+ java_path = data_paths['java']
155
+ cs_path = data_paths['cs']
156
+ with open(java_path, encoding="utf-8") as java_file:
157
+ with open(cs_path, encoding="utf-8") as cs_file:
158
+ java_lines = java_file.readlines()
159
+ cs_lines = cs_file.readlines()
160
+ for id_, (java_code, cs_code) in enumerate(zip(java_lines, cs_lines)):
161
+ java_code = java_code.strip()
162
+ cs_code = cs_code.strip()
163
+ yield id_, {
164
+ 'java_code': java_code,
165
+ 'cs_code': cs_code
166
+ }