PyTorch implementation for the Neuro-Symbolic Sudoku Solver leveraging the power of Neural Logic Machines (NLM)

Overview

Neuro-Symbolic Sudoku Solver

PyTorch implementation for the Neuro-Symbolic Sudoku Solver leveraging the power of Neural Logic Machines (NLM). Please note that this is not an officially supported Google product. This project is a direct application of work done as part of original NLM project. We have applied NLM concept to solve more complex (Solving Sudoku) problems.

⭐ Star us on GitHub β€” it helps!

Neural Logic Machine (NLM) is a neural-symbolic architecture for both inductive learning and logic reasoning. NLMs use tensors to represent logic predicates. This is done by grounding the predicate as True or False over a fixed set of objects. Based on the tensor representation, rules are implemented as neural operators that can be applied over the premise tensors and generate conclusion tensors. Learn more about NLM from the paper.

Predicate Logic

We have used below boolean predicates as inputs to NLM architecture:

  1. isRow(r, num): Does number num present in row r inside Sudoku grid?
  2. isColumn(c, num): Does number num present in column c inside Sudoku grid?
  3. isSubMat(r, c, num): Does number num present in 3x3 sub-matrix starting with row r and column c.

Note here that isRow and isColumn are binary predicates and isSubMat is ternary predicate. We have stacked the results of isRow and isColumn and inputted as binary predicate.

The core architecture of the model contains deep reinforcement learning leveraging representation power of first order logic predicates.

Prerequisites

  • Python 3.x
  • PyTorch 0.4.0
  • Jacinle. We use the version ed90c3a for this repo.
  • Other required python packages specified by requirements.txt. See the Installation.

Installation

Clone this repository:

git clone https://github.com/ashutosh1919/neuro-symbolic-sudoku-solver.git --recursive

Install Jacinle included as a submodule. You need to add the bin path to your global PATH environment variable:

export PATH=
   
    /third_party/Jacinle/bin:$PATH

   

Create a conda environment for NLM, and install the requirements. This includes the required python packages from both Jacinle and NLM. Most of the required packages have been included in the built-in anaconda package:

conda create -n nlm anaconda
conda install pytorch torchvision -c pytorch

Usage

This repo is extension of original NLM repository. We haven't removed the codebase of problems solved in the base repository but we are only maintaining the Sudoku codebase in this repository.

Below is the file structure for the code we have added to original repository to understand things better.

The code in difflogic/envs/sudoku contains information about the environment for reinforcement learning. grid.py selects dataset randomly from 1 Million Sudoku Dataset from Kaggle. grid_env.py creates reinforcement learning environment which can perform actions.

The code in scripts/sudoku/learn_policy.py trains the model whereas scripts/sudoku/inference.py generates prediction from trained model.

We also provide pre-trained models for 3 decision-making tasks in models directory,

Taking the Sudoku task as an example.

# To train the model:
$ jac-run scripts/sudoku/learn_policy.py --task sudoku --dump-dir models

# To infer the model:
$ jac-run scripts/sudoku/inference.py --task sudoku --load-checkpoint models/checkpoints/checkpoint_10.pth

Below is the sample output that you should get after running inference.py where the program will generate a problem Sudoku grid and NLM model will solve it.

We have trained model with tuning with different parameters and we got below results.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Ashutosh Hathidara

πŸ’» πŸ€” 🚧 🎨 πŸ“– πŸ’¬ πŸ”¬

pandeylalit9

πŸ’» πŸ€” 🎨 🚧 πŸ”¬ πŸ“– πŸ’¬

This project follows the all-contributors specification. Contributions of any kind welcome!

References

Owner
Ashutosh Hathidara
A passionate individual who always thrive to work on end to end products which develop sustainable and scalable social and technical systems to create impact.
Ashutosh Hathidara
Repository of best practices for deep learning in Julia, inspired by fastai

FastAI Docs: Stable | Dev FastAI.jl is inspired by fastai, and is a repository of best practices for deep learning in Julia. Its goal is to easily ena

FluxML 532 Jan 02, 2023
A toolkit for making real world machine learning and data analysis applications in C++

dlib C++ library Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real worl

Davis E. King 11.6k Jan 01, 2023
PPLNN is a Primitive Library for Neural Network is a high-performance deep-learning inference engine for efficient AI inferencing

PPLNN is a Primitive Library for Neural Network is a high-performance deep-learning inference engine for efficient AI inferencing

943 Jan 07, 2023
KaziText is a tool for modelling common human errors.

KaziText KaziText is a tool for modelling common human errors. It estimates probabilities of individual error types (so called aspects) from grammatic

ÚFAL 3 Nov 24, 2022
PyTorch Implementation of Unsupervised Depth Completion with Calibrated Backprojection Layers (ORAL, ICCV 2021)

Unsupervised Depth Completion with Calibrated Backprojection Layers PyTorch implementation of Unsupervised Depth Completion with Calibrated Backprojec

80 Dec 13, 2022
Efficient Multi Collection Style Transfer Using GAN

Proposed a new model that can make style transfer from single style image, and allow to transfer into multiple different styles in a single model.

Zhaozheng Shen 2 Jan 15, 2022
Automatic library of congress classification, using word embeddings from book titles and synopses.

Automatic Library of Congress Classification The Library of Congress Classification (LCC) is a comprehensive classification system that was first deve

Ahmad Pourihosseini 3 Oct 01, 2022
MRI reconstruction (e.g., QSM) using deep learning methods

deepMRI: Deep learning methods for MRI Authors: Yang Gao, Hongfu Sun This repo is devloped based on Pytorch (1.8 or later) and matlab (R2019a or later

Hongfu Sun 17 Dec 18, 2022
A deep learning network built with TensorFlow and Keras to classify gender and estimate age.

Convolutional Neural Network (CNN). This repository contains a source code of a deep learning network built with TensorFlow and Keras to classify gend

Pawel Dziemiach 1 Dec 18, 2021
Gym environment for FLIPIT: The Game of "Stealthy Takeover"

gym-flipit Gym environment for FLIPIT: The Game of "Stealthy Takeover" invented by Marten van Dijk, Ari Juels, Alina Oprea, and Ronald L. Rivest. Desi

Lisa Oakley 2 Dec 15, 2021
Diffusion Normalizing Flow (DiffFlow) Neurips2021

Diffusion Normalizing Flow (DiffFlow) Reproduce setup environment The repo heavily depends on jam, a personal toolbox developed by Qsh.zh. The API may

76 Jan 01, 2023
The world's largest toxicity dataset.

The Toxicity Dataset by Surge AI Saving the internet is fun. Combing through thousands of online comments to build a toxicity dataset isn't. That's wh

Surge AI 134 Dec 19, 2022
Compute descriptors for 3D point cloud registration using a multi scale sparse voxel architecture

MS-SVConv : 3D Point Cloud Registration with Multi-Scale Architecture and Self-supervised Fine-tuning Compute features for 3D point cloud registration

42 Jul 25, 2022
This is the code for our paper "Iconary: A Pictionary-Based Game for Testing Multimodal Communication with Drawings and Text"

Iconary This is the code for our paper "Iconary: A Pictionary-Based Game for Testing Multimodal Communication with Drawings and Text". It includes the

AI2 6 May 24, 2022
An elaborate and exhaustive paper list for Named Entity Recognition (NER)

Named-Entity-Recognition-NER-Papers by Pengfei Liu, Jinlan Fu and other contributors. An elaborate and exhaustive paper list for Named Entity Recognit

Pengfei Liu 388 Dec 18, 2022
Augmentation for Single-Image-Super-Resolution

SRAugmentation Augmentation for Single-Image-Super-Resolution Implimentation CutBlur Cutout CutMix Cutup CutMixup Blend RGBPermutation Identity OneOf

Yubo 6 Jun 27, 2022
Image Segmentation with U-Net Algorithm on Carvana Dataset using AWS Sagemaker

Image Segmentation with U-Net Algorithm on Carvana Dataset using AWS Sagemaker This is a full project of image segmentation using the model built with

Htin Aung Lu 1 Jan 04, 2022
The mini-MusicNet dataset

mini-MusicNet A music-domain dataset for multi-label classification Music transcription is sequence-to-sequence prediction problem: given an audio per

John Thickstun 4 Nov 09, 2022
Kernel Point Convolutions

Created by Hugues THOMAS Introduction Update 27/04/2020: New PyTorch implementation available. With SemanticKitti, and Windows supported. This reposit

Hugues THOMAS 584 Jan 07, 2023
Hyperparameter tuning for humans

KerasTuner KerasTuner is an easy-to-use, scalable hyperparameter optimization framework that solves the pain points of hyperparameter search. Easily c

Keras 2.6k Dec 27, 2022