Git Product home page Git Product logo

pauljblazek / deepdistilling Goto Github PK

View Code? Open in Web Editor NEW
71.0 4.0 6.0 1.38 MB

Mechanistically interpretable neurosymbolic AI (Nature Comput Sci 2024): losslessly compressing NNs to computer code and discovering new algorithms which generalize out-of-distribution and outperform human-designed algorithms

Home Page: https://rdcu.be/dy2Go

License: Other

Python 99.46% Jupyter Notebook 0.54%
explainable-ai program-synthesis mechanistic-interpretability inductive-logic-programming model-distillation distilling neurosymbolic domain-adaptation out-of-distribution-generalization interpretable

deepdistilling's Introduction

Deep distilling

This repository includes code to produce results in the paper "Automated discovery of algorithms from data", which can be read at https://rdcu.be/dy2Go. The preprint is at https://arxiv.org/abs/2111.08275.

This paper seeks to fully demonstrate the mechanistic interpretability of ENNs and show that it can be used for discovery of novel algorithms. We have developed deep distilling to automatically condense the weights in an ENN into functioning computer code. This mechanistic interpretability allows for more readily discernible explainability, both by condensing a large number of parameters into a small number of lines of code, as well as by interpreting many aspects of the weights into such forms as for-loops, distilled variables, and logical functions.

Our original work on essence neural networks (ENNs) can be accessed at https://www.nature.com/articles/s43588-021-00132-w or with this shareable PDF link: https://rdcu.be/cyfGB.

Getting Started

Each of the two learning tasks shown here have a corresponding "distill_.py" file that sets hyperparameters, imports the ENN weights from corresponding .csv files, condense the ENN to code, and then tests that new code on several test sets. They also have a corresponding "output_.py" file where the distilled code is written.

Prerequisites

This code was implemented in Python 3.11.5

Results

Run the cell in the examples.ipynb notebook. Code is distilled on the shape orientation and MAXSAT problems. Then it is tested against various test sets as described in the paper.

Files

Results files

  • examples.ipynb : notebook where code can be called to run the ENN condenser for the MAXSAT and orientation problems

  • output_*.py : files to which deep distilling writes its output code for the given problem

Deep distilling files (in /src/)

  • distill.py : general code used to call the necessary functions to condense an ENN and then test it; calls into load_dd.py

  • load_dd.py : general code used to organize the ENN condensing algorithm, calling the below functions as needed

  • cluster.py : file containing the Cluster class, which is used to store groups of neurons and their connectivity patterns

  • clustering.py : file containing the algorithm for grouping neurons based on related connectivity patterns. It proceeds by a long series of checks against various types of patterns and then determines for a group what kind of for-loop is best suited for iterating over it.

  • forloop.py : file containing the algorithm for producing the code strings. It does this by writing appropriate for-loops and then within them translating the connectivity patterns found in Clusters into Python-style code

  • neuron.py : file containing the Neuron class, which contains the weights and connectivity pattern of a neuron

  • utils.py : contains some ancillary functions needed, such as rescaling weights and organizing indices of incoming neurons, as well as many short functions used in discovering for-loops and groups

Problem-specific files (in /src/)

  • distill_*.py : file to run distilling for the given problem

  • general_maxsat.py : file containing pre-distilled code that generalizes the maxsat problem to any size (i.e., any number of clauses and variables)

  • maxsat.py : file containing the code necessary to generate test data for maxsat and test it against the distilled code

Data files (in /data/)

Within the data/orientation and data/sat folders, ENN weights and biases are stored in the ENN subfolders, and training and test sets are stored in the train and test subfolders.

deepdistilling's People

Contributors

paul-blazek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

deepdistilling's Issues

Getting examples.ipynb to run

The attached environment.yml file provides the version-aligned dependencies with the version alignment solver:
$ mamba env create -f environment.yml
$ mamba activate deepdistilling

Modifications to the dependencies can be version aligned without specifying version numbers with the solver:
$ mamba env update --file environment.yml --prune

I also had to modify the following program:

$ diff --git a/src/distill_maxsat.py b/src/distill_maxsat.py
index a9197c5..6b906ed 100644
--- a/src/distill_maxsat.py
+++ b/src/distill_maxsat.py
@@ -27,7 +27,8 @@ def main() -> None:
     print()
 
     print("\nTesting generalized distilled code (pre-condensed) on random Boolean formulae")
-    from src.general_maxsat import ENN_maxsat
+#    from src.general_maxsat import ENN_maxsat
+    from general_maxsat import ENN_maxsat
 
     def add_input_size(func, input_dims):
         def wrapper(x):

environment.yml.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.