AsianPlayer/TriDrive / code /weak /gpt_weak_labels_export.py
AsianPlayer's picture
download
raw
4.79 kB
"""cwm3/weak/gpt_weak_labels_export.py — consolidate the GPT `ground_relation` returns into ONE weak-label table for the warning-head label curve.
python gpt_weak_labels_export.py --stamp <UTC> --lists <csv> [<csv> ...] # csv files with a clip_id column (calibration / main lists)
Reads cwm2/annotation_package/returns/<model>/ground_relation/<clip_id>.json (the package's standard output location), joins the private
clip maps (idx / uid / dongle / t0 / regime / ctrl), re-asserts every clip is on a TRAIN device (run_gpt._split_of_clips) and writes
cwm3/weak/gpt_weak_labels_<stamp>.jsonl (new file; append-only policy) + a .summary.json. Fields per record:
clip_id idx uid dongle t0 regime ctrl list source model preset cache_key response_id prompt_warranted_now gpt_bin(0/1/None for unsure)
behavior_task_compatibility max_demand task_families concern_persists observed_vehicle_response confidence reason_codes human_label(if any).
These are WEAK labels (pretrain / mining material), never gold; nothing here touches test or val devices. No DMS field is read.
"""
from __future__ import annotations
import argparse, collections, json, sys
from pathlib import Path
import pandas as pd
CWM3 = Path(__file__).resolve().parents[1]; EXPLORE = CWM3.parent; CWM2 = EXPLORE / "cwm2"; PKG = CWM2 / "annotation_package"
BIN = {"warranted_attention": 1, "warranted_hands": 1, "not_warranted": 0}
DEMAND = {"low": 0, "moderate": 1, "high": 2}
def main():
ap = argparse.ArgumentParser(); ap.add_argument("--stamp", required=True); ap.add_argument("--lists", nargs="+", required=True)
ap.add_argument("--model", default="gpt-5"); ap.add_argument("--preset", default="economy"); a = ap.parse_args()
sys.path.insert(0, str(CWM3 / "weak")); sys.path.insert(0, str(PKG)); import run_gpt # noqa: E402,F401
maps = {}
for p in (CWM2 / "private" / "clip_map_full.json", CWM2 / "private" / "clip_map.json"):
maps.update(json.load(open(p)))
out = CWM3 / "weak" / f"gpt_weak_labels_{a.stamp}.jsonl"; assert not out.exists(), f"append-only: {out} exists"
recs = []; stats = collections.Counter()
for lst in a.lists:
df = pd.read_csv(lst, dtype={"clip_id": str})
for r in df.itertuples():
p = PKG / "returns" / a.model / "ground_relation" / f"{r.clip_id}.json"
if not p.is_file():
stats["missing_return"] += 1; continue
env = json.load(open(p)); ann = env.get("annotation") or {}
if env.get("preset") != a.preset or not ann or env.get("status") != "completed":
stats[f"skipped_{env.get('status')}_{env.get('preset')}"] += 1; continue
m = maps[r.clip_id]; tasks = ann.get("tasks") or []
dl = [DEMAND.get(t.get("demand_level"), -1) for t in tasks]
recs.append(dict(clip_id=r.clip_id, idx=m["idx"], uid=m["uid"], dongle=m["dongle"], t0=m["t0"], regime=m["regime"], ctrl=m["ctrl"],
list=Path(lst).name, source=getattr(r, "source", "calibration"), model=a.model, preset=a.preset, cache_key=env.get("cache_key"),
response_id=env.get("response_id"), prompt_warranted_now=ann.get("prompt_warranted_now"), gpt_bin=BIN.get(ann.get("prompt_warranted_now")),
behavior_task_compatibility=ann.get("behavior_task_compatibility"),
max_demand=({0: "low", 1: "moderate", 2: "high"}.get(max(dl), "unknown") if dl else None),
task_families=sorted({t.get("family") for t in tasks}), concern_persists=ann.get("concern_persists"),
observed_vehicle_response=ann.get("observed_vehicle_response"), confidence=ann.get("confidence"),
reason_codes=ann.get("reason_codes") or [], human_label=(m.get("label") if "label" in m else None)))
stats["exported"] += 1
sp = run_gpt._split_of_clips([r["clip_id"] for r in recs]); bad = {c: s for c, s in sp.items() if s != "train"}
assert not bad, f"non-train clips in export: {bad}"
with open(out, "w") as f:
for r in recs:
f.write(json.dumps(r) + "\n")
summ = dict(stamp=a.stamp, n=len(recs), stats=dict(stats), prompt_counts=collections.Counter(r["prompt_warranted_now"] for r in recs).most_common(),
by_source=collections.Counter(r["source"] for r in recs).most_common(), by_regime=collections.Counter(r["regime"] for r in recs).most_common(),
devices=len({r["dongle"] for r in recs}), device_split=collections.Counter(sp.values()).most_common(), lists=a.lists, output=str(out))
json.dump(summ, open(out.with_suffix(".summary.json"), "w"), indent=1)
print(json.dumps(summ, indent=1))
if __name__ == "__main__":
main()

Xet Storage Details

Size:
4.79 kB
·
Xet hash:
944df88d9cbc09fac7fbcfa59440f3f01f4628a66846efa826dbb02c0aec5fab

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.