Download scripts/_diff_hf_vs_local.py from LiYacheng/r4d-bench-qa: direct link, hf CLI and curl.
- Browser
- Download file 5.1 kB
-
https://huggingface.co/datasets/LiYacheng/r4d-bench-qa/resolve/main/scripts/_diff_hf_vs_local.py
- Command line
-
hf download hf://datasets/LiYacheng/r4d-bench-qa/scripts/_diff_hf_vs_local.py
-
curl -L -o _diff_hf_vs_local.py https://huggingface.co/datasets/LiYacheng/r4d-bench-qa/resolve/main/scripts/_diff_hf_vs_local.py
5.1 kB
| """Diff HuggingFace published queries vs local scene *_queries.json.""" | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| import urllib.request | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from scripts.predictions_ground_truth import SCENES_CONFIG | |
| REPO = "LiYacheng/r4d-bench-qa" | |
| BASE = f"https://huggingface.co/datasets/{REPO}/raw/main" | |
| def fetch(path: str): | |
| url = f"{BASE}/{path}" | |
| with urllib.request.urlopen(url, timeout=60) as r: | |
| return r.read().decode("utf-8") | |
| def main(): | |
| diffs = [] | |
| for cfg in SCENES_CONFIG: | |
| folder = cfg["folder"] | |
| local_path = ROOT / "data" / "scenes" / folder / cfg["query_file"] | |
| rel = f"data/scenes/{folder}/{cfg['query_file']}" | |
| try: | |
| remote_raw = fetch(rel) | |
| except Exception as e: | |
| diffs.append({"file": rel, "error": str(e)}) | |
| print(f"FAIL fetch {rel}: {e}") | |
| continue | |
| local = json.loads(local_path.read_text(encoding="utf-8")) | |
| remote = json.loads(remote_raw) | |
| if isinstance(local, dict): | |
| local = local["queries"] | |
| if isinstance(remote, dict): | |
| remote = remote["queries"] | |
| loc = {q["query_id"]: q for q in local} | |
| rem = {q["query_id"]: q for q in remote} | |
| for qid in sorted(set(loc) | set(rem)): | |
| if qid not in loc: | |
| diffs.append({"query_id": qid, "issue": "only_on_HF"}) | |
| continue | |
| if qid not in rem: | |
| diffs.append({"query_id": qid, "issue": "only_local"}) | |
| continue | |
| L, R = loc[qid], rem[qid] | |
| for field in ("text_en", "text_zh", "query_type"): | |
| if (L.get(field) or "") != (R.get(field) or ""): | |
| diffs.append( | |
| { | |
| "query_id": qid, | |
| "issue": f"{field}_diff", | |
| "local": L.get(field), | |
| "hf": R.get(field), | |
| } | |
| ) | |
| if sorted(L.get("target_track_ids") or []) != sorted( | |
| R.get("target_track_ids") or [] | |
| ): | |
| diffs.append( | |
| { | |
| "query_id": qid, | |
| "issue": "target_track_ids_diff", | |
| "local": L.get("target_track_ids"), | |
| "hf": R.get("target_track_ids"), | |
| } | |
| ) | |
| # also eval files | |
| for rel in [ | |
| "evaluation/R4D-Bench_queries.json", | |
| "evaluation/R4D-Bench_predictions.json", | |
| ]: | |
| try: | |
| remote = json.loads(fetch(rel)) | |
| local = json.loads((ROOT / rel).read_text(encoding="utf-8")) | |
| except Exception as e: | |
| diffs.append({"file": rel, "error": str(e)}) | |
| continue | |
| if rel.endswith("predictions.json"): | |
| for qid in sorted(set(local) | set(remote)): | |
| if sorted(local.get(qid) or []) != sorted(remote.get(qid) or []): | |
| diffs.append( | |
| { | |
| "query_id": qid, | |
| "issue": "eval_predictions_diff", | |
| "local": local.get(qid), | |
| "hf": remote.get(qid), | |
| } | |
| ) | |
| else: | |
| loc = {q["query_id"]: q for q in local} | |
| rem = {q["query_id"]: q for q in remote} | |
| for qid in sorted(set(loc) | set(rem)): | |
| if qid not in loc or qid not in rem: | |
| diffs.append({"query_id": qid, "issue": "eval_queries_presence"}) | |
| continue | |
| if (loc[qid].get("text_en") or "") != (rem[qid].get("text_en") or ""): | |
| diffs.append( | |
| { | |
| "query_id": qid, | |
| "issue": "eval_text_en_diff", | |
| "local": loc[qid].get("text_en"), | |
| "hf": rem[qid].get("text_en"), | |
| } | |
| ) | |
| if sorted(loc[qid].get("target_track_ids") or []) != sorted( | |
| rem[qid].get("target_track_ids") or [] | |
| ): | |
| diffs.append( | |
| { | |
| "query_id": qid, | |
| "issue": "eval_ids_diff", | |
| "local": loc[qid].get("target_track_ids"), | |
| "hf": rem[qid].get("target_track_ids"), | |
| } | |
| ) | |
| out = ROOT / "assets" / "gt_audit" / "hf_vs_local_diff.json" | |
| out.write_text(json.dumps(diffs, ensure_ascii=False, indent=2), encoding="utf-8") | |
| print(f"DIFFS={len(diffs)}") | |
| for d in diffs: | |
| print(d) | |
| print(f"Wrote {out}") | |
| if __name__ == "__main__": | |
| main() | |