GithubHelp home page GithubHelp logo

silky / grenade Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huwcampbell/grenade

0.0 2.0 0.0 25 KB

Machine learning which might blow up in your face

License: BSD 2-Clause "Simplified" License

Shell 4.28% Haskell 95.72%

grenade's Introduction

Grenade

First shalt thou take out the Holy Pin, then shalt thou count to three, no more, no less.
Three shall be the number thou shalt count, and the number of the counting shall be three.
Four shalt thou not count, neither count thou two, excepting that thou then proceed to three.
Five is right out.

๐Ÿ’ฃ Machine learning which might blow up in your face ๐Ÿ’ฃ

Grenade is a dependently typed, practical, and pretty quick neural network library for concise and precise specifications of complex networks in Haskell.

As an example, a network which can achieve less than 1.5% error on mnist can be specified and initialised with random weights in under 10 lines of code with

randomMnistNet :: MonadRandom m => m (Network Identity '[('D2 28 28), ('D3 24 24 10), ('D3 12 12 10), ('D3 12 12 10), ('D3 8 8 16), ('D3 4 4 16), ('D1 256), ('D1 256), ('D1 80), ('D1 80), ('D1 10), ('D1 10)])
randomMnistNet = do
  a :: Convolution 1 10 5 5 1 1  <- randomConvolution
  let b :: Pooling 2 2 2 2        = Pooling
  c :: Convolution 10 16 5 5 1 1 <- randomConvolution
  let d :: Pooling 2 2 2 2        = Pooling
  e :: FullyConnected 256 80     <- randomFullyConnected
  f :: FullyConnected 80  10     <- randomFullyConnected
  return $ a :~> b :~> Relu :~> c :~> d :~> FlattenLayer :~> Relu :~> e :~> Logit :~> f :~> O Logit

The network can be thought of as a heterogeneous list of layers, and its type signature includes a type level list of the shapes of the data passed between the layers of the network.

In the above example, the input layer can be seen to be a two dimensional (D2) image with 28 by 28 pixels. The last item in the list is one dimensional (D1) with 10 values, representing the categories of the mnist data.

Layers in Grenade are represented as Haskell classes, so creating one's own is easy in downstream code. If the shapes of a network are not specified correctly and a layer can not sensibly perform the operation between two shapes, then it will result in a compile time error.

Thanks

Writing a library like this has been on my mind for a while now, but a big shout out must go to Justin Le, whose dependently typed fully connected network inspired me to get cracking, gave many ideas for the type level tools I needed, and was a great starting point for writing this library.

Performance

Grenade is backed by hmatrix and blas, and uses a pretty clever convolution trick popularised by Caffe, which is surprisingly effective and fast. So for many small scale problems it should be sufficient.

That said, it's currently stuck on a single core and doesn't hit up the GPU, so there's a fair bit of performance sitting there begging.

Training 15 generations over Kaggle's mnist training data took a few hours.

Contributing

Contributions are welcome.

grenade's People

Contributors

angerman avatar huwcampbell avatar

Watchers

 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.