Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implementing a perceptron classifier

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 number of documents which I grouped according to category(sports, entertainment etc). I also have a list of the most used words in these documents along with their frequencies. On a particular website there was stated that I must have some sort of a decision function accepting arguments x and w. x apparently is some sort of vector ( i dont know what w is). But I dont know how to use the information I have to build the perceptron algorithm and how to use it to classify my documents. Have you got any ideas? Thanks :)

like image 699
rbc089 Avatar asked Jan 11 '11 22:01

rbc089


People also ask

How do you implement perceptron?

First, we will look at the Unit Step Function and see how the Perceptron Algorithm classifies and then have a look at the perceptron update rule. Finally, we will plot the decision boundary for our data. We will use the data with only two features, and there will be two classes since Perceptron is a binary classifier.

What is a perceptron classifier?

The Perceptron Classifier is a linear algorithm that can be applied to binary classification tasks. How to fit, evaluate, and make predictions with the Perceptron model with Scikit-Learn. How to tune the hyperparameters of the Perceptron algorithm on a given dataset.


1 Answers

How a perceptron looks like

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.

How the output is calculated from 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.

Where the weights come from

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.

How to construct a Perceptron

Some questions you need to address are

  1. What are the relevant characteristics of the documents and how can they be encoded into an n-dimansional vector?
  2. Which examples should be chosen to adjust the weights?
  3. How shall the output be interpreted to classify a document? Example: A single output that yields the most likely class versus a vector that assigns probabilities to each class.
  4. How many hidden layers are needed and how large should they be? I recommend starting with one hidden layer with 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.

like image 145
Oswald Avatar answered Oct 18 '22 00:10

Oswald