Download create_dataset.py from Exxe/crossword-construction-logic: direct link, hf CLI and curl.
- Browser
- Download file 7.27 kB
-
https://huggingface.co/datasets/Exxe/crossword-construction-logic/resolve/main/create_dataset.py
- Command line
-
hf download hf://datasets/Exxe/crossword-construction-logic/create_dataset.py
-
curl -L -o create_dataset.py https://huggingface.co/datasets/Exxe/crossword-construction-logic/resolve/main/create_dataset.py
7.27 kB
| #!/usr/bin/env python3 | |
| """ | |
| create_dataset.py — Provenance script for the crossword-construction-logic | |
| dataset (v1). | |
| The dataset teaches the CONSTRUCTION LOGIC of crossword puzzles: numbering, | |
| crossing contracts, candidate arithmetic (MRV + constraint propagation), | |
| shadow-entry verification, duplicate rules, declared conventions, grid | |
| diagnosis, and verification discipline — in five languages (en, ru, zh, hi, | |
| ja), on machine-verified mini grids, with every machine-checkable claim | |
| re-derived at import time by the generator modules. | |
| Reads raw rows from raw.jsonl, builds sharded parquet, and writes stats.json. | |
| Re-runnable: produces identical output given the same raw.jsonl and seed. | |
| USAGE | |
| ----- | |
| python create_dataset.py | |
| Inputs: ./raw.jsonl (420 rows; composition below) | |
| ./features.json (schema: 12 fields, all string) | |
| Outputs: ./data/train-*.parquet, ./data/test-*.parquet, ./stats.json | |
| DATASET COMPOSITION | |
| ------------------- | |
| 420 rows total in 5 languages, 9 task types: | |
| - 365 positive examples (quality: good) | |
| - 33 flawed examples (quality: flawed — recoverable construction defects, | |
| presented for diagnosis) | |
| - 22 bad examples (quality: bad — hallucinated grids, phantom verification | |
| reports, script/layer confusions; for critic training) | |
| Languages: | |
| - en (English): 228 rows (the teaching backbone incl. cryptic clues) | |
| - ru (Russian): 48 rows (native Cyrillic narration) | |
| - zh (Chinese): 48 rows (native simplified-Chinese narration) | |
| - hi (Hindi): 48 rows (native Devanagari narration) | |
| - ja (Japanese): 48 rows (native Japanese narration) | |
| Task types (all languages share the same machinery): | |
| - design_grid (54), fill_grid (56), fill_trace (40), diagnose_failure (50), | |
| write_clues (60), cryptic_clue (28, en only), validate_puzzle (40), | |
| methodology_qa (85), historical_note (7) | |
| Verification discipline (the dataset's core property): | |
| - every catalog grid re-validates on import (grids.check_fill: pool | |
| membership, crossing agreement, duplicates, minimum length, no unchecked | |
| cells); | |
| - every narrated solver number (candidate counts, node ledgers, forced | |
| cascades, shadow completions) comes from the actual solver and is | |
| re-asserted at import; | |
| - a dataset-level battery (see project worklog; generate the same via the | |
| source modules) additionally re-checks claims, script purity, field | |
| consistency, and quotas against raw.jsonl itself. | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| # Allow importing from the skill's scripts/ directory | |
| SKILL_SCRIPTS = "/home/z/my-project/skills/dataset-producer/scripts" | |
| sys.path.insert(0, SKILL_SCRIPTS) | |
| try: | |
| from produce_dataset import produce_dataset, load_features | |
| except ImportError: | |
| print("ERROR: produce_dataset.py not found at " + SKILL_SCRIPTS, file=sys.stderr) | |
| sys.exit(1) | |
| # ─── Constants ───────────────────────────────────────────────────────────── | |
| DATASET_NAME = "crossword-construction-logic" | |
| RAW_PATH = Path(__file__).parent / "raw.jsonl" | |
| FEATURES_PATH = Path(__file__).parent / "features.json" | |
| SEED = 42 | |
| SPLITS = {"train": 0.85, "test": 0.15} | |
| SHARD_SIZE = "500KB" | |
| # ─── Feature schema (12 fields) ──────────────────────────────────────────── | |
| FEATURES = { | |
| "instruction": {"_type": "Value", "dtype": "string"}, | |
| "input": {"_type": "Value", "dtype": "string"}, | |
| "output": {"_type": "Value", "dtype": "string"}, | |
| "task_type": {"_type": "Value", "dtype": "string"}, | |
| "language": {"_type": "Value", "dtype": "string"}, | |
| "quality": {"_type": "Value", "dtype": "string"}, | |
| "puzzle_style": {"_type": "Value", "dtype": "string"}, | |
| "grid_size": {"_type": "Value", "dtype": "string"}, | |
| "difficulty": {"_type": "Value", "dtype": "string"}, | |
| "source_format": {"_type": "Value", "dtype": "string"}, | |
| "verified": {"_type": "Value", "dtype": "string"}, | |
| "id": {"_type": "Value", "dtype": "string"}, | |
| } | |
| # ─── Main ───────────────────────────────────────────────────────────────── | |
| def main(): | |
| print(f"=== Building dataset: {DATASET_NAME} (v1) ===\n") | |
| print(f"Step 1: Loading raw rows from {RAW_PATH}") | |
| if not RAW_PATH.exists(): | |
| print(f" ERROR: {RAW_PATH} not found.", file=sys.stderr) | |
| sys.exit(1) | |
| with open(RAW_PATH, "r", encoding="utf-8") as f: | |
| rows = [json.loads(line) for line in f if line.strip()] | |
| print(f" Loaded {len(rows)} rows\n") | |
| for field in ("task_type", "language", "quality", "puzzle_style", | |
| "grid_size", "difficulty", "source_format", "verified"): | |
| missing = [r["id"] for r in rows if field not in r] | |
| if missing: | |
| print(f" ERROR: rows missing {field} field: {missing}", file=sys.stderr) | |
| sys.exit(1) | |
| out_dir = Path(__file__).parent / "data" | |
| out_dir.mkdir(parents=True, exist_ok=True) | |
| print("Step 2: Building parquet shards and computing stats...") | |
| features = load_features(FEATURES) | |
| stats = produce_dataset( | |
| rows=rows, | |
| features=features, | |
| splits=SPLITS, | |
| out_dir=out_dir, | |
| shard_size=SHARD_SIZE, | |
| seed=SEED, | |
| ) | |
| print("\n=== Production complete ===") | |
| print(f"Total examples: {stats['total_examples']:,}") | |
| print(f"Download size: {stats['total_download_size']:,} bytes") | |
| print(f"Dataset size: {stats['total_dataset_size']:,} bytes") | |
| print(f"Size bucket: {stats['size_categories']}") | |
| print(f"\nSplits:") | |
| for name, s in stats["splits"].items(): | |
| print(f" {name}: {s['num_examples']:,} rows, {len(s['shards'])} shard(s)") | |
| from collections import Counter | |
| quality_counts = Counter(r["quality"] for r in rows) | |
| language_counts = Counter(r["language"] for r in rows) | |
| task_counts = Counter(r["task_type"] for r in rows) | |
| print(f"\nQuality breakdown:") | |
| for q in ["good", "flawed", "bad"]: | |
| print(f" {q}: {quality_counts.get(q, 0)}") | |
| print(f"\nLanguage breakdown:") | |
| for lang in ["en", "ru", "zh", "hi", "ja"]: | |
| print(f" {lang}: {language_counts.get(lang, 0)}") | |
| print(f"\nTask-type breakdown:") | |
| for t, n in task_counts.most_common(): | |
| print(f" {t}: {n}") | |
| print(f"\nProvenance:") | |
| print(f" - Methodology: construction logic ported from the Crosshare " | |
| f"app's grid/autofill semantics (AGPL-3.0 code studied, logic " | |
| f"re-implemented independently in this project's generator)") | |
| print(f" - Rows written by GLM (Super Z) under the project lead's " | |
| f"editorial direction; every machine-checkable claim generated by " | |
| f"the project solver/grid library and re-asserted at import") | |
| print(f" - Generation date: 2026-10-20") | |
| print(f" - Random seed: {SEED}") | |
| print(f" - Split fractions: {SPLITS}") | |
| print(f" - Shard size: {SHARD_SIZE}") | |
| if __name__ == "__main__": | |
| main() | |