Datasets:
Download scripts/replay_hf_statistics.py from sungguk/visual-answerability: direct link, hf CLI and curl.
- Browser
- Download file 3.98 kB
-
https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/scripts/replay_hf_statistics.py
- Command line
-
hf download hf://datasets/sungguk/visual-answerability/scripts/replay_hf_statistics.py
-
curl -L -o replay_hf_statistics.py https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/scripts/replay_hf_statistics.py
3.98 kB
| #!/usr/bin/env python3 | |
| """Reproduce all 18 cells and paired intervals from 72,000 saved scoring records.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| from analyze_crossdomain_paper import CROSS_KEYS, MODELS, analyze | |
| from hf_release_common import read_json, read_rows, write_json | |
| from score_hf_dataset import score | |
| def replay(dataset, output): | |
| output.mkdir(parents=True, exist_ok=True) | |
| # Histogram keys are integers in memory and strings in the saved JSON. | |
| # Compare the same serialized representation used by the original replay. | |
| result = json.loads( | |
| json.dumps(analyze(dataset / "inputs", dataset / "expected"), allow_nan=False) | |
| ) | |
| expected = read_json(dataset / "expected/revision-analysis.json") | |
| if result != expected: | |
| differing = [key for key in result if result[key] != expected.get(key)] | |
| raise ValueError("Numerical replay differs from frozen analysis: " + ", ".join(differing)) | |
| labels = read_rows(dataset / "metadata/views.jsonl.gz") | |
| for model in MODELS: | |
| predictions = read_rows(dataset / f"inputs/plotqa/{model}.jsonl.gz") + read_rows( | |
| dataset / f"inputs/crossdomain/{CROSS_KEYS[model]}.jsonl.gz" | |
| ) | |
| scored = score(labels, predictions) | |
| for source, values in scored["by_source"].items(): | |
| archived = result["domains"][source]["models"][model] | |
| if values["counts"] != archived["counts"] or values["states"] != archived["states"]: | |
| raise ValueError( | |
| "Public prediction scorer disagrees with paper: " + source + "/" + model | |
| ) | |
| write_json(output / (model + "-score.json"), scored) | |
| from build_answerability_rewrite_assets import build as build_chart | |
| result_path = output / "analysis.json" | |
| write_json(result_path, result) | |
| subprocess.run( | |
| [ | |
| sys.executable, | |
| str(dataset / "scripts/build_crossdomain_paper_assets.py"), | |
| "--analysis", | |
| str(result_path), | |
| "--output", | |
| str(output / "tables"), | |
| ], | |
| check=True, | |
| ) | |
| build_chart( | |
| dataset / "inputs", | |
| result_path, | |
| output / "charts", | |
| dataset / "evidence/plotqa/bounded-witness-proofs.jsonl.gz", | |
| ) | |
| from collections import Counter | |
| finite = read_rows(dataset / "evidence/finite/original-results.jsonl.gz") | |
| solver = read_rows(dataset / "evidence/finite/solver-results.jsonl.gz") | |
| if ( | |
| len(finite) != 1024 | |
| or len(solver) != 1456 | |
| or Counter(row["truth"] for row in solver) != {"ambiguous": 822, "constant": 634} | |
| ): | |
| raise ValueError("Finite study counts differ") | |
| if not all(row["enumeration_status"] == row["smt_status"] == row["truth"] for row in solver): | |
| raise ValueError("Archived solver decisions disagree") | |
| report = { | |
| "status": "passed", | |
| "saved_records": 72000, | |
| "model_domain_cells": 18, | |
| "exact_analysis_replay": True, | |
| "bootstrap_draws": 10000, | |
| "new_prediction_scorer_matches_all_18_cells": True, | |
| "finite_cases": len(finite), | |
| "solver_cases": len(solver), | |
| "solver_constructors_rerun": False, | |
| "inference_calls": 0, | |
| "gqa_question_text": "ID references; original text verified separately during reconstruction", | |
| } | |
| write_json(output / "replay-validation.json", report) | |
| return report | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--dataset", type=Path, default=Path(__file__).resolve().parents[1]) | |
| parser.add_argument("--output", type=Path, required=True) | |
| args = parser.parse_args() | |
| if args.output.resolve().is_relative_to(args.dataset.resolve()): | |
| parser.error("Write replay outputs outside the frozen dataset directory") | |
| print(json.dumps(replay(args.dataset, args.output))) | |