implementing a perceptron classifier

后端 未结 5 927
失恋的感觉
失恋的感觉 2021-02-03 12:37

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

5条回答
  •  别跟我提以往
    2021-02-03 13:02

    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.

提交回复
热议问题