Download scripts/prepare.py from scx-admin/aussie-1k: direct link, hf CLI and curl.
- Browser
- Download file 6.45 kB
-
https://huggingface.co/datasets/scx-admin/aussie-1k/resolve/main/scripts/prepare.py
- Command line
-
hf download hf://datasets/scx-admin/aussie-1k/scripts/prepare.py
-
curl -L -o prepare.py https://huggingface.co/datasets/scx-admin/aussie-1k/resolve/main/scripts/prepare.py
6.45 kB
| #!/usr/bin/env python3 | |
| """Rebuild the v6.1 benchmark and audit files using only the standard library.""" | |
| import hashlib | |
| import json | |
| import unicodedata | |
| from collections import Counter | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| SOURCE_SHA256 = "5308a7c86264b258a98be729b322dcab4aa978086460efaccf9e88cf80aac246" | |
| VERSION = "6.1" | |
| def digest(data): | |
| return hashlib.sha256(data).hexdigest() | |
| def normalise(text): | |
| return unicodedata.normalize("NFC", text).strip() | |
| def write_jsonl(path, rows): | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text( | |
| "".join(json.dumps(row, ensure_ascii=False, separators=(",", ":")) + "\n" for row in rows), | |
| encoding="utf-8", | |
| ) | |
| def build(): | |
| source = ROOT / "source/v6.jsonl" | |
| raw = source.read_bytes() | |
| if digest(raw) != SOURCE_SHA256: | |
| raise ValueError("Source differs from the frozen v6 dataset; create a new release instead.") | |
| groups = {} | |
| audit = [] | |
| original = [] | |
| changed_rows = 0 | |
| for line_number, line in enumerate(raw.decode("utf-8").splitlines(), 1): | |
| if not line.strip(): | |
| continue | |
| row = json.loads(line) | |
| if set(row) != {"question", "answer", "decision", "reason", "scores"}: | |
| raise ValueError(f"Unexpected source fields on line {line_number}") | |
| if not all(isinstance(row[key], str) and row[key].strip() | |
| for key in ("question", "answer", "decision", "reason")): | |
| raise ValueError(f"Invalid text fields on line {line_number}") | |
| if row["decision"] not in {"keep", "rewrite"}: | |
| raise ValueError(f"Unexpected decision on line {line_number}") | |
| if set(row["scores"]) != {"difficulty", "obscurity", "quality"}: | |
| raise ValueError(f"Unexpected scores on line {line_number}") | |
| if not all(type(value) is int and 1 <= value <= 5 for value in row["scores"].values()): | |
| raise ValueError(f"Invalid scores on line {line_number}") | |
| original.append(row) | |
| question, answer = normalise(row["question"]), normalise(row["answer"]) | |
| changed_rows += (question != row["question"] or answer != row["answer"]) | |
| if question not in groups: | |
| groups[question] = { | |
| "id": "aussieqa-" + digest(question.encode("utf-8"))[:20], | |
| "question": question, | |
| "answers": [], | |
| } | |
| item = groups[question] | |
| if answer not in item["answers"]: | |
| item["answers"].append(answer) | |
| audit.append({ | |
| "id": item["id"], | |
| "source_version": "6", | |
| "source_line": line_number, | |
| "answer_index": item["answers"].index(answer), | |
| "curation_decision": row["decision"], | |
| "curation_reason": row["reason"], | |
| "curation_scores": row["scores"], | |
| }) | |
| rows = list(groups.values()) | |
| assert len(original) == 1000 | |
| assert len(rows) == 984 | |
| assert len({row["id"] for row in rows}) == len(rows), "ID collision" | |
| assert sum(len(row["answers"]) for row in rows) == 998 | |
| # Every source answer and all curation fields must remain recoverable. | |
| by_id = {row["id"]: row for row in rows} | |
| for source_row, record in zip(original, audit): | |
| item = by_id[record["id"]] | |
| assert item["question"] == normalise(source_row["question"]) | |
| assert item["answers"][record["answer_index"]] == normalise(source_row["answer"]) | |
| assert record["curation_scores"] == source_row["scores"] | |
| assert record["curation_decision"] == source_row["decision"] | |
| assert record["curation_reason"] == source_row["reason"] | |
| write_jsonl(ROOT / "data/v6.1/test.jsonl", rows) | |
| write_jsonl(ROOT / "metadata/v6.1/curation.jsonl", audit) | |
| question_counts = Counter(row["question"] for row in original) | |
| manifest = { | |
| "dataset": "Aussie-1k", | |
| "repository": "scx-admin/aussie-1k", | |
| "version": VERSION, | |
| "release_date": "2026-10-13", | |
| "source_version": "6", | |
| "source_file_modified_date": "2025-11-18", | |
| "language": "en-AU", | |
| "split": "test", | |
| "source_records": len(original), | |
| "test_records": len(rows), | |
| "reference_answers": sum(len(row["answers"]) for row in rows), | |
| "answer_count_distribution": dict(sorted(Counter(len(row["answers"]) for row in rows).items())), | |
| "source_repeated_question_groups": sum(n > 1 for n in question_counts.values()), | |
| "merged_question_occurrences": len(original) - len(rows), | |
| "deduplicated_question_answer_occurrences": len(original) - sum(len(row["answers"]) for row in rows), | |
| "normalised_text_rows": changed_rows, | |
| "source_curation_decisions": dict(sorted(Counter(row["decision"] for row in original).items())), | |
| "source_curation_score_distributions": { | |
| key: {str(score): sum(row["scores"][key] == score for row in original) for score in range(1, 6)} | |
| for key in ("difficulty", "obscurity", "quality") | |
| }, | |
| "id_algorithm": "aussieqa- + first 20 hexadecimal characters of SHA-256 of NFC-normalised, stripped UTF-8 question", | |
| "ordering": "First occurrence of each normalised question in v6; answers in first occurrence order", | |
| "transformations": [ | |
| "Validate source SHA-256 and record schema", | |
| "Normalise question and answer text to Unicode NFC and strip outer whitespace (zero changes in this source)", | |
| "Group identical normalised questions; retain every distinct normalised answer", | |
| "Assign question-content IDs and expose only id, question, answers in the test split", | |
| "Move original curation metadata and source line mapping into a separate audit file", | |
| ], | |
| "files": {}, | |
| } | |
| for relative in ("source/v6.jsonl", "data/v6.1/test.jsonl", "metadata/v6.1/curation.jsonl"): | |
| contents = (ROOT / relative).read_bytes() | |
| manifest["files"][relative] = {"sha256": digest(contents), "bytes": len(contents)} | |
| target = ROOT / "metadata/v6.1/manifest.json" | |
| target.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps({"version": VERSION, "source_rows": len(original), "test_rows": len(rows), | |
| "reference_answers": manifest["reference_answers"], "normalised_text_rows": changed_rows})) | |
| if __name__ == "__main__": | |
| build() | |