VeriSpoof-Bench / scripts /check_reference.py
AustinXiao's picture
Dataset card and files preview (private)
f053b90 verified
Raw History Blame Contribute Delete
2.08 kB
#!/usr/bin/env python3
"""Re-score the stored per-item outputs of VeriSpoof-Base / -Plus (reference_results/<model>/<subset>.parquet) with
scripts/score.py and compare with the metrics reported by the research evaluation (reported_metrics.json).
python scripts/check_reference.py [--bench <dataset dir>]
Metrics that need model log-probabilities not stored per item (ad_reasoning eer_loc, flip_rate, head_* token-head
metrics, held-out faithfulness rates) are listed as not re-scorable.
"""
import argparse
import json
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import score as SC # noqa: E402
HERE = os.path.dirname(os.path.abspath(__file__))
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--bench", default=os.path.join(HERE, ".."))
a = ap.parse_args()
ok = True
for model in ("verispoof_base", "verispoof_plus"):
d = f"{a.bench}/reference_results/{model}"
rep = json.load(open(f"{d}/reported_metrics.json"))
n_cmp, worst, skipped = 0, (0.0, None), set()
for s, r in rep.items():
items = SC.load_items(a.bench, s)
m = SC.score_subset(items, SC.read_table(f"{d}/{s}"), None, s)
for k, v in r.items():
if not isinstance(v, (int, float)) or isinstance(v, bool):
continue
if k not in m or m[k] is None:
skipped.add(k)
continue
diff = abs(m[k] - v)
n_cmp += 1
if diff > worst[0]:
worst = (diff, f"{s}:{k} rescored {m[k]} reported {v}")
if diff > 1e-3:
ok = False
print(f"MISMATCH {model} {s} {k}: rescored {m[k]} reported {v}")
print(f"{model}: {len(rep)} subsets, {n_cmp} metric values compared, max |diff| {worst[0]:.2g} ({worst[1]}); "
f"not re-scorable from stored outputs: {sorted(skipped)}")
print("ALL MATCH" if ok else "SOME MISMATCHES")
if __name__ == "__main__":
main()