import json import datasets _CITATION = """\ """ _LICENSE = """\ """ _DESCRIPTION = """\ Review classification based on Yandex Georeview dataset. """ _LANGUAGES = { "ru": "Russian" } _HOMEPAGE_URL = "" _DOWNLOAD_URL = "{split}.jsonl" _VERSION = "1.0.0" class GeoreviewClassConfig(datasets.BuilderConfig): """BuilderConfig for GeoreviewCalssConfig.""" def __init__(self, languages=None, **kwargs): super(GeoreviewClassConfig, self).__init__(version=datasets.Version(_VERSION, ""), **kwargs), self.languages = languages class GeoreviewClass(datasets.GeneratorBasedBuilder): """The Georeview Corpus""" BUILDER_CONFIGS = [ GeoreviewClassConfig( name='ru', languages='ru', description="Review classification based on Yandex Georeview dataset", ) ] BUILDER_CONFIG_CLASS = GeoreviewClassConfig DEFAULT_CONFIG_NAME = 'ru' def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "text": datasets.Value("string"), "label": datasets.Value("int32"), "label_text": datasets.Value("string"), } ), supervised_keys=None, license=_LICENSE, homepage=_HOMEPAGE_URL, citation=_CITATION, ) def _split_generators(self, dl_manager): train_urls = [_DOWNLOAD_URL.format(split="train")] dev_urls = [_DOWNLOAD_URL.format(split="validation")] test_urls = [_DOWNLOAD_URL.format(split="test")] train_paths = dl_manager.download_and_extract(train_urls) dev_paths = dl_manager.download_and_extract(dev_urls) test_paths = dl_manager.download_and_extract(test_urls) print(train_paths, dev_paths, test_paths) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"file_paths": train_paths}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"file_paths": dev_paths}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"file_paths": test_paths}), ] def _generate_examples(self, file_paths): row_count = 0 for file_path in file_paths: with open(file_path, "r", encoding="utf-8") as f: for line in f: yield row_count, json.loads(line) row_count += 1