File size: 2,384 Bytes
53f81c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2559715
8bdeaeb
53f81c9
 
 
2559715
 
 
 
 
 
 
 
 
 
 
 
 
 
53f81c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from dataclasses import dataclass
from typing import Optional

import datasets
from datasets.data_files import DataFilesDict


@dataclass
class RussianExamsConfig(datasets.BuilderConfig):
    features: Optional[datasets.Features] = None


class RussianExams(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        RussianExamsConfig(name="math_tasks", features=datasets.Features({
            "text": datasets.Value("string"),
            "answer": datasets.Value("string"),
            "source": datasets.Value("string"),
        }), data_files=DataFilesDict({"test": ["data/math_tasks_1.json"]})),
        RussianExamsConfig(name="yes_no_math_tasks", features=datasets.Features({
            "statement": datasets.Value("string"),
            "label": datasets.Value("bool"),
            "source": datasets.Value("string"),
        }), data_files=DataFilesDict({"test": ["data/yes_no_math_tasks.json"]})),
        RussianExamsConfig(name="russian_basis_tasks", features=datasets.Features({
            "sentence": datasets.Value("string"),
            "basis": datasets.Value("string"),
            "label": datasets.Value("bool"),
            "source": datasets.Value("string"),
        }), data_files=DataFilesDict({"test": ["data/russian_basis_tasks.json"]})),
        RussianExamsConfig(name="russian_phrase_conn_tasks", features=datasets.Features({
            "phrase": datasets.Value("string"),
            "connection": datasets.Value("string"),
            "answer": datasets.Value("string"),
            "source": datasets.Value("string"),
        }), data_files=DataFilesDict({"test": ["data/russian_phrase_conn_tasks.json"]})),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            features=self.config.features,
        )

    def _split_generators(self, dl_manager):
        data_dir = dl_manager.download_and_extract(self.config.data_files["test"][0])
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": data_dir,
                    "split": "test",
                },
            ),
        ]

    def _generate_examples(self, filepath, split):
        with open(filepath, 'rb') as f:
            data = json.load(f)
        return enumerate(data)