#!/usr/bin/env python3 """Validate the LongCapBench-TAC-Long labels, provenance, and LongCap-35B-A3B-FP8 predictions.""" import argparse import hashlib import json import math from pathlib import Path from urllib.parse import urlsplit COUNTS = {"01_movie_en": 1892, "01_movie_zh": 1956, "08_standup_variety_en": 1187, "08_standup_variety_zh": 1485} MEDIA_SUFFIXES = {".wav", ".mp3", ".mp4", ".flac", ".ogg", ".webm", ".m4a", ".aac", ".mov", ".zip", ".tar", ".gz"} PUBLIC_FILES = { "LICENSE", "README.md", "SCHEMA.md", "build.py", "validate.py", "verify_audio.py", "dataset.json", "references.jsonl", "predictions/longcap-35b-a3b-fp8.jsonl", "sources.jsonl", "manifest.jsonl", "event_provenance.jsonl", "annotation_notes.json", "ontology.json", "exclusions.json", "prediction_status.json", "record.schema.json", } def read_rows(path): return [json.loads(s) for s in path.read_text().splitlines() if s.strip()] def hash_events(events): return hashlib.sha256(json.dumps(events, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False).encode()).hexdigest() def validate(root): dataset = json.loads((root / "dataset.json").read_text()) for name, expected in dataset["files"].items(): assert hashlib.sha256((root / name).read_bytes()).hexdigest() == expected, f"File hash mismatch: {name}" refs, preds = read_rows(root / "references.jsonl"), read_rows(root / "predictions/longcap-35b-a3b-fp8.jsonl") manifest = {r["key"]: r for r in read_rows(root / "manifest.jsonl")} sources = {r["key"]: r for r in read_rows(root / "sources.jsonl")} provenance = {r["key"]: r["events"] for r in read_rows(root / "event_provenance.jsonl")} assert len(refs) == len(preds) == len(manifest) == len(sources) == 4 assert {r["key"] for r in refs} == {r["key"] for r in preds} == set(COUNTS) assert sum(len(r["events"]) for r in refs) == 6520 assert sum(len(r["events"]) for r in preds) == 6505 for collection, label in ((refs, "reference"), (preds, "prediction")): for row in collection: key = row["key"] assert set(row) <= {"key", "subset", "duration", "evaluated_event_types", "events"} assert row["duration"] == sources[key]["expected_frames"] / 16000 assert hash_events(row["events"]) == manifest[key][label + "_events_sha256"] for event in row["events"]: assert set(event) == {"start", "end", "attributes"} assert all(isinstance(event[t], (float, int)) and not isinstance(event[t], bool) and math.isfinite(event[t]) for t in ("start", "end")) assert event["attributes"]["type"] in ("speech", "music", "sound_event") assert not {"ancestor", "ancestors", "event_index"}.intersection(event["attributes"]) if label == "reference": assert 0 <= event["start"] < event["end"] <= row["duration"] if label == "reference": assert len(row["events"]) == len(provenance[key]) == COUNTS[key] excluded = json.loads((root / "exclusions.json").read_text())["source_event_id"] assert all(e["source_event_id"] != excluded for events in provenance.values() for e in events) for source in sources.values(): assert urlsplit(source["source_url"]).scheme == "https" assert source["media_included"] is False assert source["source_url_kind"] in {"video_media", "video_page"} notes = json.loads((root / "annotation_notes.json").read_text())["recordings"] assert sum(len(r["events_over_60_seconds"]) for r in notes) == 22 assert sum(len(r["annotation_gaps_over_15_seconds"]) for r in notes) == 10 assert sum(len(r["events_clipped_at_audio_end"]) for r in notes) == 1 statuses = json.loads((root / "prediction_status.json").read_text())["recordings"] assert sum(r["truncated"] for r in statuses) == 3 for path in root.rglob("*"): # Ignore Git and download-tool metadata such as .gitattributes and .cache/. if any(part.startswith(".") for part in path.relative_to(root).parts): continue assert not path.is_symlink(), f"Symlink not allowed: {path}" assert path.suffix.lower() not in MEDIA_SUFFIXES, f"Media/archive not allowed: {path}" if path.is_file(): assert path.relative_to(root).as_posix() in PUBLIC_FILES, f"Unlisted release file: {path}" return {"valid": True, "recordings": 4, "reference_events": 6520, "prediction_events": 6505, "known_annotation_gaps": 10, "long_reference_events": 22, "partial_prediction_recordings": 3, "media_files": 0, "source_url_reconstruction_verified": False} if __name__ == "__main__": p = argparse.ArgumentParser(description=__doc__) p.add_argument("--root", type=Path, default=Path(__file__).resolve().parent) print(json.dumps(validate(p.parse_args().root), indent=2))