import json import datasets logger = datasets.logging.get_logger(__name__) _DESCRIPTION = """\ Ukrainian Multi30k """ _CITATION = """\ """ _URLS = { "train" : "train.json", "flickr_2016" : "test_2016_flickr.json", "flickr_2017" : "test_2017_flickr.json", "flickr_2018" : "test_2018_flickr.json", "mscoco_2017" : "test_2017_mscoco.json" } class UkrainianMulti30k(datasets.GeneratorBasedBuilder): """Ukrainian Multi30k Dataset""" VERSION = datasets.Version("0.0.1") DEFAULT_CONFIG_NAME = "multi30k" BUILDER_CONFIGS = [ datasets.BuilderConfig(name="multi30k", version=VERSION, description=""), datasets.BuilderConfig(name="flickr_2016", version=VERSION, description=""), datasets.BuilderConfig(name="flickr_2017", version=VERSION, description=""), datasets.BuilderConfig(name="flickr_2018", version=VERSION, description=""), datasets.BuilderConfig(name="mscoco_2017", version=VERSION, description=""), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "en": datasets.Value("string"), "uk": datasets.Value("string") } ), citation=_CITATION, ) def _split_generators(self, dl_manager): downloaded_files = dl_manager.download(_URLS) if self.config.name == "multi30k": return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files["train"]}) ] elif self.config.name == "flickr_2016": return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files["flickr_2016"]}) ] elif self.config.name == "flickr_2017": return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files["flickr_2017"]}) ] elif self.config.name == "flickr_2018": return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files["flickr_2018"]}) ] elif self.config.name == "mscoco_2017": return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files["mscoco_2017"]}) ] def _generate_examples(self, filepaths): with open(filepaths, encoding="utf-8") as f: for num, rows_str in enumerate(f): rows = json.loads(rows_str) yield num, rows