revision: NCM on our data at 50,000 updates (weights, curves, results), clue-set scores, README
5f0b693 verified Download revision/code/convert_rrn.py from GOVINDFROM/parallel-consistent-masked-diffusion: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/GOVINDFROM/parallel-consistent-masked-diffusion/resolve/main/revision/code/convert_rrn.py
- Command line
-
hf download hf://GOVINDFROM/parallel-consistent-masked-diffusion/revision/code/convert_rrn.py
-
curl -L -o convert_rrn.py https://huggingface.co/GOVINDFROM/parallel-consistent-masked-diffusion/resolve/main/revision/code/convert_rrn.py
1.57 kB
| """Convert the RRN `sudoku-hard` CSVs (Palm et al., 2018) to this repository's arrays. | |
| Each CSV line is `puzzle,solution`, 81 digits each, 0 for a blank. The output is | |
| `<split>_puz.npy` / `<split>_sol.npy`, int64 of shape (N, 81), the layout that | |
| `src/train_sudoku.py --hard` and `ncm/eval_ours.py --data` read. | |
| curl -L -o sudoku-hard.zip "https://www.dropbox.com/s/rp3hbjs91xiqdgc/sudoku-hard.zip?dl=1" | |
| unzip sudoku-hard.zip | |
| python ncm/convert_rrn.py --src sudoku-hard --out data/rrn | |
| """ | |
| import argparse | |
| from pathlib import Path | |
| import numpy as np | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__) | |
| ap.add_argument("--src", type=Path, required=True, help="folder holding train.csv, valid.csv, test.csv") | |
| ap.add_argument("--out", type=Path, required=True) | |
| a = ap.parse_args() | |
| a.out.mkdir(parents=True, exist_ok=True) | |
| for split in ("train", "valid", "test"): | |
| rows = [l.strip().split(",") for l in open(a.src / f"{split}.csv") if l.strip()] | |
| puz = np.array([[int(c) for c in p] for p, _ in rows], dtype=np.int64) | |
| sol = np.array([[int(c) for c in s] for _, s in rows], dtype=np.int64) | |
| assert puz.shape[1] == sol.shape[1] == 81 and sol.min() >= 1 | |
| assert ((puz == 0) | (puz == sol)).all(), "a clue disagrees with its solution" | |
| np.save(a.out / f"{split}_puz.npy", puz) | |
| np.save(a.out / f"{split}_sol.npy", sol) | |
| clues = (puz > 0).sum(1) | |
| print(f"{split}: {len(puz):,} puzzles, {clues.min()}-{clues.max()} clues") | |
| if __name__ == "__main__": | |
| main() | |