Datasets:
Add files using upload-large-folder tool
Browse files- mixbench.py +17 -29
mixbench.py
CHANGED
|
@@ -1,35 +1,32 @@
|
|
| 1 |
-
#
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import csv
|
| 5 |
import datasets
|
| 6 |
|
| 7 |
_DESCRIPTION = """
|
| 8 |
-
MixBench is a benchmark for mixed-modality retrieval.
|
| 9 |
"""
|
| 10 |
|
| 11 |
_HOMEPAGE = "https://huggingface.co/datasets/mixed-modality-search/MixBench25"
|
| 12 |
|
| 13 |
-
# Define config for each dataset
|
| 14 |
-
class MixBenchConfig(datasets.BuilderConfig):
|
| 15 |
-
def __init__(self, **kwargs):
|
| 16 |
-
super().__init__(**kwargs)
|
| 17 |
-
|
| 18 |
class MixBench(datasets.GeneratorBasedBuilder):
|
| 19 |
-
BUILDER_CONFIG_CLASS = MixBenchConfig
|
| 20 |
BUILDER_CONFIGS = [
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
MixBenchConfig(name="VisualNews", version=datasets.Version("1.0.0"), description="VisualNews subset"),
|
| 24 |
-
MixBenchConfig(name="OVEN", version=datasets.Version("1.0.0"), description="OVEN subset"),
|
| 25 |
]
|
| 26 |
|
| 27 |
def _info(self):
|
| 28 |
-
#
|
| 29 |
return datasets.DatasetInfo(
|
| 30 |
description=_DESCRIPTION,
|
| 31 |
homepage=_HOMEPAGE,
|
| 32 |
-
features=datasets.Features({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
def _split_generators(self, dl_manager):
|
|
@@ -56,46 +53,37 @@ class MixBench(datasets.GeneratorBasedBuilder):
|
|
| 56 |
|
| 57 |
def _generate_examples(self, path, split):
|
| 58 |
if split == "query":
|
| 59 |
-
self.info.features = datasets.Features({
|
| 60 |
-
"query_id": datasets.Value("string"),
|
| 61 |
-
"text": datasets.Value("string"),
|
| 62 |
-
"image": datasets.Value("string"),
|
| 63 |
-
})
|
| 64 |
with open(path, encoding="utf-8") as f:
|
| 65 |
for idx, line in enumerate(f):
|
| 66 |
item = json.loads(line)
|
| 67 |
yield idx, {
|
| 68 |
"query_id": item["query_id"],
|
|
|
|
| 69 |
"text": item["text"],
|
| 70 |
"image": item.get("image", ""),
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
elif split in {"corpus", "mixed_corpus"}:
|
| 74 |
-
self.info.features = datasets.Features({
|
| 75 |
-
"corpus_id": datasets.Value("string"),
|
| 76 |
-
"text": datasets.Value("string"),
|
| 77 |
-
"image": datasets.Value("string"),
|
| 78 |
-
})
|
| 79 |
with open(path, encoding="utf-8") as f:
|
| 80 |
for idx, line in enumerate(f):
|
| 81 |
item = json.loads(line)
|
| 82 |
yield idx, {
|
|
|
|
| 83 |
"corpus_id": item["corpus_id"],
|
| 84 |
"text": item["text"],
|
| 85 |
"image": item["image"],
|
|
|
|
| 86 |
}
|
| 87 |
|
| 88 |
elif split == "qrel":
|
| 89 |
-
self.info.features = datasets.Features({
|
| 90 |
-
"query_id": datasets.Value("string"),
|
| 91 |
-
"corpus_id": datasets.Value("string"),
|
| 92 |
-
"score": datasets.Value("int32"),
|
| 93 |
-
})
|
| 94 |
with open(path, encoding="utf-8") as f:
|
| 95 |
reader = csv.DictReader(f, delimiter="\t")
|
| 96 |
for idx, row in enumerate(reader):
|
| 97 |
yield idx, {
|
| 98 |
"query_id": row["query_id"],
|
| 99 |
"corpus_id": row["corpus_id"],
|
|
|
|
|
|
|
| 100 |
"score": int(row["score"]),
|
| 101 |
}
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import csv
|
| 4 |
import datasets
|
| 5 |
|
| 6 |
_DESCRIPTION = """
|
| 7 |
+
MixBench is a benchmark for mixed-modality retrieval across text, image, and image+text corpora.
|
| 8 |
"""
|
| 9 |
|
| 10 |
_HOMEPAGE = "https://huggingface.co/datasets/mixed-modality-search/MixBench25"
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
class MixBench(datasets.GeneratorBasedBuilder):
|
|
|
|
| 13 |
BUILDER_CONFIGS = [
|
| 14 |
+
datasets.BuilderConfig(name=name, version=datasets.Version("1.0.0"), description=f"{name} subset of MixBench")
|
| 15 |
+
for name in ["MSCOCO", "Google_WIT", "VisualNews", "OVEN"]
|
|
|
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
def _info(self):
|
| 19 |
+
# ⚠️ unified superset schema (all splits must use this)
|
| 20 |
return datasets.DatasetInfo(
|
| 21 |
description=_DESCRIPTION,
|
| 22 |
homepage=_HOMEPAGE,
|
| 23 |
+
features=datasets.Features({
|
| 24 |
+
"query_id": datasets.Value("string"),
|
| 25 |
+
"corpus_id": datasets.Value("string"),
|
| 26 |
+
"text": datasets.Value("string"),
|
| 27 |
+
"image": datasets.Value("string"),
|
| 28 |
+
"score": datasets.Value("int32"),
|
| 29 |
+
}),
|
| 30 |
)
|
| 31 |
|
| 32 |
def _split_generators(self, dl_manager):
|
|
|
|
| 53 |
|
| 54 |
def _generate_examples(self, path, split):
|
| 55 |
if split == "query":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
with open(path, encoding="utf-8") as f:
|
| 57 |
for idx, line in enumerate(f):
|
| 58 |
item = json.loads(line)
|
| 59 |
yield idx, {
|
| 60 |
"query_id": item["query_id"],
|
| 61 |
+
"corpus_id": "",
|
| 62 |
"text": item["text"],
|
| 63 |
"image": item.get("image", ""),
|
| 64 |
+
"score": 0,
|
| 65 |
}
|
| 66 |
|
| 67 |
elif split in {"corpus", "mixed_corpus"}:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
with open(path, encoding="utf-8") as f:
|
| 69 |
for idx, line in enumerate(f):
|
| 70 |
item = json.loads(line)
|
| 71 |
yield idx, {
|
| 72 |
+
"query_id": "",
|
| 73 |
"corpus_id": item["corpus_id"],
|
| 74 |
"text": item["text"],
|
| 75 |
"image": item["image"],
|
| 76 |
+
"score": 0,
|
| 77 |
}
|
| 78 |
|
| 79 |
elif split == "qrel":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
with open(path, encoding="utf-8") as f:
|
| 81 |
reader = csv.DictReader(f, delimiter="\t")
|
| 82 |
for idx, row in enumerate(reader):
|
| 83 |
yield idx, {
|
| 84 |
"query_id": row["query_id"],
|
| 85 |
"corpus_id": row["corpus_id"],
|
| 86 |
+
"text": "",
|
| 87 |
+
"image": "",
|
| 88 |
"score": int(row["score"]),
|
| 89 |
}
|