miscellaneous / build_candidate_pool.py
Rakancorle11's picture
Upload supp/ and root scripts
203a7fb verified
"""Build the candidate pool for case study (BEFORE re-running Gemini).
Selection rule (only the trustworthy signals):
- Qwen failed mute (raw_output == 'yes', i.e. real hallucination)
- Qwen failed swap (raw_output == 'yes', real false-match)
- Qwen failed BOTH delay AND early sync
- Gemini failed swap (raw_output == 'yes', real false-match)
Skipped on purpose:
- Gemini mute direct: all wrong rows are empty raw_output -> not real signal
- Gemini sync : we will re-run this on the candidate pool
Writes pool to /home/ubuntu/case_study_pool.jsonl
"""
import json
import re
from pathlib import Path
GEMINI_SWAP = "/home/ubuntu/eval_results/gemini_mute_sync_swap/swap/swap_gemini_gemini-3.1-pro-preview__promptDirect/eval_results.jsonl"
QWEN_MUTE = "/home/ubuntu/eval_results/mute/mute_qwen3omni_vanilla_promptDirect/eval_results.jsonl"
QWEN_SWAP = "/home/ubuntu/eval_results/swap/swap_Qwen_Qwen3-Omni-30B-A3B-Instruct_promptDirect/eval_results.jsonl"
QWEN_SYNC = "/home/ubuntu/eval_results/sync/sync_qwen3omni_vanilla/eval_results.jsonl"
OUT_PATH = Path("/home/ubuntu/case_study_pool.jsonl")
SYNC_SUFFIX_RE = re.compile(r"_(delay|early)_\d+(?:\.\d+)?s(?=\.mp4$)")
DIRECTION_RE = re.compile(r"_(delay|early)_(\d+(?:\.\d+)?)s\.mp4$")
def base_of(name): return SYNC_SUFFIX_RE.sub("", name)
def direction_of(name):
m = DIRECTION_RE.search(name)
return m.group(1) if m else None
def load_jsonl(path):
with open(path) as f:
for line in f:
line = line.strip()
if line:
yield json.loads(line)
def real_yes_wrong(jsonl_path):
"""Wrong rows whose raw_output is actually 'yes' (drops empty/ambiguous artifacts)."""
out = set()
for r in load_jsonl(jsonl_path):
if r.get("correct", True):
continue
raw = (r.get("raw_output") or "").strip().lower()
if raw.startswith("yes"):
out.add(r["video"])
return out
def sync_is_wrong(row):
gt_synced = bool(row.get("gt_synced"))
pred_synced = bool(row.get("pred_synced"))
if gt_synced != pred_synced:
return True
if not gt_synced and row.get("pred_direction") != row.get("gt_direction"):
return True
return False
def collect_qwen_sync_intervention_failures(jsonl_path):
by_base = {}
for r in load_jsonl(jsonl_path):
v = r["video"]
d = direction_of(v)
if d is None:
continue # skip the synced original
if sync_is_wrong(r):
by_base.setdefault(base_of(v), {})[d] = {
"variant": v,
"gt": (r.get("gt_direction"), r.get("gt_offset_sec")),
"pred_synced": r.get("pred_synced"),
"pred": (r.get("pred_direction"), r.get("pred_offset_sec")),
}
return by_base
def main():
qwen_mute_yes = real_yes_wrong(QWEN_MUTE)
qwen_swap_yes = real_yes_wrong(QWEN_SWAP)
gem_swap_yes = real_yes_wrong(GEMINI_SWAP)
qwen_sync_fails = collect_qwen_sync_intervention_failures(QWEN_SYNC)
qwen_sync_both = {b for b, dirs in qwen_sync_fails.items()
if "delay" in dirs and "early" in dirs}
print("Per-source REAL wrong sets (raw_output='yes' only):")
print(f" qwen mute yes-hallucinations : {len(qwen_mute_yes)}")
print(f" qwen swap yes-false-match : {len(qwen_swap_yes)}")
print(f" qwen sync (delay AND early) : {len(qwen_sync_both)}")
print(f" gemini swap yes-false-match : {len(gem_swap_yes)}")
pool = qwen_mute_yes & qwen_swap_yes & qwen_sync_both & gem_swap_yes
print(f"\nPool (4-way real intersection): {len(pool)} videos")
qwen_swap_rows = {r["video"]: r for r in load_jsonl(QWEN_SWAP)
if not r.get("correct", True)}
gem_swap_rows = {r["video"]: r for r in load_jsonl(GEMINI_SWAP)
if not r.get("correct", True)}
rows = []
for v in sorted(pool):
rec = {
"video": v,
"gemini_swap_audio_from": gem_swap_rows.get(v, {}).get("swapped_from"),
"qwen_swap_audio_from": qwen_swap_rows.get(v, {}).get("swapped_from"),
"qwen_sync_failures": [qwen_sync_fails[v]["delay"],
qwen_sync_fails[v]["early"]],
}
rows.append(rec)
with open(OUT_PATH, "w") as f:
for rec in rows:
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
print(f"[saved] {len(rows)} rows -> {OUT_PATH}")
print("\nPool videos:")
for r in rows:
print(f" {r['video']}")
if __name__ == "__main__":
main()