| |
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import sys |
| from pathlib import Path |
|
|
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) |
|
|
| from romani_asr.manifest import read_manifest_csv |
| from romani_asr.transcript_audit import ( |
| TranscriptAuditRow, |
| audit_transcripts, |
| format_markdown_report, |
| ) |
|
|
|
|
| def parse_args() -> argparse.Namespace: |
| parser = argparse.ArgumentParser( |
| description="Audit transcript consistency issues before ASR training." |
| ) |
| parser.add_argument( |
| "--manifest", |
| type=Path, |
| action="append", |
| default=[], |
| help="Manifest CSV to audit. May be passed more than once.", |
| ) |
| parser.add_argument( |
| "--output-dir", |
| type=Path, |
| default=Path("artifacts/analysis/transcript-consistency"), |
| ) |
| parser.add_argument("--top-k", type=int, default=20) |
| return parser.parse_args() |
|
|
|
|
| def default_manifests() -> list[Path]: |
| return [ |
| Path("artifacts/manifests/train.csv"), |
| Path("artifacts/manifests/validation.csv"), |
| Path("artifacts/manifests/test.csv"), |
| ] |
|
|
|
|
| def load_rows(paths: list[Path]) -> list[TranscriptAuditRow]: |
| rows: list[TranscriptAuditRow] = [] |
| for path in paths: |
| for row in read_manifest_csv(path): |
| rows.append( |
| TranscriptAuditRow( |
| id=row["id"], |
| manifest=path.name, |
| transcript=row["transcript"], |
| duration_sec=float(row["duration_sec"]), |
| ) |
| ) |
| return rows |
|
|
|
|
| def main() -> None: |
| args = parse_args() |
| manifests = args.manifest or default_manifests() |
| rows = load_rows(manifests) |
| audit = audit_transcripts(rows, top_k=args.top_k) |
|
|
| args.output_dir.mkdir(parents=True, exist_ok=True) |
| json_path = args.output_dir / "summary.json" |
| md_path = args.output_dir / "summary.md" |
| json_path.write_text( |
| json.dumps(audit, indent=2, ensure_ascii=False), |
| encoding="utf-8", |
| ) |
| report = format_markdown_report(audit) |
| md_path.write_text(report, encoding="utf-8") |
|
|
| print(report, flush=True) |
| print(f"Wrote {json_path}", file=sys.stderr) |
| print(f"Wrote {md_path}", file=sys.stderr) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|