File size: 753 Bytes
71bdcd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Load MAGAR-Bench and resolve repository-relative image paths.

Run this file from the root of a cloned Hugging Face dataset repository.
"""

from pathlib import Path

from datasets import load_dataset


def load_magar_bench(repo_root: str | Path = "."):
    root = Path(repo_root)
    dataset = load_dataset(
        "json",
        data_files={
            "train": str(root / "data" / "train.jsonl"),
            "test_inputs": str(root / "data" / "test_inputs.jsonl"),
        },
    )

    def resolve_images(record):
        record["images"] = [str(root / image_path) for image_path in record["images"]]
        return record

    return dataset.map(resolve_images)


if __name__ == "__main__":
    loaded = load_magar_bench()
    print(loaded)