File size: 1,431 Bytes
0a28a4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c87f03
0a28a4c
 
 
 
b6bd166
0a28a4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from pathlib import Path
from datasets import DatasetBuilder, DatasetInfo, Features, Value, Sequence

class MoBiPlant(DatasetBuilder):
    def _info(self):
        return DatasetInfo(
            description="MoBiPlant MCQ dataset",
            features=Features({
                "question": Value("string"),
                "area": Sequence(Value("string")),
                "normalized_area": Value("string"),
                "plant_species": Value("string"),
                "normalized_plant_species": Value("string"),
                "doi": Value("string"),
                "source": Value("string"),
                "source_journal": Value("string"),
                "Year": Value("int32"),
                "Citations": Value("int32"),
                "answer": Value("int32"),
                "options": Sequence(Value("string")),
                "is_expert": Value("bool")
            }),
            supervised_keys=None,
        )

    def _split_generators(self, dl_manager):
        data_path = Path(self.config.data_files["train"])
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": str(data_path)},
            )
        ]

    def _generate_examples(self, filepath):
        with open(filepath, encoding="utf-8") as f:
            data = json.load(f)
        for idx, ex in enumerate(data):
            yield idx, ex