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