This project was inspired by a blog series on type-safe neural networks by Justin Le. HaskellNet is a library that produces type-safe artificial neural networks in Haskell.
Machine learning code is notoriously hard to test and debug. There is no simple way to check for correctness and it is common for bugs to occur from incorrect matrix multiplications. This project experiments with the use of dependant types to ensure that the matrix multiplications are valid, helping catch a significant cause of bugs when building neural networks.
See a demo of the library here.
For more information about the project please read the report.
This README will briefly explain the repository structure and detail which code was written from scratch, adapted and what is third party code. Any files not mentioned here should not be important.
This folder contains all of the code used to produce the front-end. All the code here was written from scratch, parts of the canvas.js code borrowed from stack overflow. Most of the files can be ignored. The import to note are:
- This file contains the application logic. It is the only file that uses Elm.
- Main.elm compiles to main.js in the route directory so do not try to read that.
- This file contains the logic for drawing a number in the box. It will send data through a port to Main.elm.
- The styling for the front-end.
- Entry point for the front-end. Collates all the above files into an html document.
Contains datasets used to train and test the network code. Is not of import for viewing. Also contains some pretrained networks.
Some code to generate and read from datasets to train and test the network. Not too important to look at.
This contains the code for the neural network library. Much of it is written from scratch. The Networks.hs file used Justin Le's blog as a foundation, the serialization code is exactly as appears in the post, I believe everything else has been adapted. Connections.hs was also adapted from the blog. The rest of the files were written from scratch.
- Contains the Activations type class and a couple of pre-defined activation functions.
- Includes the connections data type and relevant functions.
- Has the Init type class and a couple of pre-defined init functions.
- Contains the main body of code in the library.
- Includes the Network data type and all the functions for using the networks.
- Has the optimser type class and a couple of pre-defined optimiser functions.
- Includes the data type used to provide the learning parameters needed for training a network.
- Contains a couple of example functions for training networks.
Includes a file that contains functions that provide some extra functions to those in HMatrix's static library.
This contains the file Api.hs which includes the server code. Provides an end point which takes in JSON and converts it to a vector to run through a pretrained network. Returns the predictions to the client. Written from scratch.