|
import json |
|
import os |
|
from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split, Value, Features, Image |
|
|
|
class AugeoBench(GeneratorBasedBuilder): |
|
def _info(self): |
|
return DatasetInfo( |
|
description="AugeoBench: Multimodal QA dataset with Japanese problem-solving questions and diagram images.", |
|
features=Features({ |
|
"id": Value("string"), |
|
"url": Value("string"), |
|
"question_context_ja": Value("string"), |
|
"question_text_ja": Value("string"), |
|
"question_information_ja": Value("string"), |
|
"answer_exact": Value("string"), |
|
"answer_text_ja": Value("string"), |
|
"question_image": Image(), |
|
"answer_image": Image(), |
|
"Genre": Value("string"), |
|
"Remarks": Value("string"), |
|
}), |
|
supervised_keys=None, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_files = { |
|
"annotation": "annotation_clean.json", |
|
"images": "images.zip", |
|
} |
|
|
|
downloaded_files = dl_manager.download_and_extract(data_files) |
|
|
|
return [ |
|
SplitGenerator( |
|
name=Split.TRAIN, |
|
gen_kwargs={ |
|
"annotation_path": downloaded_files["annotation"], |
|
"images_dir": downloaded_files["images"], |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, annotation_path, images_dir): |
|
with open(annotation_path, encoding="utf-8") as f: |
|
data = json.load(f) |
|
|
|
for idx, item in enumerate(data): |
|
q_img = os.path.join(images_dir, "images", item["question_image_path"]) if item.get("question_image_path") else None |
|
a_img = os.path.join(images_dir, "images", item["answer_image_path"]) if item.get("answer_image_path") else None |
|
|
|
yield idx, { |
|
"id": item["id"], |
|
"url": item["url"], |
|
"question_context_ja": item["question_context_ja"], |
|
"question_text_ja": item["question_text_ja"], |
|
"question_information_ja": item["question_information_ja"], |
|
"answer_exact": item["answer_exact"], |
|
"answer_text_ja": item["answer_text_ja"], |
|
"question_image": q_img, |
|
"answer_image": a_img, |
|
"Genre": item["Genre"], |
|
"Remarks": item["Remarks"], |
|
} |
|
|