{"id":13648386,"url":"https://github.com/Kyubyong/sudoku","last_synced_at":"2025-04-22T07:31:25.947Z","repository":{"id":41497684,"uuid":"76819036","full_name":"Kyubyong/sudoku","owner":"Kyubyong","description":"Can Neural Networks Crack Sudoku?","archived":false,"fork":false,"pushed_at":"2023-02-17T05:22:35.000Z","size":100,"stargazers_count":840,"open_issues_count":4,"forks_count":130,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-12T22:36:18.509Z","etag":null,"topics":["convolutional-neural-networks","number","puzzle","sudoku"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kyubyong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-19T01:52:51.000Z","updated_at":"2025-04-08T08:42:05.000Z","dependencies_parsed_at":"2024-01-14T10:59:08.895Z","dependency_job_id":"3e9e10ad-0847-4883-917b-0fe5405dd8bb","html_url":"https://github.com/Kyubyong/sudoku","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Fsudoku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Fsudoku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Fsudoku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Fsudoku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kyubyong","download_url":"https://codeload.github.com/Kyubyong/sudoku/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250195033,"owners_count":21390230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolutional-neural-networks","number","puzzle","sudoku"],"created_at":"2024-08-02T01:04:11.829Z","updated_at":"2025-04-22T07:31:25.925Z","avatar_url":"https://github.com/Kyubyong.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Can Convolutional Neural Networks Crack Sudoku Puzzles?\n\nSudoku is a popular number puzzle that requires you to fill blanks in a 9X9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids contains all of the digits from 1 to 9. There have been various approaches to solving that, including computational ones. In this project, I show that simple convolutional neural networks have the potential to crack Sudoku without any rule-based postprocessing.\n\n## Requirements\n  * NumPy \u003e= 1.11.1\n  * TensorFlow == 1.1\n\t\n## Background\n* To see what Sudoku is, check the [wikipedia](https://en.wikipedia.org/wiki/Sudoku)\n* To investigate this task comprehensively, read through [McGuire et al. 2013](https://arxiv.org/pdf/1201.0749.pdf).\n\n## Dataset\n* 1M games were generated using `generate_sudoku.py` for training. I've uploaded them on the Kaggle dataset storage. They are available [here](https://www.kaggle.com/bryanpark/sudoku/downloads/sudoku.zip).\n* 30 authentic games were collected from http://1sudoku.com.\n\n## Model description\n* 10 blocks of convolution layers of kernel size 3.\n\n## File description\n  * `generate_sudoku.py` create sudoku games. You don't have to run this. Instead, download [pre-generated games](https://www.kaggle.com/bryanpark/sudoku/downloads/sudoku.zip).\n  * `hyperparams.py` includes all adjustable hyper parameters.\n  * `data_load.py` loads data and put them in queues so multiple mini-bach data are generated in parallel.\n  * `modules.py` contains some wrapper functions.\n  * `train.py` is for training.\n  * `test.py` is for test.\n  \n\n## Training\n* STEP 1. Download and extract [training data](https://www.kaggle.com/bryanpark/sudoku).\n* STEP 2. Run `python train.py`. Or download the [pretrained file](https://www.dropbox.com/s/ipnwnorc7nz5hpe/logdir.tar.gz?dl=0).\n\n## Test\n* Run `python test.py`.\n\n## Evaluation Metric\n\nAccuracy is defined as \n\nNumber of blanks where the prediction matched the solution / Number of blanks.\n\n## Results\n\nAfter a couple of hours of training, the training curve seems to reach the optimum. \n\n\u003cimg src=\"fig/training_curve.png\"\u003e\nI use a simple trick in inference. Instead of cracking the whole blanks all at once, I fill in a single blank where the prediction is the most probable among the all predictions. As can be seen below, my model scored 0.86 in accuracy. Details are available in the `results` folder.\n\n\n \n| Level  |  Accuracy (#correct/#blanks=acc.) |\n| ---    |---     |\n|Easy|**47/47 = 1.00**|\n|Easy|**45/45 = 1.00**|\n|Easy|**47/47 = 1.00**|\n|Easy|**45/45 = 1.00**|\n|Easy|**47/47 = 1.00**|\n|Easy|**46/46 = 1.00**|\n|Medium|33/53 = 0.62|\n|Medium|**55/55 = 1.00**|\n|Medium|**55/55 = 1.00**|\n|Medium|**53/53 = 1.00**|\n|Medium|33/52 = 0.63|\n|Medium|51/56 = 0.91|\n|Hard|29/56 = 0.52|\n|Hard|**55/55 = 1.00**|\n|Hard|27/55 = 0.49|\n|Hard|**57/57 = 1.00**|\n|Hard|35/55 = 0.64|\n|Hard|15/56 = 0.27|\n|Expert|**56/56 = 1.00**|\n|Expert|**55/55 = 1.00**|\n|Expert|**54/54 = 1.00**|\n|Expert|**55/55 = 1.00**|\n|Expert|17/55 = 0.31|\n|Expert|**54/54 = 1.00**|\n|Evil|**50/50 = 1.00**|\n|Evil|**50/50 = 1.00**|\n|Evil|**49/49 = 1.00**|\n|Evil|28/53 = 0.53|\n|Evil|**51/51 = 1.00**|\n|Evil|**51/51 = 1.00**|\n|Total Accuracy| 1345/1568 = _0.86_|\n\n## References\n\nIf you use this code for research, please cite:\n\n```\n@misc{sudoku2018,\n  author = {Park, Kyubyong},\n  title = {Can Convolutional Neural Networks Crack Sudoku Puzzles?},\n  year = {2018},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/Kyubyong/sudoku}}\n}\n```\n\n## Papers that referenced this repository\n\n  * [OptNet: Differentiable Optimization as a Layer in Neural Networks](http://proceedings.mlr.press/v70/amos17a/amos17a.pdf)\n  * [Recurrent Relational Networks for Complex Relational Reasoning](https://arxiv.org/abs/1711.08028)\n  * [SATNet: Bridging deep learning and logical reasoning using a differentiable satisfiability solver](https://arxiv.org/abs/1905.12149)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyubyong%2Fsudoku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKyubyong%2Fsudoku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyubyong%2Fsudoku/lists"}