Datasets:
Download scripts/qa_gate.py from addyo07/vox-tier2-backup: direct link, hf CLI and curl.
- Browser
- Download file 4.46 kB
-
https://huggingface.co/datasets/addyo07/vox-tier2-backup/resolve/main/scripts/qa_gate.py
- Command line
-
hf download hf://datasets/addyo07/vox-tier2-backup/scripts/qa_gate.py
-
curl -L -o qa_gate.py https://huggingface.co/datasets/addyo07/vox-tier2-backup/resolve/main/scripts/qa_gate.py
4.46 kB
| """Corpus QA reporter — deterministic full re-verification of a committed dataset. | |
| Single-label non-autoregressive speech disfluency contract: | |
| 1. Category must be CLEAN or DISFLUENCY. | |
| 2. All spans must have label "speech disfluency". | |
| 3. Zero targets in spans. | |
| 4. Clean speech emits spans: []. | |
| 5. Roundtrip slice-cut excision must exactly reconstruct clean_text. | |
| 6. Entity/Number conservation, pronoun safety, Tier-1 filler free. | |
| """ | |
| import argparse | |
| import json | |
| import re | |
| import sys | |
| from collections import Counter | |
| sys.path.insert(0, "/opt/vox/sandbox/scripts") | |
| from compiler import verify_roundtrip | |
| from dedup import PROTECTED, TIER1, TIER1_ANY, near_dup, norm_tokens | |
| from schema import DatasetExample | |
| # Imported from dedup so the gate and the harvester can never drift apart. | |
| SAFE_SPAN = PROTECTED | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("dataset") | |
| ap.add_argument("--near-dup-jaccard", type=float, default=0.85) | |
| ap.add_argument("--max-pairs", type=int, default=200000) | |
| ap.add_argument("--report", default=None) | |
| args = ap.parse_args() | |
| fails = Counter() | |
| examples = {} | |
| ids, raws, fps = set(), set(), [] | |
| n = 0 | |
| for ln, line in enumerate(open(args.dataset), 1): | |
| line = line.strip() | |
| if not line: | |
| continue | |
| n += 1 | |
| try: | |
| ex = DatasetExample(**{k: v for k, v in json.loads(line).items() | |
| if k in DatasetExample.model_fields}) | |
| except Exception as e: | |
| fails["1_schema"] += 1 | |
| examples.setdefault("1_schema", (ln, str(e)[:80])) | |
| continue | |
| if ex.category not in {"DISFLUENCY", "CLEAN"}: | |
| fails["1_schema"] += 1 | |
| examples.setdefault("1_schema", (ln, f"Invalid category: {ex.category}")) | |
| if ex.id in ids: | |
| fails["2_id_unique"] += 1 | |
| examples.setdefault("2_id_unique", (ln, ex.id)) | |
| ids.add(ex.id) | |
| key = ex.raw_text.strip().lower() | |
| if key in raws: | |
| fails["3_exact_unique"] += 1 | |
| raws.add(key) | |
| fp = norm_tokens(ex.raw_text) | |
| if near_dup(fp, fps, args.near_dup_jaccard): | |
| fails["4_near_unique"] += 1 | |
| examples.setdefault("4_near_unique", (ln, ex.raw_text[:70])) | |
| if len(fps) < args.max_pairs: | |
| fps.append(fp) | |
| if ex.raw_text.strip()[-1:] not in ".?!\u0964" or \ | |
| ex.clean_text.strip()[-1:] not in ".?!\u0964": | |
| fails["10_boundary"] += 1 | |
| if ex.category == "CLEAN": | |
| if ex.spans: | |
| fails["5_clean_has_spans"] += 1 | |
| continue | |
| for s in ex.spans: | |
| if s.label != "speech disfluency": | |
| fails["1_schema"] += 1 | |
| examples.setdefault("1_schema", (ln, f"Invalid span label: {s.label}")) | |
| ok, rec = verify_roundtrip(ex.raw_text, ex.spans, ex.clean_text) | |
| if not ok: | |
| fails["5_roundtrip"] += 1 | |
| examples.setdefault("5_roundtrip", (ln, f"{rec!r} != {ex.clean_text!r}")) | |
| continue | |
| for s in ex.spans: | |
| t = s.text.strip() | |
| if TIER1.match(t) or TIER1_ANY.search(t): | |
| fails["8_tier1_free"] += 1 | |
| examples.setdefault("8_tier1_free", (ln, t[:40])) | |
| if t.lower().strip(",. ") in SAFE_SPAN: | |
| fails["9_pronoun_safe"] += 1 | |
| examples.setdefault("9_pronoun_safe", (ln, t[:40])) | |
| if TIER1_ANY.search(ex.clean_text): | |
| fails["11_clean_not_tier1"] += 1 | |
| cats = Counter() | |
| for line in open(args.dataset): | |
| try: | |
| cats[json.loads(line).get("category", "?")] += 1 | |
| except Exception: | |
| pass | |
| total = sum(fails.values()) | |
| print(f"dataset: {args.dataset}") | |
| print(f"examples: {n} categories: {dict(cats)}") | |
| if not fails: | |
| print("QA REPORT: CLEAN — all deterministic checks pass") | |
| else: | |
| print(f"QA REPORT: {total} violation(s)") | |
| for k in sorted(fails): | |
| print(f" {k}: {fails[k]} e.g. {examples.get(k)}") | |
| if args.report: | |
| json.dump({"dataset": args.dataset, "examples": n, | |
| "categories": dict(cats), "violations": dict(fails), | |
| "examples_of_violation": {k: list(v) for k, v in examples.items()}}, | |
| open(args.report, "w"), indent=2) | |
| sys.exit(1 if fails else 0) | |
| if __name__ == "__main__": | |
| main() | |