File size: 4,670 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 | #!/usr/bin/env python3
"""Aggregate mute/swap accuracy across all models in /home/ubuntu/eval_results.
For each (model, prompt_mode) we report:
mute : detection rate on muted inputs (positive = muted)
mute_org : detection rate on original audio (positive = synced)
swap : detection rate on swapped inputs (positive = mismatched)
swap_org : detection rate on original audio (positive = synced)
mute_all : combined accuracy = (correct_mute + correct_mute_org) / (n_mute + n_mute_org)
swap_all : combined accuracy = (correct_swap + correct_swap_org) / (n_swap + n_swap_org)
When sample sizes match, the combined number equals the simple mean of the two rates.
"""
from __future__ import annotations
import json
import re
from pathlib import Path
ROOT = Path("/home/ubuntu/eval_results")
# Each task -> (list of root subpaths to scan, dirname prefix to strip, accuracy keys)
TASKS = {
"mute": (["mute", "gemini_mute_sync_swap/mute"], "mute_",
["mute_detection_rate"]),
"mute_original": (["mute_original"], "mute_",
["audio_present_detection_rate", "describes_audio_rate"]),
"swap": (["swap", "gemini_mute_sync_swap/swap"], "swap_",
["mismatch_detection_rate"]),
"swap_original": (["swap_original"], "swap_",
["match_detection_rate", "correct_synced_rate"]),
}
# Suffixes attached to model names to mark which input variant was used
INPUT_SUFFIXES = ("_audioMuxed", "_originalsControl", "_visualOnly")
PROMPT_RE = re.compile(r"^(?P<model>.+)_prompt(?P<mode>[A-Za-z0-9]+)$")
def parse_dir(name: str, prefix: str) -> tuple[str, str] | None:
"""Return (model, prompt_mode) parsed from a result directory name."""
if not name.startswith(prefix):
return None
rest = name[len(prefix):]
m = PROMPT_RE.match(rest)
if not m:
return None
model = m.group("model").rstrip("_")
for suf in INPUT_SUFFIXES:
if model.endswith(suf):
model = model[: -len(suf)]
break
if model.startswith("gemini_"):
model = model[len("gemini_"):]
return model, m.group("mode")
def load_metric(sub: Path, keys: list[str]) -> tuple[float, int] | None:
"""Prefer metrics.rejudged.json (re-judged, more accurate); fall back to metrics.json."""
for fname in ("metrics.rejudged.json", "metrics.json"):
path = sub / fname
try:
data = json.loads(path.read_text())
except (FileNotFoundError, json.JSONDecodeError):
continue
for k in keys:
if k in data:
return float(data[k]), int(data["total_samples"])
return None
def collect() -> dict[tuple[str, str], dict[str, tuple[float, int]]]:
rows: dict[tuple[str, str], dict[str, tuple[float, int]]] = {}
for task, (subpaths, prefix, keys) in TASKS.items():
for subpath in subpaths:
task_dir = ROOT / subpath
if not task_dir.is_dir():
continue
for sub in sorted(task_dir.iterdir()):
if not sub.is_dir():
continue
parsed = parse_dir(sub.name, prefix)
if parsed is None:
continue
metric = load_metric(sub, keys)
if metric is None:
continue
rows.setdefault(parsed, {})[task] = metric
return rows
def fmt(rate_n: tuple[float, int] | None) -> str:
if rate_n is None:
return " — "
rate, n = rate_n
return f"{rate * 100:5.1f}% ({n})"
def combined(a: tuple[float, int] | None,
b: tuple[float, int] | None) -> tuple[float, int] | None:
if a is None or b is None:
return None
ra, na = a
rb, nb = b
return (ra * na + rb * nb) / (na + nb), na + nb
def main() -> None:
rows = collect()
header = (
f"{'Model (prompt)':<70} "
f"{'mute':>13} {'mute_org':>13} {'mute_all':>13} "
f"{'swap':>13} {'swap_org':>13} {'swap_all':>13}"
)
print(header)
print("-" * len(header))
for (model, mode), entries in sorted(rows.items()):
mute = entries.get("mute")
mute_o = entries.get("mute_original")
swap = entries.get("swap")
swap_o = entries.get("swap_original")
label = f"{model} [{mode}]"
print(
f"{label:<70} "
f"{fmt(mute):>13} {fmt(mute_o):>13} {fmt(combined(mute, mute_o)):>13} "
f"{fmt(swap):>13} {fmt(swap_o):>13} {fmt(combined(swap, swap_o)):>13}"
)
if __name__ == "__main__":
main()
|