File size: 6,326 Bytes
203a7fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | """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
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 direct swap (the original yes/no eval)
GEMINI_SWAP = "/home/ubuntu/eval_results/gemini_mute_sync_swap/swap/swap_gemini_gemini-3.1-pro-preview__promptDirect/eval_results.jsonl"
# Gemini results we re-ran on the 45-pool
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()
|