Datasets:
Upload RealXBench.py with huggingface_hub
Browse files- RealXBench.py +83 -0
RealXBench.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""RealXBench dataset."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import datasets
|
| 8 |
+
|
| 9 |
+
_DESCRIPTION = """\
|
| 10 |
+
RealXBench is a comprehensive visual question answering benchmark dataset.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
_HOMEPAGE = "https://huggingface.co/datasets/glowol/RealXBench"
|
| 14 |
+
|
| 15 |
+
_LICENSE = ""
|
| 16 |
+
|
| 17 |
+
_CITATION = """\
|
| 18 |
+
@dataset{realxbench2024,
|
| 19 |
+
title={RealXBench: A Real-World Visual Question Answering Benchmark},
|
| 20 |
+
author={},
|
| 21 |
+
year={2024},
|
| 22 |
+
}
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class RealXBench(datasets.GeneratorBasedBuilder):
|
| 27 |
+
"""RealXBench dataset."""
|
| 28 |
+
|
| 29 |
+
VERSION = datasets.Version("1.0.0")
|
| 30 |
+
|
| 31 |
+
BUILDER_CONFIGS = [
|
| 32 |
+
datasets.BuilderConfig(
|
| 33 |
+
name="default",
|
| 34 |
+
version=VERSION,
|
| 35 |
+
description="RealXBench dataset",
|
| 36 |
+
),
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
DEFAULT_CONFIG_NAME = "default"
|
| 40 |
+
|
| 41 |
+
def _info(self):
|
| 42 |
+
return datasets.DatasetInfo(
|
| 43 |
+
description=_DESCRIPTION,
|
| 44 |
+
features=datasets.Features(
|
| 45 |
+
{
|
| 46 |
+
"query": datasets.Value("string"),
|
| 47 |
+
"answer": datasets.Value("string"),
|
| 48 |
+
"image": datasets.Image(),
|
| 49 |
+
}
|
| 50 |
+
),
|
| 51 |
+
homepage=_HOMEPAGE,
|
| 52 |
+
license=_LICENSE,
|
| 53 |
+
citation=_CITATION,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
def _split_generators(self, dl_manager):
|
| 57 |
+
"""Returns SplitGenerators."""
|
| 58 |
+
data_dir = Path(__file__).parent
|
| 59 |
+
|
| 60 |
+
return [
|
| 61 |
+
datasets.SplitGenerator(
|
| 62 |
+
name=datasets.Split.TRAIN,
|
| 63 |
+
gen_kwargs={
|
| 64 |
+
"json_path": data_dir / "data.json",
|
| 65 |
+
"images_dir": data_dir / "images",
|
| 66 |
+
},
|
| 67 |
+
),
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
def _generate_examples(self, json_path, images_dir):
|
| 71 |
+
"""Yields examples."""
|
| 72 |
+
with open(json_path, "r", encoding="utf-8") as f:
|
| 73 |
+
data = json.load(f)
|
| 74 |
+
|
| 75 |
+
for idx, item in enumerate(data):
|
| 76 |
+
image_path = images_dir / item["image"].replace("images/", "")
|
| 77 |
+
|
| 78 |
+
yield idx, {
|
| 79 |
+
"query": item["query"],
|
| 80 |
+
"answer": item["answer"],
|
| 81 |
+
"image": str(image_path),
|
| 82 |
+
}
|
| 83 |
+
|