| """Final 6-way intersection for the case study, using all real signals. |
| |
| Conditions (all must hold for a base video): |
| Qwen3-Omni: |
| - mute : raw_output starts with 'yes' (hallucinated audio in silence) |
| - swap : raw_output starts with 'yes' (claimed mismatched audio matches) |
| - sync : both delay AND early variants are wrong (sync_is_wrong()) |
| Gemini-3.1-pro-preview: |
| - swap : raw_output starts with 'yes' (claimed mismatched audio matches) |
| - sync : both delay AND early variants are wrong (re-run on pool) |
| - mute : neutral prompt -> OpenAI judge marks correct=False (real hallucination) |
| |
| Writes survivors to /home/ubuntu/case_study_candidates.jsonl with full failure detail. |
| """ |
|
|
| import json |
| import re |
| from pathlib import Path |
|
|
| |
| 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" |
| |
| GEMINI_SWAP = "/home/ubuntu/eval_results/gemini_mute_sync_swap/swap/swap_gemini_gemini-3.1-pro-preview__promptDirect/eval_results.jsonl" |
| |
| GEMINI_SYNC = "/home/ubuntu/eval_results/case_study_pool/sync/case_study_pool_gemini_sync/eval_results.jsonl" |
| GEMINI_MUTE = "/home/ubuntu/eval_results/case_study_pool/mute/case_study_pool_gemini_mute_neutral/eval_results.jsonl" |
|
|
| OUT_PATH = Path("/home/ubuntu/case_study_candidates.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 starts with 'yes' (drops empty/ambiguous artifacts).""" |
| out = set() |
| for r in load_jsonl(jsonl_path): |
| if r.get("correct", True): |
| continue |
| if (r.get("raw_output") or "").strip().lower().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_sync_intervention_failures(jsonl_path): |
| """{base: {direction: row_summary}} for wrong delay/early variants only.""" |
| by_base = {} |
| for r in load_jsonl(jsonl_path): |
| v = r["video"] |
| d = direction_of(v) |
| if d is None: |
| continue |
| 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_sync_intervention_failures(QWEN_SYNC) |
| gem_sync_fails = collect_sync_intervention_failures(GEMINI_SYNC) |
|
|
| qwen_sync_both = {b for b, d in qwen_sync_fails.items() if "delay" in d and "early" in d} |
| gem_sync_both = {b for b, d in gem_sync_fails.items() if "delay" in d and "early" in d} |
|
|
| gem_mute_wrong = {r["video"] for r in load_jsonl(GEMINI_MUTE) if not r.get("correct", True)} |
|
|
| print("Per-source REAL failure sets:") |
| print(f" qwen mute (yes) : {len(qwen_mute_yes)}") |
| print(f" qwen swap (yes) : {len(qwen_swap_yes)}") |
| print(f" qwen sync (delay&early): {len(qwen_sync_both)}") |
| print(f" gemini swap (yes) : {len(gem_swap_yes)}") |
| print(f" gemini sync (delay&early): {len(gem_sync_both)}") |
| print(f" gemini mute neu (judge wrong): {len(gem_mute_wrong)}") |
|
|
| final = ( |
| qwen_mute_yes |
| & qwen_swap_yes |
| & qwen_sync_both |
| & gem_swap_yes |
| & gem_sync_both |
| & gem_mute_wrong |
| ) |
| print(f"\nFinal 6-way intersection: {len(final)} videos\n") |
|
|
| 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)} |
| gem_mute_rows = {r["video"]: r for r in load_jsonl(GEMINI_MUTE)} |
|
|
| rows = [] |
| for v in sorted(final): |
| gem_mute = gem_mute_rows.get(v, {}) |
| 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"), |
| "gemini_mute_neutral_raw": (gem_mute.get("raw_output") or "").strip(), |
| "gemini_mute_judge": gem_mute.get("judge_explanation"), |
| "gemini_sync_failures": [gem_sync_fails[v]["delay"], gem_sync_fails[v]["early"]], |
| "qwen_sync_failures": [qwen_sync_fails[v]["delay"], qwen_sync_fails[v]["early"]], |
| } |
| rows.append(rec) |
| print(f"VIDEO: {v}") |
| print(f" swap audio source : {rec['gemini_swap_audio_from']}") |
| print(f" gemini mute neutral raw : {rec['gemini_mute_neutral_raw'][:140]}") |
| for label, fails in (("gemini", rec["gemini_sync_failures"]), |
| ("qwen ", rec["qwen_sync_failures"])): |
| for f in fails: |
| tag = f["variant"].rsplit("_", 1)[-1].rstrip(".mp4") |
| print(f" [{label}] {tag:<8} gt={f['gt']} pred_synced={f['pred_synced']} pred={f['pred']}") |
| print() |
|
|
| 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}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|