Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
json
Sub-tasks:
sentiment-classification
Languages:
Russian
Size:
10K - 100K
License:
import datasets | |
import pandas as pd | |
class KinopoiskReviewsConfig(datasets.BuilderConfig): | |
def __init__(self, features, **kwargs): | |
super(KinopoiskReviewsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs) | |
self.features = features | |
class Kinopoisk(datasets.GeneratorBasedBuilder): | |
BUILDER_CONFIGS = [ | |
KinopoiskReviewsConfig( | |
name="simple", | |
description="Simple config", | |
features=["content", "title", "grade3", "movie_name", "part", "review_id", "author", "date"], | |
) | |
] | |
def _info(self): | |
features = {feature: datasets.Value("string") for feature in self.config.features} | |
#if self.config.name == "simple": | |
# features = {feature: datasets.Value("string") for feature in self.config.features} | |
features["Idx"] = datasets.Value("int32") | |
return datasets.DatasetInfo( | |
description='Kinopoisk movie reviews dataset.', | |
features=datasets.Features(features), | |
supervised_keys=None, | |
homepage='', | |
citation='', | |
) | |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: | |
urls_to_download = self._URLS | |
downloaded_files = dl_manager.download_and_extract(urls_to_download) | |
return [ | |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), | |
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), | |
] | |
def _generate_examples(self, filepath): | |
df = pd.read_json(filepath, lines=True) | |
rows = df.to_dict(orient="records") | |
for n, row in enumerate(rows): | |
example = row | |
example["Idx"] = n | |
yield example["Idx"], example | |