File size: 1,405 Bytes
2b1b387
 
 
dad6849
 
 
 
162d0e2
2b1b387
dad6849
 
 
 
 
 
 
cd5097e
b0f6513
4a96ae8
 
 
 
b0f6513
 
c32e533
b0f6513
 
 
 
 
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
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 _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