Datasets:

Modalities:
Text
ArXiv:
Tags:
code
Libraries:
Datasets
License:
tianyang commited on
Commit
5b9f5fd
1 Parent(s): 2706ded

upload data config file

Browse files
Files changed (2) hide show
  1. repobench-c.py +169 -0
  2. utils.py +16 -0
repobench-c.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """RepoBench: Benchmarking Repository-Level Code Auto-Completion Systems"""
16
+
17
+ import gzip
18
+ import pickle
19
+ import textwrap
20
+ import datasets
21
+ from utils import construct_prompt
22
+
23
+ _CITATION = """\
24
+ @misc{liu2023repobench,
25
+ title={RepoBench: Benchmarking Repository-Level Code Auto-Completion Systems},
26
+ author={Tianyang Liu and Canwen Xu and Julian McAuley},
27
+ year={2023},
28
+ eprint={2306.03091},
29
+ archivePrefix={arXiv},
30
+ primaryClass={cs.CL}
31
+ }
32
+ """
33
+
34
+ _DESCRIPTION = """\
35
+ RepoBench is a dataset that benchmarks repository-level code auto-completion systems.
36
+
37
+ RepoBench-C denotes RepoBench for code completion,
38
+ which is subtask of RepoBench for next-line code prediction given both cross-file and in-file context.
39
+ """
40
+
41
+ _HOMEPAGE = "https://github.com/Leolty/repobench"
42
+
43
+ _LICENSE = "Apache License 2.0"
44
+
45
+ _URLs = {
46
+ "python_cff": "https://raw.githubusercontent.com/Leolty/repobench/main/data/code_completion/python/cross_file_first.gz",
47
+ "python_cfr": "https://raw.githubusercontent.com/Leolty/repobench/main/data/code_completion/python/cross_file_random.gz",
48
+ "python_if": "https://raw.githubusercontent.com/Leolty/repobench/main/data/code_completion/python/in_file.gz",
49
+ "java_cff": "https://raw.githubusercontent.com/Leolty/repobench/main/data/code_completion/java/cross_file_first.gz",
50
+ "java_cfr": "https://raw.githubusercontent.com/Leolty/repobench/main/data/code_completion/java/cross_file_random.gz",
51
+ "java_if": "https://raw.githubusercontent.com/Leolty/repobench/main/data/code_completion/java/in_file.gz"
52
+ }
53
+
54
+ class RepoBenchR(datasets.GeneratorBasedBuilder):
55
+ """RepoBench"""
56
+
57
+ VERSION = datasets.Version("1.0.0")
58
+
59
+ BUILDER_CONFIGS = [
60
+ datasets.BuilderConfig(
61
+ name="python_cff",
62
+ description=textwrap.dedent(
63
+ """
64
+ cff: cross_file_first -> mask the the line that a cross-file module is first used
65
+ """
66
+ )
67
+ ),
68
+ datasets.BuilderConfig(
69
+ name="python_cfr",
70
+ description=textwrap.dedent(
71
+ """
72
+ cfr: cross_file_random -> mask a random line that a cross-file module is used (not the first time)
73
+ """
74
+ )
75
+ ),
76
+ datasets.BuilderConfig(
77
+ name="python_if",
78
+ description=textwrap.dedent(
79
+ """
80
+ if: in_file -> mask a random line with no cross-file module
81
+ """
82
+ )
83
+ ),
84
+ datasets.BuilderConfig(
85
+ name="java_cff",
86
+ description=textwrap.dedent(
87
+ """
88
+ cff: cross_file_first -> mask the the line that a cross-file module is first used
89
+ """
90
+ )
91
+ ),
92
+ datasets.BuilderConfig(
93
+ name="java_cfr",
94
+ description=textwrap.dedent(
95
+ """
96
+ cfr: cross_file_random -> mask a random line that a cross-file module is used (not the first time)
97
+ """
98
+ )
99
+ ),
100
+ datasets.BuilderConfig(
101
+ name="java_if",
102
+ description=textwrap.dedent(
103
+ """
104
+ if: in_file -> mask a random line with no cross-file module
105
+ """
106
+ )
107
+ )
108
+ ]
109
+
110
+ def _info(self):
111
+ features = datasets.Features(
112
+ {
113
+ "repo_name": datasets.Value("string"),
114
+ "file_path": datasets.Value("string"),
115
+ "context": datasets.Sequence(datasets.Value("string")),
116
+ "import_statement": datasets.Value("string"),
117
+ "code": datasets.Value("string"),
118
+ "prompt": datasets.Value("string"),
119
+ "next_line": datasets.Value("string")
120
+ }
121
+ )
122
+
123
+ return datasets.DatasetInfo(
124
+ description=_DESCRIPTION,
125
+ features=features,
126
+ homepage=_HOMEPAGE,
127
+ license=_LICENSE,
128
+ citation=_CITATION,
129
+ )
130
+
131
+ def _split_generators(self, dl_manager):
132
+ """Returns SplitGenerators."""
133
+ config_urls = _URLs[self.config.name]
134
+ data_dir = dl_manager.download(config_urls)
135
+
136
+ return [
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split("train"),
139
+ gen_kwargs={"data_dir": data_dir, "split": "train"},
140
+ ),
141
+ datasets.SplitGenerator(
142
+ name=datasets.Split("dev"),
143
+ gen_kwargs={"data_dir": data_dir, "split": "dev"},
144
+ ),
145
+ datasets.SplitGenerator(
146
+ name=datasets.Split("test"),
147
+ gen_kwargs={"data_dir": data_dir, "split": "test"},
148
+ )
149
+ ]
150
+
151
+ def _generate_examples(self, data_dir, split):
152
+ """ Yields examples. """
153
+ with gzip.open(data_dir, "rb") as f:
154
+ data = pickle.load(f)
155
+
156
+ for i, example in enumerate(data[split]):
157
+
158
+ prompt = construct_prompt(example, self.config.name.split("_")[0])
159
+
160
+ yield i, {
161
+ "repo_name": example["repo_name"],
162
+ "file_path": example["file_path"],
163
+ "context": example["context"],
164
+ "import_statement": example["import_statement"],
165
+ "code": example["code"],
166
+ "prompt": prompt,
167
+ "next_line": example["next_line"]
168
+ }
169
+
utils.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ def construct_prompt(data_point:dict, language:str):
3
+
4
+ if language == "python":
5
+ path = f"# Path: {data_point['file_path']}"
6
+
7
+ elif language == "java":
8
+ path = f"// Path: {data_point['file_path']}"
9
+
10
+ prompt = f"""{data_point['context']}
11
+ {path}
12
+ {data_point['import_statement']}
13
+
14
+ {data_point['code']}"""
15
+
16
+ return prompt