Datasets:
ArXiv:
License:
| # Copyright 2020 The HuggingFace Datasets Authors and Serivce Now Authors. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| """This is a loading script for the Stack-Repo dataset""" | |
| import csv | |
| import json | |
| import os | |
| from pathlib import Path | |
| import datasets | |
| _CITATION = """\ | |
| @article{shrivastava2023repofusion, | |
| title={RepoFusion: Training Code Models to Understand Your Repository}, | |
| author={Shrivastava, Disha and Kocetkov, Denis and de Vries, Harm and Bahdanau, Dzmitry and Scholak, Torsten}, | |
| journal={arXiv preprint arXiv:2306.10998}, | |
| year={2023} | |
| } | |
| """ | |
| _DESCRIPTION = """\ | |
| This is the Stack-Repo dataset | |
| """ | |
| _HOMEPAGE = "https://huggingface.co/datasets/RepoFusion/Stack-Repo" | |
| _LICENSE = "other" | |
| _SOURCES = { | |
| 'test': [ | |
| 'thekoc', 'JellyBrother', 'shuli495', 'xiao-ren-wu', 'UzcDevelopmentTeam', 'Penguinz22', 'andrewvmail', | |
| 'richard-trotter', 'SlimPay', 'teknux-org', 'FIXTradingCommunity', 'Juliana-Felipe', 'exasol', 'iBiber', | |
| 'sebaslogen', 'billmcchesney1', 'ms-showcase', 'mP1', 'yokotaso', 'ErikHage', 'shadaileng', 'regular-project', | |
| 'wiwilin', '1273091433', 'liangxiong3403', 'wangzlei', 'Vitaliy-Yakovchuk', 'anshul-mohil', 'MarceloCavassani', | |
| 'cwhelan', 'score-server', 'meyer5', 'SeSac-Cloud-Backend-4', 'Hugo-Gao', 'Olivia0202', 'IceIce1ce', '4pxzhou', | |
| 'bboylin', 'acolebourne', '1725762388', 'iViolinSolo', 'diaolingzc', 'trungtuan', 'havenmoney', 'speak2me', | |
| 'VincenzoArceri', 'exadel-inc', 'JohnReeson', 'CyiceK', 'Vooy' | |
| ], | |
| 'train': [ | |
| 'ValeriyKnyazhev', 'leshiv', 'MfromAzeroth', 'wugjin', 'MarbleDice', 'hivijayreddy', 'sidpatel-github', | |
| 'hellorizon', 'CreativePenguin', 'maulikpandey', 'a630140621', 'luminiusa', 'ot-maksim', 'akash-coded', | |
| 'eddiewgj', 'a616707902', 'oasis9', 'DeyanZhelyazkov', 'yweng47', 'JCThePants', 'Gorlem', 'dongjihui666', | |
| 'mediatrue', 'david2999999', 'comme-il-faut', 'jannal', 'tfjybj', 'DimkaGorhover', 'ZhangTizo', 'CIDARLAB', | |
| 'DwArFeng', 'mbarkley', 'VladRomanchuk', 'vivekmalhotragithub', 'android-little-boy', 'patrik999', 'madanalogy', | |
| 'TheTrueColonel', 'TreeZhiyuan', 'sistcoop', 'java-ea', 'DarwinReforged', 'DougEdey', '402d', 'wangdingfeng', | |
| 'WeiziPlus', 'fabionery', 'famartinrh', 'rghvgrv', 'QuincySx', 'raphaelcohn', 'hYdos', 'tacticalrce', | |
| 'danielkrajnik', 'SeanDecker1', 'bahaahussein', 'Team1772', 'zengfanmao', 'Hopp-Stu', 'My-DIGI-ID', 'slickqa', | |
| 'opentok', 'Manolomon', 'denhatmong', 'baishuo', 'zli78122', 'kenichi-ando', 'pengcash', 'Princelo', | |
| 'RuthDirnfeld', 'HRI-EU', 'jan438', 'sd2438892', 'rsofista', 'mpsitech', 'AvaN0x', 'JDode', 'dreadwail', | |
| 'pcjs156', 'MrWe', 'smallxiongxiong', 'wuxinlingluan', 'FLxmw', 'TransFICC', 'fengpod', 'orient33', 'hamsterxc', | |
| 'diegolemospadilha', 'CheRut', 'ToreAad', 'AndrewHYC', 'Azagwen', 'Ndivhuwo', 'gou02rav32', 'CDZR0', | |
| 'MFunction96', 'google', 'mariodavid', 'jacksontenorio8', 'DieguinhoHR' | |
| ], | |
| 'val': [ | |
| 'malcolmgreaves', 'atlasapi', 'HeXavi8', 'fank243', 'StealWonders', 'asyakasimova', 'truthiswill', | |
| 'swiatecki', 'yanjingfan', 'vamnoize', 'Eugenemdk', 'explodingnuggets', 'MartinItsLinda', | |
| 'Web-Programmer-B-P', 'SergeyZhernovoy', 'sunhaidong', 'marcogrella', 'C0DEC0L0NY', 'JustinZuidgeest', | |
| 'ShareWiFi', 'ConusDaktis', 'lqhshishen', 'vaginessa', 'Juansero29', 'meghbhalerao', 'YunLemon', | |
| 'MeiVinEight', 'Huawei-DTSE-India-Delhi-NCR', 'ym-monkey', 'Selim042', 'ValentinGiboulot', 'jesusbmx', | |
| 'FantasybabyChange', 'zegelin', 'MeasureAuthoringTool', 'death-knight', 'abargnesi', 'cmunilla', | |
| 'sladyn98', 'jhaprabhatt', 'smartsv-dev', 'Lavaong', 'ShahabGT', 'WXB2010', 'digideskio', 'p1r9t3', | |
| 'chathamabate', 'heymysweetheart', 'blockchain-etl', 'Jeniel557' | |
| ] | |
| } | |
| class StackRepo(datasets.GeneratorBasedBuilder): | |
| """This is a builder class for the Stack-Repo dataset""" | |
| VERSION = datasets.Version("1.0.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig( | |
| name="bm25_contexts", | |
| version=VERSION, | |
| description="This part of the dataset covers bm25 contexts" | |
| ), | |
| datasets.BuilderConfig( | |
| name="PP_contexts", | |
| version=VERSION, | |
| description="This part of the dataset covers PP contexts" | |
| ), | |
| datasets.BuilderConfig( | |
| name="randomNN_contexts", | |
| version=VERSION, | |
| description="This part of the dataset covers randomNN contexts" | |
| ), | |
| datasets.BuilderConfig( | |
| name="sources", | |
| version=VERSION, | |
| description="This part of the dataset covers java file sources used in building other configurations" | |
| ), | |
| ] | |
| def _info(self): | |
| if self.config.name == 'sources': | |
| features = datasets.Features({ | |
| 'file': datasets.Value('string'), | |
| 'content': datasets.Value('string') | |
| }) | |
| else: | |
| features = datasets.Features({ | |
| 'id': datasets.Value('string'), | |
| 'hole_file': datasets.Value('string'), | |
| 'hole_line': datasets.Value('int32'), | |
| 'hole_pos': datasets.Value('int32'), | |
| 'question': datasets.Value('string'), | |
| 'target': datasets.Value('string'), | |
| 'answers': datasets.Sequence( | |
| datasets.Value('string') | |
| ), | |
| 'ctxs': [{ | |
| 'title': datasets.Value('string'), | |
| 'text': datasets.Value('string'), | |
| 'score': datasets.Value('float64') | |
| }] | |
| }) | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=features, | |
| homepage=_HOMEPAGE, | |
| license=_LICENSE, | |
| citation=_CITATION, | |
| ) | |
| def manual_download_instructions(self): | |
| # We are ok if user specifies local path instead of dataset name and data_dir | |
| # for sources configuration and other configurations can be downloaded from the hub | |
| # automatically. So, we manipulate return value here to get around manual_dir is None | |
| # check in _check_manual_download | |
| # NOTE: this hack can broke if implementaion of the _check_manual_download will change | |
| # TODO: override _check_manual_download instead | |
| if self.config.name == 'sources': | |
| if not self.dl_manager.manual_dir is None: | |
| base_path = Path(self.dl_manager.manual_dir) | |
| else: | |
| base_path = Path(self.base_path) | |
| if base_path.expanduser().absolute().is_dir(): | |
| return None | |
| return ( | |
| "first download the dataset to a local folder with " | |
| "git clone https://huggingface.co/datasets/RepoFusion/Stack-Repo " | |
| "<path/to/manual/data>" | |
| ) | |
| else: | |
| return None | |
| def _split_generators(self, dl_manager): | |
| splits = [ | |
| (datasets.Split.TRAIN, 'train'), | |
| (datasets.Split.TEST, 'test'), | |
| (datasets.Split.VALIDATION, 'val') | |
| ] | |
| if not dl_manager.manual_dir is None: | |
| base_path = Path(dl_manager.manual_dir) | |
| else: | |
| base_path = Path(self.base_path) | |
| if self.config.name == 'sources': | |
| src = { | |
| split[0]: [ | |
| el.relative_to(base_path) | |
| for el in (base_path / f'data/{split[1]}/').rglob('*.java') | |
| ] | |
| for split in splits | |
| } | |
| else: | |
| src = { | |
| split[0]: [ | |
| f'data/{split[1]}/{el}/hole_and_{self.config.name}.json' | |
| for el in _SOURCES[split[1]] | |
| ] | |
| for split in splits | |
| } | |
| data_dir = dl_manager.download_and_extract(src) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=split[0], | |
| gen_kwargs={ | |
| "filepaths": data_dir[split[0]], | |
| "base_path": base_path | |
| }, | |
| ) | |
| for split in splits | |
| ] | |
| def _generate_examples(self, filepaths, base_path): | |
| for filepath in filepaths: | |
| if self.config.name == 'sources': | |
| filepath = Path(filepath) | |
| file = str(filepath.relative_to(base_path)) | |
| yield file, { | |
| 'file': file, | |
| 'content': filepath.read_text() | |
| } | |
| else: | |
| with open(filepath, encoding="utf-8") as f: | |
| for row in f: | |
| data = json.loads(row) | |
| parts = data['id'].rsplit('_', 2) | |
| data['hole_file'] = str(base_path / parts[0]) | |
| data['hole_line'] = int(parts[1]) | |
| data['hole_pos'] = int(parts[2]) | |
| yield data['id'], data | |