Update MMSearch-Plus dataset with encrypted text fields (images unchanged)
Browse files- README.md +17 -3
- mmsearch_plus.py +112 -72
README.md
CHANGED
|
@@ -9,6 +9,11 @@ tags:
|
|
| 9 |
- Multimodal Long Context
|
| 10 |
size_categories:
|
| 11 |
- n<1K
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
dataset_info:
|
| 13 |
features:
|
| 14 |
- name: question
|
|
@@ -64,7 +69,7 @@ Official repository for the paper "[MMSearch-Plus: Benchmarking Provenance-Aware
|
|
| 64 |
|
| 65 |
## Usage
|
| 66 |
|
| 67 |
-
**⚠️ Important:
|
| 68 |
|
| 69 |
### Dataset Usage
|
| 70 |
|
|
@@ -72,13 +77,22 @@ Load the dataset with automatic decryption using your canary string:
|
|
| 72 |
|
| 73 |
```python
|
| 74 |
import os
|
|
|
|
| 75 |
from datasets import load_dataset
|
| 76 |
|
| 77 |
# Set the canary string (hint: it's the name of this repo without username)
|
| 78 |
os.environ['MMSEARCH_PLUS'] = 'your_canary_string'
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# Explore the dataset - everything is already decrypted!
|
| 84 |
print(f"Dataset size: {len(dataset['train'])}")
|
|
|
|
| 9 |
- Multimodal Long Context
|
| 10 |
size_categories:
|
| 11 |
- n<1K
|
| 12 |
+
configs:
|
| 13 |
+
- config_name: default
|
| 14 |
+
data_files:
|
| 15 |
+
- split: train
|
| 16 |
+
path: "*.arrow"
|
| 17 |
dataset_info:
|
| 18 |
features:
|
| 19 |
- name: question
|
|
|
|
| 69 |
|
| 70 |
## Usage
|
| 71 |
|
| 72 |
+
**⚠️ Important: This dataset is encrypted to prevent data contamination. However, decryption is handled transparently by the dataset loader.**
|
| 73 |
|
| 74 |
### Dataset Usage
|
| 75 |
|
|
|
|
| 77 |
|
| 78 |
```python
|
| 79 |
import os
|
| 80 |
+
from huggingface_hub import hf_hub_download
|
| 81 |
from datasets import load_dataset
|
| 82 |
|
| 83 |
# Set the canary string (hint: it's the name of this repo without username)
|
| 84 |
os.environ['MMSEARCH_PLUS'] = 'your_canary_string'
|
| 85 |
|
| 86 |
+
# Download the custom data loader script
|
| 87 |
+
script_path = hf_hub_download(
|
| 88 |
+
repo_id="Cie1/MMSearch-Plus",
|
| 89 |
+
filename="mmsearch_plus.py",
|
| 90 |
+
repo_type="dataset",
|
| 91 |
+
revision="main", # pin if needed
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Load dataset with transparent decryption using the custom loader
|
| 95 |
+
dataset = load_dataset(script_path, trust_remote_code=True)
|
| 96 |
|
| 97 |
# Explore the dataset - everything is already decrypted!
|
| 98 |
print(f"Dataset size: {len(dataset['train'])}")
|
mmsearch_plus.py
CHANGED
|
@@ -1,15 +1,12 @@
|
|
| 1 |
-
"""MMSearch-Plus dataset with transparent decryption.
|
| 2 |
-
|
| 3 |
-
Note: Only text fields (question, answer, video_url, arxiv_id) are encrypted.
|
| 4 |
-
Images are NOT encrypted and remain as PIL Image objects for accessibility.
|
| 5 |
-
"""
|
| 6 |
|
| 7 |
import base64
|
| 8 |
import hashlib
|
|
|
|
| 9 |
import os
|
| 10 |
-
from typing import Dict, Any
|
| 11 |
import datasets
|
| 12 |
-
from
|
| 13 |
|
| 14 |
_CITATION = """\
|
| 15 |
@article{tao2025mmsearch,
|
|
@@ -30,6 +27,13 @@ _HOMEPAGE = "https://mmsearch-plus.github.io/"
|
|
| 30 |
|
| 31 |
_LICENSE = "CC BY-NC 4.0"
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def derive_key(password: str, length: int) -> bytes:
|
| 34 |
"""Derive encryption key from password using SHA-256."""
|
| 35 |
hasher = hashlib.sha256()
|
|
@@ -37,6 +41,23 @@ def derive_key(password: str, length: int) -> bytes:
|
|
| 37 |
key = hasher.digest()
|
| 38 |
return key * (length // len(key)) + key[: length % len(key)]
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def decrypt_text(ciphertext_b64: str, password: str) -> str:
|
| 41 |
"""Decrypt base64-encoded ciphertext using XOR cipher with derived key."""
|
| 42 |
if not ciphertext_b64:
|
|
@@ -50,76 +71,82 @@ def decrypt_text(ciphertext_b64: str, password: str) -> str:
|
|
| 50 |
except Exception:
|
| 51 |
return ciphertext_b64
|
| 52 |
|
| 53 |
-
|
| 54 |
-
"""
|
| 55 |
-
# Decrypt text fields - matches encryption script fields
|
| 56 |
-
text_fields = ['question', 'video_url', 'arxiv_id']
|
| 57 |
-
|
| 58 |
-
for field in text_fields:
|
| 59 |
-
if field in example and example[field]:
|
| 60 |
-
example[field] = decrypt_text(example[field], canary)
|
| 61 |
-
|
| 62 |
-
# Handle answer field (list of strings)
|
| 63 |
-
if 'answer' in example and example['answer']:
|
| 64 |
-
decrypted_answers = []
|
| 65 |
-
for answer in example['answer']:
|
| 66 |
-
if answer:
|
| 67 |
-
decrypted_answers.append(decrypt_text(answer, canary))
|
| 68 |
-
else:
|
| 69 |
-
decrypted_answers.append(answer)
|
| 70 |
-
example['answer'] = decrypted_answers
|
| 71 |
-
|
| 72 |
-
# Images are NOT encrypted - they remain as PIL Image objects
|
| 73 |
-
return example
|
| 74 |
-
|
| 75 |
-
class MmsearchPlus(GeneratorBasedBuilder):
|
| 76 |
-
"""MMSearch-Plus dataset builder with transparent decryption."""
|
| 77 |
|
| 78 |
VERSION = datasets.Version("1.0.0")
|
| 79 |
|
| 80 |
def _info(self):
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
description=_DESCRIPTION,
|
| 83 |
-
features=
|
| 84 |
-
"question": Value("string"),
|
| 85 |
-
"answer": Sequence(Value("string")),
|
| 86 |
-
"num_images": Value("int64"),
|
| 87 |
-
"arxiv_id": Value("string"),
|
| 88 |
-
"video_url": Value("string"),
|
| 89 |
-
"category": Value("string"),
|
| 90 |
-
"difficulty": Value("string"),
|
| 91 |
-
"subtask": Value("string"),
|
| 92 |
-
"img_1": Image(),
|
| 93 |
-
"img_2": Image(),
|
| 94 |
-
"img_3": Image(),
|
| 95 |
-
"img_4": Image(),
|
| 96 |
-
"img_5": Image(),
|
| 97 |
-
}),
|
| 98 |
homepage=_HOMEPAGE,
|
| 99 |
license=_LICENSE,
|
| 100 |
citation=_CITATION,
|
| 101 |
)
|
| 102 |
|
| 103 |
def _split_generators(self, dl_manager):
|
| 104 |
-
# Get canary from environment variable
|
| 105 |
canary = os.environ.get("MMSEARCH_PLUS")
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
if not canary:
|
| 108 |
raise ValueError(
|
| 109 |
-
"
|
| 110 |
-
"
|
| 111 |
-
"
|
| 112 |
-
"
|
| 113 |
-
"Hint: The canary is the name of this dataset repository (without the username).\n"
|
| 114 |
)
|
| 115 |
-
|
| 116 |
-
# Download
|
| 117 |
-
urls = ["
|
| 118 |
downloaded_files = dl_manager.download(urls)
|
| 119 |
-
|
| 120 |
return [
|
| 121 |
-
SplitGenerator(
|
| 122 |
-
name=Split.TRAIN,
|
| 123 |
gen_kwargs={
|
| 124 |
"filepaths": downloaded_files,
|
| 125 |
"canary": canary,
|
|
@@ -129,21 +156,34 @@ class MmsearchPlus(GeneratorBasedBuilder):
|
|
| 129 |
|
| 130 |
def _generate_examples(self, filepaths, canary):
|
| 131 |
"""Generate examples with transparent decryption."""
|
| 132 |
-
import sys
|
| 133 |
-
print(f"🔓 [MMSearch-Plus] Decrypting dataset with canary: {canary[:10]}...", file=sys.stderr)
|
| 134 |
-
|
| 135 |
key = 0
|
|
|
|
| 136 |
for filepath in filepaths:
|
| 137 |
-
# Load the arrow file
|
| 138 |
arrow_dataset = datasets.Dataset.from_file(filepath)
|
| 139 |
-
|
| 140 |
for idx in range(len(arrow_dataset)):
|
| 141 |
example = arrow_dataset[idx]
|
| 142 |
-
|
| 143 |
-
#
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
yield key, example
|
| 147 |
-
key += 1
|
| 148 |
-
|
| 149 |
-
print(f"✅ [MMSearch-Plus] Decrypted {key} samples successfully!", file=sys.stderr)
|
|
|
|
| 1 |
+
"""MMSearch-Plus dataset with transparent decryption."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
import base64
|
| 4 |
import hashlib
|
| 5 |
+
import io
|
| 6 |
import os
|
| 7 |
+
from typing import Dict, Any, List
|
| 8 |
import datasets
|
| 9 |
+
from PIL import Image
|
| 10 |
|
| 11 |
_CITATION = """\
|
| 12 |
@article{tao2025mmsearch,
|
|
|
|
| 27 |
|
| 28 |
_LICENSE = "CC BY-NC 4.0"
|
| 29 |
|
| 30 |
+
_URLS = {
|
| 31 |
+
"train": [
|
| 32 |
+
"data-00000-of-00002.arrow",
|
| 33 |
+
"data-00001-of-00002.arrow"
|
| 34 |
+
]
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
def derive_key(password: str, length: int) -> bytes:
|
| 38 |
"""Derive encryption key from password using SHA-256."""
|
| 39 |
hasher = hashlib.sha256()
|
|
|
|
| 41 |
key = hasher.digest()
|
| 42 |
return key * (length // len(key)) + key[: length % len(key)]
|
| 43 |
|
| 44 |
+
def decrypt_image(ciphertext_b64: str, password: str) -> Image.Image:
|
| 45 |
+
"""Decrypt base64-encoded encrypted image bytes back to PIL Image."""
|
| 46 |
+
if not ciphertext_b64:
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
encrypted = base64.b64decode(ciphertext_b64)
|
| 51 |
+
key = derive_key(password, len(encrypted))
|
| 52 |
+
decrypted = bytes([a ^ b for a, b in zip(encrypted, key)])
|
| 53 |
+
|
| 54 |
+
# Convert bytes back to PIL Image
|
| 55 |
+
img_buffer = io.BytesIO(decrypted)
|
| 56 |
+
image = Image.open(img_buffer)
|
| 57 |
+
return image
|
| 58 |
+
except Exception:
|
| 59 |
+
return None
|
| 60 |
+
|
| 61 |
def decrypt_text(ciphertext_b64: str, password: str) -> str:
|
| 62 |
"""Decrypt base64-encoded ciphertext using XOR cipher with derived key."""
|
| 63 |
if not ciphertext_b64:
|
|
|
|
| 71 |
except Exception:
|
| 72 |
return ciphertext_b64
|
| 73 |
|
| 74 |
+
class MmsearchPlus(datasets.GeneratorBasedBuilder):
|
| 75 |
+
"""MMSearch-Plus dataset with transparent decryption."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
VERSION = datasets.Version("1.0.0")
|
| 78 |
|
| 79 |
def _info(self):
|
| 80 |
+
# Define features to handle the complete dataset schema
|
| 81 |
+
features = datasets.Features({
|
| 82 |
+
"question": datasets.Value("string"),
|
| 83 |
+
"answer": datasets.Sequence(datasets.Value("string")),
|
| 84 |
+
"num_images": datasets.Value("int64"),
|
| 85 |
+
"arxiv_id": datasets.Value("string"),
|
| 86 |
+
"video_url": datasets.Value("string"),
|
| 87 |
+
"category": datasets.Value("string"),
|
| 88 |
+
"difficulty": datasets.Value("string"),
|
| 89 |
+
"subtask": datasets.Value("string"),
|
| 90 |
+
# Image fields (not encrypted, kept as PIL Images)
|
| 91 |
+
"img_1": datasets.Image(),
|
| 92 |
+
"img_2": datasets.Image(),
|
| 93 |
+
"img_3": datasets.Image(),
|
| 94 |
+
"img_4": datasets.Image(),
|
| 95 |
+
"img_5": datasets.Image(),
|
| 96 |
+
# Additional fields that might exist in the dataset
|
| 97 |
+
"choices": datasets.Sequence(datasets.Value("string")),
|
| 98 |
+
"question_zh": datasets.Value("string"),
|
| 99 |
+
"answer_zh": datasets.Sequence(datasets.Value("string")),
|
| 100 |
+
"regex": datasets.Value("string"),
|
| 101 |
+
"text_criteria": datasets.Value("string"),
|
| 102 |
+
"original_filename": datasets.Value("string"),
|
| 103 |
+
"screenshots_dir": datasets.Value("string"),
|
| 104 |
+
"time_points": datasets.Sequence(datasets.Value("string")),
|
| 105 |
+
"search_query": datasets.Value("string"),
|
| 106 |
+
"question_type": datasets.Value("string"),
|
| 107 |
+
"requires_image_understanding": datasets.Value("bool"),
|
| 108 |
+
"source": datasets.Value("string"),
|
| 109 |
+
"content_keywords": datasets.Value("string"),
|
| 110 |
+
"reasoning": datasets.Value("string"),
|
| 111 |
+
"processed_at": datasets.Value("string"),
|
| 112 |
+
"model_used": datasets.Value("string"),
|
| 113 |
+
"entry_index": datasets.Value("int64"),
|
| 114 |
+
"original_image_paths": datasets.Sequence(datasets.Value("string")),
|
| 115 |
+
"masked_image_paths": datasets.Sequence(datasets.Value("string")),
|
| 116 |
+
"is_valid": datasets.Value("bool"),
|
| 117 |
+
})
|
| 118 |
+
|
| 119 |
+
return datasets.DatasetInfo(
|
| 120 |
description=_DESCRIPTION,
|
| 121 |
+
features=features,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
homepage=_HOMEPAGE,
|
| 123 |
license=_LICENSE,
|
| 124 |
citation=_CITATION,
|
| 125 |
)
|
| 126 |
|
| 127 |
def _split_generators(self, dl_manager):
|
| 128 |
+
# Get canary from environment variable or kwargs
|
| 129 |
canary = os.environ.get("MMSEARCH_PLUS")
|
| 130 |
+
|
| 131 |
+
# Check if passed in the builder's initialization
|
| 132 |
+
if hasattr(self, 'canary'):
|
| 133 |
+
canary = self.canary
|
| 134 |
+
|
| 135 |
if not canary:
|
| 136 |
raise ValueError(
|
| 137 |
+
"Canary string is required for decryption. Either set the MMSEARCH_PLUS "
|
| 138 |
+
"environment variable or pass it via the dataset loading kwargs. "
|
| 139 |
+
"Example: load_dataset('path/to/dataset', trust_remote_code=True) after setting "
|
| 140 |
+
"os.environ['MMSEARCH_PLUS'] = 'your_canary_string'"
|
|
|
|
| 141 |
)
|
| 142 |
+
|
| 143 |
+
# Download files
|
| 144 |
+
urls = _URLS["train"]
|
| 145 |
downloaded_files = dl_manager.download(urls)
|
| 146 |
+
|
| 147 |
return [
|
| 148 |
+
datasets.SplitGenerator(
|
| 149 |
+
name=datasets.Split.TRAIN,
|
| 150 |
gen_kwargs={
|
| 151 |
"filepaths": downloaded_files,
|
| 152 |
"canary": canary,
|
|
|
|
| 156 |
|
| 157 |
def _generate_examples(self, filepaths, canary):
|
| 158 |
"""Generate examples with transparent decryption."""
|
|
|
|
|
|
|
|
|
|
| 159 |
key = 0
|
| 160 |
+
|
| 161 |
for filepath in filepaths:
|
| 162 |
+
# Load the arrow file
|
| 163 |
arrow_dataset = datasets.Dataset.from_file(filepath)
|
| 164 |
+
|
| 165 |
for idx in range(len(arrow_dataset)):
|
| 166 |
example = arrow_dataset[idx]
|
| 167 |
+
|
| 168 |
+
# Decrypt text fields - matches encryption script fields
|
| 169 |
+
text_fields = ['question', 'video_url', 'arxiv_id']
|
| 170 |
+
|
| 171 |
+
for field in text_fields:
|
| 172 |
+
if example.get(field):
|
| 173 |
+
example[field] = decrypt_text(example[field], canary)
|
| 174 |
+
|
| 175 |
+
# Handle answer field (list of strings)
|
| 176 |
+
if example.get("answer"):
|
| 177 |
+
decrypted_answers = []
|
| 178 |
+
for answer in example["answer"]:
|
| 179 |
+
if answer:
|
| 180 |
+
decrypted_answers.append(decrypt_text(answer, canary))
|
| 181 |
+
else:
|
| 182 |
+
decrypted_answers.append(answer)
|
| 183 |
+
example["answer"] = decrypted_answers
|
| 184 |
+
|
| 185 |
+
# Images are not encrypted - they remain as PIL Image objects
|
| 186 |
+
# No image decryption needed as per the encryption script
|
| 187 |
+
|
| 188 |
yield key, example
|
| 189 |
+
key += 1
|
|
|
|
|
|