import json import os import datasets # Define the different configurations (languages) _LANGUAGES = ["java", "kt", "py"] class BugLocalizationConfig(datasets.BuilderConfig): """BuilderConfig for BugLocalization dataset""" def __init__(self, **kwargs): """BuilderConfig for BugLocalization. Args: **kwargs: keyword arguments forwarded to super. """ super(BugLocalizationConfig, self).__init__(**kwargs) class BugLocalization(datasets.GeneratorBasedBuilder): """BugLocalization dataset""" BUILDER_CONFIGS = [ BugLocalizationConfig(name=lang, description=f"My dataset for {lang}.") for lang in _LANGUAGES ] def _info(self): pass def _split_generators(self, dl_manager): urls = { "python": "python.jsonl", "java": "java.jsonl", "kotlin": "kotlin.jsonl", } downloaded_files = dl_manager.download_and_extract(urls) return [datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files[self.config.name]} )] def _generate_examples(self, filepath): with open(filepath, encoding="utf-8") as f: for id_, line in enumerate(f): data = json.loads(line) yield data