--- name: multilingual-dataset-quality description: Pharmaceutical-grade (ISO 2859-1 AQL) batch-sampled quality control and multilingual linguistic rubric checker for LLM datasets (local files or Hugging Face Hub), producing a 0-100 score, A-F grade, GMP disposition (RELEASED/QUARANTINE/REJECTED), and transparent Certificate of Analysis. --- # Multilingual Dataset Quality (ISO 2859-1 Batch QC) `scripts/multilingual_quality.py` applies **pharmaceutical-style acceptance sampling (ISO 2859-1 / ANSI ASQ Z1.4 General Level II)** together with **per-language COMPLIN-inspired grammatical checks** and the sibling [`dataset-quality`](https://skills.renaissancelabs.eu/skill/dataset-quality/) skill to evaluate local or Hugging Face datasets. Every run emits a **0–100 quality score**, **letter grade (A–F)**, **GMP batch disposition** (`RELEASED`, `QUARANTINE`, or `REJECTED`), and a transparent **QC Certificate of Analysis** documenting *how* the dataset was sampled and *what* defects were found. Standard library only (Python 3.9+). Run from this skill's folder: ```bash # 1. Check the ISO 2859-1 pharmaceutical sampling plan for a dataset of N rows python3 scripts/multilingual_quality.py plan --lot-size 50000 # 2. Run a seeded random batch QC audit on a local dataset (JSONL/JSON/CSV/TSV/TXT/GZ) python3 scripts/multilingual_quality.py eval data/sv_sft.jsonl --lang sv --stage sft --provenance native-curated --license cc-by-4.0 --seed 42 --out receipt.json # 3. Audit a live Hugging Face dataset (samples stratified random windows across the split) python3 scripts/multilingual_quality.py eval --hf KBLab/riksdagen-records --lang sv --stage pretraining --provenance native-human --license cc0-1.0 --seed 42 # 4. Inspect the per-language grammatical & orthographic rubric for manual verification python3 scripts/multilingual_quality.py rubric --lang sv python3 scripts/multilingual_quality.py rubric --list-languages # 5. Render a Markdown Certificate of Analysis from any saved receipt python3 scripts/multilingual_quality.py report receipt.json ``` ## Pharmaceutical Batch Sampling Protocol (ISO 2859-1 / AQL) Just like incoming batch quality control in pharmaceutical manufacturing (GMP), sample size scales proportionally with the **lot size ($N$)** using **ISO 2859-1 General Inspection Level II** with deterministic seeded random sampling (`--seed 42`) across the full dataset rather than inspecting only the first few rows: | Lot Size ($N$ rows) | Code | Sample Size ($n$) | Critical AQL 1.0% ($Ac$ / $Re$) | Major AQL 2.5% ($Ac$ / $Re$) | |---|---:|---:|---:|---:| | 2–90 | A–E | 2–13 | 0 / 1 | 0–1 / 1–2 | | 91–280 | F–G | 20–32 | 0–1 / 1–2 | 1–2 / 2–3 | | 281–1,200 | H–J | 50–80 | 1–2 / 2–3 | 3–5 / 4–6 | | 1,201–10,000 | K–L | 125–200 | 3–5 / 4–6 | 7–10 / 8–11 | | 10,001–150,000 | M–N | 315–500 | 7–10 / 8–11 | 14–21 / 15–22 | | 150,001+ | P–Q | 800–1,250 | 14–21 / 15–22 | 21 / 22 | ### Defect classes & GMP disposition states - **Critical defects** (`AQL 1.0%`): exposed API/private keys, unparseable/empty rows, UTF-8 mojibake corruption. - **Major defects** (`AQL 2.5%`): wrong Unicode script, non-target-language leakage (missing native function words), translationese / AI-slop clichés. - **Minor defects**: very short fragments or web boilerplate. Every batch receives one of three explicit QC states: - **`RELEASED`**: Passed all AQL acceptance limits ($d_{\text{crit}} \le Ac_{\text{crit}}$, $d_{\text{maj}} \le Ac_{\text{maj}}$), met target sample size, and scored $\ge 80/100$. - **`QUARANTINE`**: Score 60–79 or partial sample coverage ($n_{\text{actual}} < n_{\text{target}}$) — requires cleaning or tightened re-inspection before production training. - **`REJECTED`**: Exceeded Critical or Major AQL Rejection Number ($Re$), or scored $< 60/100$. ## Entropic, Perplexity & Dataset-Wide Diagnostics To look at data quality from **structural**, **sample-level**, and **whole-dataset** perspectives simultaneously, every audit also computes zero-dependency information-theoretic signals: - **Character & Word Shannon Entropy (`char_entropy_bits`, `word_entropy_bits`)**: detects degenerate/repetitive text ($< 2.8$ bits/char) and random/encoded noise ($> 5.6$ bits/char). - **Holdout Bigram Pseudo-Perplexity (`bigram_perplexity` & `high_ppl_outlier_rate`)**: flags both collapsed template generation and high-perplexity outlier rows ($> 2\sigma$ above batch median). - **Per-Document vs Joint-Batch Compression (`mean_doc_zlib_bpb` vs `joint_batch_zlib_bpb`)**: measures **cross-document redundancy** (template collapse across the dataset as a whole). - **Zipf's Law Power-Law Slope (`zipf_alpha`) & `distinct-2`**: checks whether word frequencies follow natural human language scaling ($\alpha \approx 0.85\text{–}1.25$) and rich bigram diversity. ## Agent QC Instructions (Step-by-Step) When asked to evaluate or certify a dataset's quality: 1. **Determine the sampling plan:** Run `plan --lot-size N` (or let `eval` compute it automatically from the file/HF split size). 2. **Execute seeded random batch sampling:** Run `eval` with `--seed 42` so the exact sampled batch is reproducible. 3. **Run manual grammatical rubric review:** Run `rubric --lang ` and inspect 10–20 sampled rows against the language's `grammar_checks` (e.g., Swedish V2 word order & compound nouns, Finnish vowel harmony, Yoruba tone marks, Arabic MSA vs dialect clarity). 4. **Publish the Certificate of Analysis:** Report the score (`0–100`), grade (`A–F`), disposition (`RELEASED` / `QUARANTINE` / `REJECTED`), exact sampling ratio ($n / N$), defect counts, and linguistic findings — or submit it directly to **[Open Data Atlas](https://github.com/RenaissanceLabs-EU/data-atlas/issues/new?template=quality-audit.yml)**. ## Scoring dimensions (0–100) & prior art Powers the quality badges on **[Open Data Atlas](https://data.renaissancelabs.eu/quality/)**, combining: - **[Renaissance Labs `dataset-quality`](https://skills.renaissancelabs.eu/skill/dataset-quality/)** (`hygiene`, 15%): schema, exact & MinHash LSH dedup, Gopher/FineWeb heuristics, zlib density, diversity, PII/secrets. - **[COMPLIN](https://github.com/BirgerMoell/complin)** (`linguistic`, 20%): per-language script purity, diacritic preservation, function-word density, and grammatical checklists across 27 languages. - **[OpenEuroLLM `propella-annotations`](https://huggingface.co/datasets/openeurollm/propella-annotations)** (`value`, 10% + `provenance`, 25% + `license`, 20% + `verification`, 10%): native authenticity, openness, educational/reasoning value, and batch verification.