|
import json |
|
import os |
|
import logging |
|
import tarfile |
|
import datasets |
|
|
|
_CITATION = """\ |
|
@misc{jee-neet-benchmark, |
|
title={JEE/NEET LLM Benchmark}, |
|
author={Md Rejaullah}, |
|
year={2025}, |
|
howpublished={\\url{https://huggingface.co/datasets/Reja1/jee-neet-benchmark}}, |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
A benchmark dataset for evaluating Large Language Models (LLMs) on Joint Entrance Examination (JEE) |
|
and National Eligibility cum Entrance Test (NEET) questions from India. Questions are provided as |
|
images, and metadata includes exam details, subject, and correct answers. |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/Reja1/jee-neet-benchmark" |
|
|
|
_LICENSE = "MIT License" |
|
|
|
|
|
class JeeNeetBenchmarkConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for JeeNeetBenchmark.""" |
|
|
|
def __init__(self, images_dir="images", **kwargs): |
|
"""BuilderConfig for JeeNeetBenchmark. |
|
Args: |
|
images_dir: Directory containing the image files, relative to the dataset root. |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
self.images_dir = images_dir |
|
super(JeeNeetBenchmarkConfig, self).__init__(**kwargs) |
|
|
|
|
|
class JeeNeetBenchmark(datasets.GeneratorBasedBuilder): |
|
"""JEE/NEET LLM Benchmark Dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
JeeNeetBenchmarkConfig( |
|
name="default", |
|
version=VERSION, |
|
description="Default config for JEE/NEET Benchmark", |
|
images_dir="images", |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "default" |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"image": datasets.Image(), |
|
"question_id": datasets.Value("string"), |
|
"exam_name": datasets.Value("string"), |
|
"exam_year": datasets.Value("int32"), |
|
"exam_code": datasets.Value("string"), |
|
"subject": datasets.Value("string"), |
|
"question_type": datasets.Value("string"), |
|
"correct_answer": datasets.Value("string"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
repo_metadata_path = os.path.join("data", "metadata.jsonl") |
|
repo_images_archive_path = "images.tar.gz" |
|
|
|
|
|
|
|
dl_manager.download_config.force_download = True |
|
dl_manager.download_config.force_extract = True |
|
|
|
try: |
|
|
|
downloaded_files = dl_manager.download_and_extract({ |
|
"metadata_file": repo_metadata_path, |
|
"images_archive": repo_images_archive_path |
|
}) |
|
except Exception as e: |
|
|
|
logging.error(f"Failed to download/extract dataset files. Metadata path in repo: '{repo_metadata_path}', Images archive path in repo: '{repo_images_archive_path}'. Error: {e}") |
|
raise |
|
|
|
metadata_path = downloaded_files["metadata_file"] |
|
|
|
images_extracted_root = downloaded_files["images_archive"] |
|
|
|
logging.info(f"Metadata file successfully downloaded to: {metadata_path}") |
|
logging.info(f"Images archive successfully extracted to: {images_extracted_root}") |
|
|
|
|
|
if not os.path.exists(metadata_path): |
|
error_msg = f"Metadata file not found at expected local path after download: {metadata_path}. Check repository path '{repo_metadata_path}'." |
|
logging.error(error_msg) |
|
raise FileNotFoundError(error_msg) |
|
|
|
if not os.path.isdir(images_extracted_root): |
|
error_msg = f"Images archive was not extracted to a valid directory: {images_extracted_root}. Check repository path '{repo_images_archive_path}' and archive integrity." |
|
logging.error(error_msg) |
|
raise FileNotFoundError(error_msg) |
|
|
|
|
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"metadata_filepath": metadata_path, |
|
"image_base_dir": images_extracted_root, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, metadata_filepath, image_base_dir): |
|
"""Yields examples.""" |
|
logging.info(f"Generating examples from metadata: {metadata_filepath}") |
|
logging.info(f"Using image base directory: {image_base_dir}") |
|
|
|
with open(metadata_filepath, "r", encoding="utf-8") as f: |
|
for idx, line in enumerate(f): |
|
try: |
|
row = json.loads(line) |
|
except json.JSONDecodeError as e: |
|
logging.error(f"Error decoding JSON on line {idx+1} in {metadata_filepath}: {e}") |
|
continue |
|
|
|
|
|
|
|
image_path_from_metadata = row.get("image_path") |
|
if not image_path_from_metadata: |
|
logging.warning(f"Missing 'image_path' in metadata on line {idx+1} of {metadata_filepath}. Skipping.") |
|
continue |
|
|
|
|
|
image_path_full = os.path.join(image_base_dir, image_path_from_metadata) |
|
|
|
if not os.path.exists(image_path_full): |
|
logging.warning(f"Image file not found at {image_path_full} (referenced on line {idx+1} of {metadata_filepath}). Skipping.") |
|
continue |
|
|
|
yield idx, { |
|
"image": image_path_full, |
|
"question_id": row.get("question_id", ""), |
|
"exam_name": row.get("exam_name", ""), |
|
"exam_year": row.get("exam_year", -1), |
|
"exam_code": row.get("exam_code", "N/A"), |
|
"subject": row.get("subject", ""), |
|
"question_type": row.get("question_type", ""), |
|
"correct_answer": json.dumps(row.get("correct_answer", [])), |
|
} |
|
|