ICM-Bench / scripts /validate_release.py
ryanren0330's picture
Add files using upload-large-folder tool
91fb04a verified
Raw
History Blame Contribute Delete
2.55 kB
#!/usr/bin/env python3
import hashlib
import json
import re
import tarfile
from collections import Counter
from pathlib import Path
root = Path(__file__).resolve().parents[1]
qa = [json.loads(line) for line in (root / "annotations/qa_test.jsonl").read_text().splitlines() if line]
videos = [json.loads(line) for line in (root / "videos/metadata.jsonl").read_text().splitlines() if line]
assert len(qa) == 1217, len(qa)
assert len(videos) == 839, len(videos)
assert Counter(x["category"] for x in qa) == {
"Identity Recall": 400,
"Cross-Episode Identity Retrieval": 500,
"Long-Term Identity Profile Inference": 317,
}
ids = {x["video_id"] for x in videos}
assert ids == {f"clip_{index:03d}" for index in range(839)}
with tarfile.open(root / "videos.tar", "r") as archive:
archived_ids = {Path(name).stem for name in archive.getnames() if name.endswith(".mp4")}
assert archived_ids == ids
assert not list((root / "videos").glob("clip_*.mp4"))
video_fields = {"file_name", "video_id", "date", "duration_seconds", "is_calibration"}
assert all(set(row) == video_fields for row in videos)
for row in qa:
assert "evidence_shot_ids" not in row
assert set(row["evidence_video_ids"]) <= ids
assert "category_id" not in row
assert "evidence_id_namespace" not in row
assert "evidence_metadata_status" not in row
assert "access_policy" not in row
if row["category"] == "Long-Term Identity Profile Inference":
assert row["before_clip"] is None
else:
assert row["before_clip"] in ids
latest_evidence = max(int(value.removeprefix("clip_")) for value in row["evidence_video_ids"])
target_delay = 5 + int(hashlib.sha256(row["question_id"].encode("utf-8")).hexdigest()[:8], 16) % 16
expected_before_clip = f"clip_{min(838, latest_evidence + target_delay):03d}"
assert row["before_clip"] == expected_before_clip
profile = [row for row in qa if row["category"] == "Long-Term Identity Profile Inference"]
assert all(len(row["evidence_video_ids"]) >= 2 for row in profile)
speaker_pattern = re.compile(r"\b(?:Li Ming|Wang Lin|Zhang Hua|Li Jian|Chen Tao|Sarah Wu):\s*")
speakerless = sorted((root / "resources/asr_transcripts").glob("*.srt"))
labeled = sorted((root / "resources/transcripts_with_speakers").glob("*.srt"))
assert len(speakerless) == len(labeled) == 829
assert [path.name for path in speakerless] == [path.name for path in labeled]
assert all(not speaker_pattern.search(path.read_text()) for path in speakerless)
print("ICM-Bench release validation passed.")