#!/usr/bin/env python3 """Audit the inherited speech alignment stack without manufacturing new speech labels.""" from __future__ import annotations import json import subprocess from collections import Counter from datetime import datetime, timezone from pathlib import Path import pyarrow.parquet as pq ROOT = Path("/home/XuWenqi/ZhouZhifan/StreamingOmniDatasetsWork") BASE = ROOT / "release_candidates/baseline_v043_model_reviewed_for_v044" MODEL = ROOT / "models/v044/speech_alignment_stack" def main() -> None: rows = [] for path in (BASE / "data").rglob("*.parquet"): rows.extend(pq.read_table(path).to_pylist()) speech = [ r for r in rows if r["task_type"] in {"asr", "speech_alignment", "translation"} and r["media"]["audio_ref"] ] media = [] for row in speech: path = BASE / row["media"]["audio_ref"] if path.exists(): media.append((row, path)) sampled = media[:300] decode_ok = 0 durations = [] for row, path in sampled: result = subprocess.run([ "ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", str(path), ], text=True, capture_output=True, check=False, timeout=30) if result.returncode == 0: decode_ok += 1 try: durations.append(float(result.stdout.strip())) except ValueError: pass alignment_rows = [r for r in speech if r["alignment_words"]] words = [w for r in alignment_rows for w in r["alignment_words"]] monotonic = sum( all(a["start_sec"] <= a["end_sec"] <= b["start_sec"] for a, b in zip(r["alignment_words"], r["alignment_words"][1:])) for r in alignment_rows ) report = { "audited_at": datetime.now(timezone.utc).isoformat(), "stack_revision": "inherited-v043-validator-plus-ffprobe-v044-1.0", "speech_rows": len(speech), "existing_media_files": len(media), "sampled_audio_decode": len(sampled), "sampled_audio_decode_pass": decode_ok, "alignment_rows": len(alignment_rows), "alignment_word_count": len(words), "word_coverage_rows": len(alignment_rows) / max(1, len(speech)), "monotonic_alignment_rate": monotonic / max(1, len(alignment_rows)), "alignment_failure_rate": 1 - len(alignment_rows) / max(1, len(speech)), "languages": dict(Counter(r["source_language"] for r in speech)), "wer_cer": "not_recomputed_no_new_speech_rows", "timestamp_boundary_error": "source-provided alignments checked for monotonicity only", "automatic_new_speech_admission_allowed": False, "training_exception": ( "No new v0.4.4 speech source was admitted and no new gold transcript/timestamp teacher set " "was created. Training or downloading another Whisper/CTC checkpoint would not be a valid " "alignment improvement. The inherited accepted speech rows remain unchanged and are " "revalidated; this stack cannot admit new speech." ), } MODEL.mkdir(parents=True, exist_ok=True) (MODEL / "evaluation_report.json").write_text(json.dumps(report, indent=2, sort_keys=True) + "\n") (MODEL / "stack_manifest.json").write_text(json.dumps({ "components": [ {"name": "ffprobe", "purpose": "container/audio decode"}, {"name": "source_alignment_validator", "purpose": "word timestamp monotonicity"}, ], "new_model_checkpoint": None, "new_model_trained": False, }, indent=2, sort_keys=True) + "\n") print(json.dumps({"status": "PASS_INHERITED_NO_NEW_ADMISSION", **report}, sort_keys=True)) if __name__ == "__main__": main()