实施感知器分类器 [英] implementing a perceptron classifier

查看:102
本文介绍了实施感知器分类器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python和NLP的新手.我需要实现一个感知器分类器.我搜索了一些网站,但找不到足够的信息.目前,我有一些文件按类别(体育,娱乐等)分类.我还列出了这些文档中最常用的单词以及它们的出现频率.在一个特定的网站上,有人说我必须具有某种接受参数x和w的决策函数. x显然是某种矢量(我不知道w是什么).但是我不知道如何使用建立感知器算法所需的信息以及如何使用它对我的文档进行分类.你有什么主意吗?谢谢:)

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 :)

推荐答案

感知器的外观

从外部来看,感知器是一种函数,它接受n个参数(即n维向量)并产生m个输出(即m维向量).

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).

在内部,一个感知器由 neurons 层组成,因此,一个层中的每个神经元都接收来自上一层的所有神经元的输入,并使用该输入来计算单个输出.第一层由n个神经元组成,它接收输入.最后一层由m个神经元组成,并在感知器完成对输入的处理之后保存输出.

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.

从神经元i到神经元j的每个连接都有一个 weight w(i,j)(我将在后面解释它们的来源).第二层神经元ptotal 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))

其中,k在第一层的所有神经元上运行.通过应用激活函数,根据神经元的总输入来计算神经元的激活.费米函数是经常使用的激活函数,所以

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))).

通过应用output function根据神经元的激活来计算神经元的输出.经常使用的输出函数是标识f(x) = x(确实有些作者将输出函数视为激活函数的一部分).我只是假设

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.

您需要解决的一些问题

  1. 文档的相关特征是什么?如何将它们编码为n维矢量?
  2. 应该选择哪个示例来调整权重?
  3. 应如何解释输出结果以对文档进行分类?示例:单个输出产生最可能的类别,而矢量则为每个类别分配概率.
  4. 需要多少个隐藏层,它们应该有多大?我建议从一个具有n神经元的隐藏层开始.
  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.

这篇关于实施感知器分类器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆