Download src/buddi_asr/data/validate.py from NabuxAi/buddi-asr-source-code: direct link, hf CLI and curl.
- Browser
- Download file 2.87 kB
-
https://huggingface.co/datasets/NabuxAi/buddi-asr-source-code/resolve/main/src/buddi_asr/data/validate.py
- Command line
-
hf download hf://datasets/NabuxAi/buddi-asr-source-code/src/buddi_asr/data/validate.py
-
curl -L -o validate.py https://huggingface.co/datasets/NabuxAi/buddi-asr-source-code/resolve/main/src/buddi_asr/data/validate.py
2.87 kB
| """Manifest integrity, privacy, and split-leakage checks.""" | |
| from __future__ import annotations | |
| from collections import Counter, defaultdict | |
| from pathlib import Path | |
| from typing import Any | |
| from buddi_asr.data.manifest import read_manifest, resolve_audio_path | |
| def validate_manifest(path: str | Path, *, check_audio: bool = True) -> dict[str, Any]: | |
| manifest_path = Path(path).resolve() | |
| records = list(read_manifest(manifest_path)) | |
| errors: list[str] = [] | |
| warnings: list[str] = [] | |
| seen_audio: set[str] = set() | |
| speaker_splits: dict[str, set[str]] = defaultdict(set) | |
| split_counts: Counter[str] = Counter() | |
| language_counts: Counter[str] = Counter() | |
| source_counts: Counter[str] = Counter() | |
| parse_quality_counts: Counter[str] = Counter() | |
| missing_duration = 0 | |
| for index, record in enumerate(records, start=1): | |
| if record.audio in seen_audio: | |
| errors.append(f"duplicate audio path at record {index}: {record.audio}") | |
| seen_audio.add(record.audio) | |
| if check_audio and not resolve_audio_path(record, manifest_path).is_file(): | |
| errors.append(f"audio not found at record {index}: {record.audio}") | |
| if record.duration_sec is None: | |
| missing_duration += 1 | |
| if record.split: | |
| speaker_splits[record.speaker_id].add(record.split) | |
| split_counts[record.split] += 1 | |
| language_counts[record.language] += 1 | |
| source_counts[record.source] += 1 | |
| quality = record.metadata.get("speaker_parse_quality") | |
| if isinstance(quality, str): | |
| parse_quality_counts[quality] += 1 | |
| leaking_speakers = { | |
| speaker: sorted(splits) for speaker, splits in speaker_splits.items() if len(splits) > 1 | |
| } | |
| if leaking_speakers: | |
| examples = list(sorted(leaking_speakers.items()))[:5] | |
| errors.append( | |
| f"{len(leaking_speakers)} speaker IDs cross split boundaries; examples: {examples}" | |
| ) | |
| session_only = parse_quality_counts.get("session_only", 0) | |
| if session_only: | |
| warnings.append( | |
| f"{session_only} records have session-only speaker grouping; final speaker-disjoint " | |
| "metrics require manual anonymous overrides or upstream speaker metadata" | |
| ) | |
| if missing_duration: | |
| warnings.append(f"{missing_duration} records do not have a probed duration") | |
| return { | |
| "ok": not errors, | |
| "manifest": str(manifest_path), | |
| "records": len(records), | |
| "speakers": len({record.speaker_id for record in records}), | |
| "errors": errors, | |
| "warnings": warnings, | |
| "splits": dict(sorted(split_counts.items())), | |
| "languages": dict(sorted(language_counts.items())), | |
| "sources": dict(sorted(source_counts.items())), | |
| "speaker_parse_quality": dict(sorted(parse_quality_counts.items())), | |
| } | |