Giter Site home page Giter Site logo

starchild's Introduction

StarChild

StarChild is a library for leveraging the interactive theorem proving and SMT checking abilities of F* to verify properties of neural networks. It currently supports feedforward neural networks using ReLU, sigmoid, and softmax activation functions. Networks are written as follows:

val layer1 : layer 2 1
let layer1 = { weights    = [[228300.0R /. 13.0R]; [228300.0R /. 13.0R]]
             ; biases     = [~.337910.0R /. 13.0R]
             ; activation = Sigmoid
             }

val model : network 2 1 1
let model = NLast layer1

Properties of the model can then be checked using F* assertions. Let’s check if the model correctly implements the AND gate:

let _ = assert (run_network model [1.0R; 1.0R] == [1.0R])
let _ = assert (run_network model [0.0R; 1.0R] == [0.0R])
let _ = assert (run_network model [1.0R; 0.0R] == [0.0R])
let _ = assert (run_network model [0.0R; 0.0R] == [0.0R])

Yes! It correctly implements the AND gate! However, is it robust? What do we mean by robust? That’s generally not an easy question. For this AND gate, let’s take robustness to mean that if the input is within some epsilon of a 0.0 or 1.0, the gate still works:

let epsilon  = 0.24R
let truthy x = dist x 1.0R <=. epsilon
let falsy  x = dist x 0.0R <=. epsilon

let _ = assert (forall x1 x2. truthy x1 && truthy x2 ==> run_network model [x1; x2] == [1.0R])
let _ = assert (forall x1 x2. falsy  x1 && truthy x2 ==> run_network model [x1; x2] == [0.0R])
let _ = assert (forall x1 x2. truthy x1 && falsy  x2 ==> run_network model [x1; x2] == [0.0R])
let _ = assert (forall x1 x2. falsy  x1 && falsy  x2 ==> run_network model [x1; x2] == [0.0R])

The network we defined is robust around truthy and falsy inputs!

StarChild ships with a script which can help you convert a subset of Keras models to F* files. It’s called convert.py, and you invoke it like this:

python convert.py \
  -i models/Fashion_MNIST_PCA_100_ReLU_64_Softmax_10.h5 \
  -o models/Fashion_MNIST_PCA_100_ReLU_64_Softmax_10.fst

Make sure to install the requirements first!1

StarChild also comes with two example models, trained on the Fashion MNIST dataset, using the train_*.py scripts. Currently, F* chokes up when type checking the larger of the models.


You may also be interested in StarChild’s friend, Lazuli!

1: Run pip install -r requirements.txt.

starchild's People

Contributors

dependabot[bot] avatar katyakom avatar leina0 avatar wenkokke avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

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.