Datasets:
Split geneval2 into geneval2_raw and geneval2_reprompted; row groups of 20 rows with a page index
365f8e2 verified Download make_geneval2.py from iisys-hof/situate-diffuse: direct link, hf CLI and curl.
- Browser
- Download file 5.15 kB
-
https://huggingface.co/datasets/iisys-hof/situate-diffuse/resolve/main/make_geneval2.py
- Command line
-
hf download hf://datasets/iisys-hof/situate-diffuse/make_geneval2.py
-
curl -L -o make_geneval2.py https://huggingface.co/datasets/iisys-hof/situate-diffuse/resolve/main/make_geneval2.py
5.15 kB
| """Writes the geneval2_raw and geneval2_reprompted subsets from the finished GenEval2 runs: one row per prompt (800), one picture | |
| column per model, with Soft-TIFA's score per question and per prompt (GM) from all three judges. Two subsets, since 100 rows of all | |
| 17 pictures are more than the dataset viewer reads at once. | |
| python make_geneval2.py ../SITUATE-DIFFUSER26/1_benchmarks/GenEval2 | |
| """ | |
| import json | |
| import math | |
| import sys | |
| from pathlib import Path | |
| from datasets import Dataset, Features, Image, Sequence, Value | |
| HERE = Path(__file__).resolve().parent | |
| GENEVAL2 = Path(sys.argv[1]) | |
| RESULTS = GENEVAL2 / "results" | |
| SHARDS = 10 # parquet files of about 250 MB | |
| ROW_GROUP = 20 # rows; with the page index the viewer reads only the rows it shows | |
| RUNS = { # subset -> column name -> run | |
| "raw": {"krea_2_turbo": "raw/krea-2-turbo", | |
| "fibo_2_edit_turbo": "raw/fibo-2-edit-turbo", | |
| "ming_image_0_1_design": "raw/ming-image-0.1-design", | |
| "moss_image_sft": "raw/moss-image-sft", | |
| "flux_3_klein": "raw/flux-3-klein", | |
| "qwen_image_2_1_turbo": "raw/qwen-image-2.1-turbo", | |
| "qwen_image_2512_lightning": "raw/qwen-image-2512-lightning", | |
| "hidream_o1_image": "raw/hidream-o1-image"}, | |
| "reprompted": {"krea_2_turbo": "reprompted/krea-2-turbo", | |
| "fibo_2_edit_turbo": "reprompted/fibo-2-edit-turbo", | |
| "ming_image_0_1_design": "reprompted/ming-image-0.1-design", | |
| "moss_image_sft": "reprompted/moss-image-sft", | |
| "flux_3_klein": "reprompted/flux-3-klein-reprompt", | |
| "qwen_image_2_1_turbo": "reprompted/qwen-image-2.1-turbo-reprompt", | |
| "qwen_image_2512_lightning": "reprompted/qwen-image-2512-lightning", | |
| "hidream_o1_image": "reprompted/hidream-o1-image-reprompt", | |
| "ideogram_4": "reprompted/ideogram-4-reprompt"}, | |
| } | |
| JUDGES = {"qwen3vl": "scores.json", "qwen35": "scores_qwen35.json", "qwen38": "scores_qwen38.json"} # Qwen3-VL-8B, Qwen3.5-9B, Qwen3.8-27B | |
| def gmean(scores): # Soft-TIFA GM of one prompt: the geometric mean of its question scores | |
| return math.prod(scores) ** (1 / len(scores)) | |
| def own_rewriter(run): | |
| return run.endswith("-reprompt") | |
| def features(subset): | |
| judge_scores = {judge: Value("float64") for judge in JUDGES} | |
| question_scores = {judge: Sequence(Value("float64")) for judge in JUDGES} | |
| fields = {"prompt": Value("string"), | |
| "atom_count": Value("int32"), | |
| "skills": Sequence(Value("string")), | |
| "questions": Sequence(Value("string")), | |
| "answers": Sequence(Value("string"))} | |
| if subset == "reprompted": | |
| fields["fixed_rewrite"] = Value("string") | |
| for name, run in RUNS[subset].items(): | |
| fields[name] = Image() | |
| if own_rewriter(run): | |
| fields[f"{name}_rewrite"] = Value("string") | |
| fields[f"{name}_gm"] = judge_scores | |
| fields[f"{name}_question_scores"] = question_scores | |
| return Features(fields) | |
| def rows(subset): | |
| data = [json.loads(line) for line in (GENEVAL2 / "geneval2/geneval2_data.jsonl").read_text().splitlines()] | |
| fixed = [json.loads(line) for line in (GENEVAL2 / "reprompts/geneval2_reprompted.jsonl").read_text().splitlines()] | |
| pictures = {} | |
| scores = {} | |
| rewrites = {} | |
| for run in RUNS[subset].values(): | |
| pictures[run] = json.loads((RESULTS / run / "images.json").read_text()) | |
| scores[run] = {judge: json.loads((RESULTS / run / file).read_text()) for judge, file in JUDGES.items()} | |
| if own_rewriter(run): | |
| rewrites[run] = json.loads((RESULTS / run / "prompts.json").read_text()) | |
| for number, item in enumerate(data): | |
| prompt = item["prompt"] | |
| row = {"prompt": prompt, | |
| "atom_count": item["atom_count"], | |
| "skills": item["skills"], | |
| "questions": [question for question, _ in item["vqa_list"]], | |
| "answers": [answer for _, answer in item["vqa_list"]]} | |
| if subset == "reprompted": | |
| row["fixed_rewrite"] = fixed[number]["prompt"] | |
| for name, run in RUNS[subset].items(): | |
| picture = Path(pictures[run][prompt]) | |
| row[name] = {"bytes": picture.read_bytes(), "path": f"{run}/{picture.name}"} | |
| if own_rewriter(run): | |
| row[f"{name}_rewrite"] = rewrites[run][prompt] | |
| row[f"{name}_gm"] = {judge: gmean(scores[run][judge][number]) for judge in JUDGES} | |
| row[f"{name}_question_scores"] = {judge: scores[run][judge][number] for judge in JUDGES} | |
| yield row | |
| for subset in RUNS: | |
| data = Dataset.from_generator(rows, gen_kwargs={"subset": subset}, features=features(subset)) | |
| out = HERE / f"geneval2_{subset}" | |
| out.mkdir(exist_ok=True) | |
| for index in range(SHARDS): | |
| shard = data.shard(SHARDS, index, contiguous=True) | |
| shard.to_parquet(out / f"test-{index:05d}-of-{SHARDS:05d}.parquet", batch_size=ROW_GROUP, write_page_index=True) | |
| print(f"{subset}: {len(data)} prompts, {len(data.column_names)} columns -> {out}") | |