Hi I\'m pretty new to Python and to NLP. I need to implement a perceptron classifier. I searched through some websites but didn\'t find enough information. For now I have a numb
From the outside, a perceptron is a function that takes n
arguments (i.e an n
-dimensional vector) and produces m
outputs (i.e. an m
-dimensional vector).
On the inside, a perceptron consists of layers of neurons, such that each neuron in a layer receives input from all neurons of the previous layer and uses that input to calculate a single output. The first layer consists of n
neurons and it receives the input. The last layer consist of m
neurons and holds the output after the perceptron has finished processing the input.
Each connection from a neuron i
to a neuron j
has a weight w(i,j)
(I'll explain later where they come from). The total input
of a neuron p
of the second layer is the sum of the weighted output of the neurons from the first layer. So
total_input(p) = Σ(output(k) * w(k,p))
where k
runs over all neurons of the first layer. The activation of a neuron is calculated from the total input of the neuron by applying an activation function. An often used activation function is the Fermi function, so
activation(p) = 1/(1-exp(-total_input(p))).
The output of a neuron is calculated from the activation of the neuron by applying an output function
. An often used output function is the identity f(x) = x
(and indeed some authors see the output function as part of the activation function). I will just assume that
output(p) = activation(p)
When the output off all neurons of the second layer is calculated, use that output to calculate the output of the third layer. Iterate until you reach the output layer.
At first the weights are chosen randomly. Then you select some examples (from which you know the desired output). Feed each example to the perceptron and calculate the error, i.e. how far off from the desired output is the actual output. Use that error to update the weights. One of the fastest algorithms for calculating the new weights is Resilient Propagation.
Some questions you need to address are
n
-dimansional vector?n
neurons.The first and second points are very critical to the quality of the classifier. The perceptron might classify the examples correctly but fail on new documents. You will probably have to experiment. To determine the quality of the classifier, choose two sets of examples; one for training, one for validation. Unfortunately I cannot give you more detailed hints to answering these questions due to lack of practical experience.