RussianExams / RussianExams.py
batalovme's picture
new
8bdeaeb
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)