|
|
import json |
|
|
import os |
|
|
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, **kwargs): |
|
|
"""BuilderConfig for JeeNeetBenchmark. |
|
|
Args: |
|
|
**kwargs: keyword arguments forwarded to super. |
|
|
""" |
|
|
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", |
|
|
), |
|
|
] |
|
|
|
|
|
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.Sequence(datasets.Value("int32")), |
|
|
} |
|
|
) |
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=features, |
|
|
homepage=_HOMEPAGE, |
|
|
license=_LICENSE, |
|
|
citation=_CITATION, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
|
|
|
|
base_dir = self.config.data_dir if self.config.data_dir is not None else os.path.dirname(__file__) |
|
|
metadata_path = os.path.join(base_dir, "data", "metadata.jsonl") |
|
|
image_dir = os.path.join(base_dir, "images") |
|
|
|
|
|
|
|
|
if not os.path.exists(metadata_path): |
|
|
raise FileNotFoundError( |
|
|
f"Metadata file not found at {metadata_path}. " |
|
|
f"Make sure 'data/metadata.jsonl' exists in your dataset repository. " |
|
|
f"If running locally, you might need to specify the path using --data_dir argument " |
|
|
f"or ensure the script is run from the project root." |
|
|
) |
|
|
|
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TEST, |
|
|
|
|
|
gen_kwargs={ |
|
|
"metadata_filepath": metadata_path, |
|
|
"image_base_dir": image_dir, |
|
|
}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples(self, metadata_filepath, image_base_dir): |
|
|
"""Yields examples.""" |
|
|
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: |
|
|
print(f"Error decoding JSON on line {idx+1}: {e}") |
|
|
continue |
|
|
|
|
|
image_path_relative = row.get("image_path") |
|
|
if not image_path_relative: |
|
|
print(f"Warning: Missing 'image_path' on line {idx+1}. Skipping.") |
|
|
continue |
|
|
|
|
|
|
|
|
image_path_full = os.path.join(image_base_dir, os.path.relpath(image_path_relative, start="images")) |
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(image_path_full): |
|
|
print(f"Warning: Image file not found at {image_path_full} referenced on line {idx+1}. 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", ""), |
|
|
"subject": row.get("subject", ""), |
|
|
"question_type": row.get("question_type", ""), |
|
|
"correct_answer": row.get("correct_answer", []), |
|
|
} |
|
|
|