File size: 2,638 Bytes
2b1b387
 
 
15a7648
 
 
 
 
 
 
 
 
 
 
 
dad6849
 
 
 
162d0e2
2b1b387
dad6849
 
 
 
 
 
 
cd5097e
b0f6513
 
 
641c840
 
 
 
 
 
 
 
 
 
 
9da67d0
641c840
 
b0f6513
 
15a7648
b0f6513
3fdcb2c
d54e42a
ee9bf6e
ce7668f
 
97d5418
 
63634b7
9b11299
97d5418
ce7668f
9b11299
97d5418
bf81393
 
2b1b387
 
 
 
 
 
b0f6513
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import datasets
import pandas as pd

_CITATION = """\
@article{blinov2013research,
  title={Research of lexical approach and machine learning methods for sentiment analysis},
  author={Blinov, PD and Klekovkina, Maria and Kotelnikov, Eugeny and Pestov, Oleg},
  journal={Computational Linguistics and Intellectual Technologies},
  volume={2},
  number={12},
  pages={48--58},
  year={2013}
}
"""

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):
        return datasets.DatasetInfo(
            description='Kinopoisk movie reviews dataset.',
            features=datasets.Features(
                {
                    "content": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "grade3": datasets.Value("string"),
                    "movie_name": datasets.Value("string"),
                    "part": datasets.Value("string"),
                    "review_id": datasets.Value("string"),
                    "author": datasets.Value("string"),
                    "date":datasets.Value("string"),
                    "grade10": datasets.Value("string"),
                    "Idx": datasets.Value("int32"),
                }
            ),
            supervised_keys=None,
            homepage='',
            citation=_CITATION,
        )
    
    def _split_generators(self, dl_manager: datasets.DownloadManager):
        urls_to_download = {
            "train": "kinopoisk.jsonl",
            "dev": "kinopoisk.jsonl",
        }
        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