Introduction of neural-redis, part 1
The machine learning module for redis
Objective
Assuming you already know about Neural Network.
The neural-redis module provides an easy way to simulate a Multi-layer Neural Network that can do regression and classification, and it is designed to be native supported by redis server.
Create a neural network
If we are going to implement a neural network model that has 2 inputs, 1 hidden layer with 3 units, and 1 output as below:
Here are the steps:
- Clone unstable branch of redis-server and build it.
- Clone and build neural-redis, then load it via redis-server.
- Connect the server via redis-cli, and create the neural network (named as
net
) via the following command:
> NR.CREATE net REGRESSOR 2 3 -> 1 NORMALIZE DATASET 50 TEST 10
(integer) 13
REGRESSOR
means that given certain inputs and desired outputs.
NORMALIZE
means that it is up to Redis to normalize the data it receives, so there is no need to provide data in the -/+ 1 range.
DATASET 50
andTEST 10
means that we want an internal memory for the dataset of 50 and 10 items respectively for the training dataset, and the testing dataset.For more API reference including
NR.CREATE
you can refer to:
https://github.com/antirez/neural-redis#api-reference
The output 13
means the number of tunable parameters in the neural network.
Why 13?
In the neural network, we have input X, output Y, and hidden H:
Now for easily explanation, considering activation function:
And linear combination:
Which includes the weight A between input layer and hidden layer, weight B between hidden layer and output layer, and the bias/threshold Δ for the outputs:
The total number of these parameters is 13.
neural-redis is using RPROP algorithm by default.
For more information about the implementation, you can refer to: https://github.com/antirez/neural-redis/blob/master/nn.c
What is next?
Part 2 will show you how to train the neural network.
Reference
https://en.wikipedia.org/wiki/Artificial_neural_network
https://github.com/antirez/neural-redis/blob/master/README.md
https://en.wikibooks.org/wiki/Artificial_Neural_Networks/Activation_Functions
https://en.wikipedia.org/wiki/Artificial_neuron
https://en.wikipedia.org/wiki/Rprop