Classification of samples based on neural network.
neural-classifier is a neural network library based on the first chapters
from this book. It is divided on
neural-classifier which is a general API for neural networks
neural-classifier/mnist which contains helper functions for working with
MNIST/EMNIST datasets. For API documentation visit
How to work with MNIST dataset?
- Unpack files in
(neural-classifier-mnist:load-mnist-database)(this will take about 10-15 seconds).
- Create a neural network:
(defparameter *nn* neural-classifier-mnist:make-mnist-classifier 35)where
35is a number of hidden neurons.
(neural-classifier-mnist:train-epochs *nn* 10)to train the network for 10 epochs. This function will return data about the network's accuracy for each epoch.
- To test your own digits convert them to
784x1matrix of type
magicl:matrix/single-floatand pass it to
- Also you can play with some other hyper-parameters, not only the number of
neural-classifier:*learn-rate*is how fast gradient descent algorithm works (i.e. how fast your network learns),
neural-classifier:*decay-rate*is related to regularization and should be about
Nis a number of training samples. Zero means no regularization.
How to build custom nets and data?
See GH pages for this project (link above). In general you need to write
functions which translate your data and labels into
matrices. Then you create a net with
snakes generator which returns conses in the form
(DATA . LABEL). To train a network for one epoch you call
magiclfor matrix operations.
nibblesfor loading MNIST data.
nibbles can be downloaded with
What if the network shows good accuracy but fails to recognize my own digits?
If the accuracy returned by
train-epochs is good, but the network fails to
recognize digits draws by your own hand, try EMNIST database instead of
MNIST. Copy four
emnist-digits-* files to your MNIST directory preserving
the name of destination files. Images in EMNIST set are transposed (x and y
coordinates swapped), so do the same with your own images.