Web Information Paper Review (4)

Yoshua Bengio, et al.:A Neural Probabilistic Language Model

Link: word2vec 中的数学原理详解(三)背景知识

In this paper, the author introduce how to use deep learning neural network to predict the word in sentence and compare it with the traditional n-gram method. The goal of nlp is to learn the probabilistic model to describe how words and sentences are generated. We want to know that in a document, what word will come next after a specific sequence of words. This can help computer better understand the human language.

The traditional method is called n-gram, which model the human language under the naive bayes assumption. The probability of a specific T sequence words are model as the product of consecutive bayes conditional probability. The probability is approximate to the frequency of the sequence of word in a corpora. However, this need a huge amount of count. If the T is very large, the count procedure will cost a lost. So a modified n-gram is proposed to reduce this. When consider bayes conditional probability, we only consider (n-1) word before the word we going to predict. Usually, n is chosen to 3. The drawbacks of this n-gram method are: (1) it don’t consider context farther than 3. (2) it don’t consider the potential relationship under the words. In nature language, context words can up to 10 or more. Also, latent semantic is very prevail among words. When counting word sequence in the corpora, we cannot ignore similar sentence but different words. The traditional way is use word vector to represent each word. But this is not effective and when corpora is very large, might introduce the curse of dimensionality, which means the vector to represent each word has too big dimension and not computable. In this paper, this two issues are solved by using distributed word feature vector and the neural network.

The distributed word feature vector provide a vector space to contain all the words in the corpora. It has m features (elements) which is specific by user and depended on the size of the corpora. Usually, the m is 60, which means each word can be described by using 60 parameters. And between similar meaning words, the vector degree is small. So when consider n words sentence, we concreate the each words vector together to form a n*m sentence vector. For similar sentences, the sentences’ vectors should have small degree. This is how we map the nature word to the input data of the neural network.

The basic idea of machine learning or the neural network is: first model the problem we want to solve. The model is control by a set of parameters. Then find the loss function or the likelihood function which describe how far is the prediction from the distribution's expectation. Then driven this evaluation function with the training data and the corresponding labels. So now the problem turn out to be to find the parameter make the evaluation function have the max/min value. Finally, use gradient descent or ascent to find a set of parameter satisfied this as the model parameters. Then we can use this model to predict in our problem.

In this paper, they use neural network to model this problem. They use a five layer recurrent neural network. The first layer is the input layer which do nothing just input (n-1) nature language words into the net. This also use the modified bayes model. The second layer is a hidden layer and also called word feature layer in the paper. This layer convert each input nature word to the m-feature vector space. Each words is map to a m-dimension vector C. Notice, this C is not pre-defined. It is also considered as a set of parameter in the net. We need to train the model to get C for each word. The next is a hidden layer, which map the concatenation of the (n-1)’s vector C to a row vector x and then use (d+Hx) to model this sentence vector. D is the layer bias which has the dimension of the neural number h in this layer. H is the weight of this hidden layer. The next layer is the output layer. This layer basic apply hyperbolic tangent to the output of the last layer and weighted with U, which is a |V|*h weight matrix. Also have a output bias of b which is |V| dimension. And a direct connection weight W which I will discuss at last. So the output of the output layer is a non-normalized probabilistic vector in respect to the |V| words in the corpora. The output function is: y = b + Wx + U tanh(d + Hx). Before we pick the final prediction, we need to normalized the probabilistic with the softmax function at the softmax layer and pick the largest p as our prediction. This is how to predict with neural network and also called forward phase.

After we define our model, we need to tranning the label data to get all of our parameters. We have PARAM=|V|(1+nm+h)+h(1+(n-1)m) free parameter need to specific. Now, let’s define the likelihood function to describe how confident we are about our prediction: L = 1/T∑log f(w_t, w_t-1...w_t-n ; theta) + R(theta). The method to find the theta make the L get max value is by using gradient ascent. However, at here, if we directly use gradient ascent, this will turn out to be a PARAM dimension problem which is hard to solve when PARAM is large. So we divide the model into layers and each time only train the parameters within a layer. This is how neural nets reduce the computation of traditional machine learning problems. BTW, R(theta) is the weight decay penalty which restrict the gradient ascent searching area after every epoch and don’t make it go too far and cannot converge.

To train this kind of net, we still have a very large computation. So the author come out with the parameter-parallel processing to train and predict the model. Suppose we have M CPU and |V| words in the corpora. So the output will be a |V| dimensional vector. We instead of divide the input data into subsets, they divide the output into subsets and every CPU take charge of |V|/M output units. The forward phase is basicly like what I describe above but each CPU calculate |V|/M outputs and merge together then softmax. What is most interesting is how they train the model with the parameter parallel processing.

The training process is also called Backward/Update phase. They train the model from the back layer to the front layer and each time only train parameters within one layer. The learning rate (step) is e. First, the train the output layer. The parameters in the output layers are (b, W, U) and I still ignore the direct connection weight W. So the (b, U) can be represented by using a. Then for each CPU, use gradient ascent to find the a which can make the L has the maximum value. For b, since it is a constant bias, we compute partial derivative of the L to y_i to update b and start from the initial b. Y_i represent the input variable to the L in this layer. Eventually, we can get a b make L largest. The do the similar gradient ascent to U, but multiply with a. After all M CPU computation is done, we get M set of  a=(b, U) as every parameter’s best solution. This layer parameter training has finished. The only information will pass to the next training layer, hidden layer with (d, H), is the partial derivative of L to a. In this hidden layer, we have h neurals so we use the back-propagation to get the partial derivative of L to o. O is (d+Hx) represent the input variables in this layer to the L function. Then still use gradient ascent to get d and H for each neural. Also update the partial derivative of L to x and pass to the next layer’s training. Then in the word feature layer, use gradient ascent to get C for each input word. Then we get distributed representation vector of (n-1) input word. We should training the whole corpora to get the C for each word. And when prediction, we can use them as the word feature layer’s parameter. Also, they use a method to avoid the exp in softmax is too much to compute.

The W is called direct connection weight, which means ignore the hidden layer and directly map the input C to the output layer and then use softmax to normalize. This might reduce the iteration converge times but not improve the model’s performance.

From this paper, I learn how the neural net are used in nlp problems and have a better understanding of the neural nets. I am very interested in this topic and will study further inside.


Tomas Mikolov, et al.:Distributed Representations of Words and Phrases and their Compositionality

Link: 深度学习word2vec笔记之算法篇文本深度表示模型Word2VecVector Representations of Words - TensorFlow

In this paper, the author introduces new model to analysis the nature language called word2vec. The word2vec has two model: CBOW and the Skip-gram model. CBOW is aim at predicting the next word based on the context. The Skip-gram model is aim at predicting a word around the target word. They are all based on the Huffman tree which can reduce the overall computation a lot. The paper also introduce the technique called subsampling and negative sampling which can reduce computation and the phrase based model.

The Skip-gram can be understanded as a 3 layer neural net. The input layer is just word. The hidden layer is map the word to the word vector. The output layer is basically a Huffman tree. All the words in the corpora are at the leaf and the node is only a word vector which can be understanded as a classifier of the word. Each word confront a node will be put into either left or the right path. This can roughly distinguish the word. And after pass through all the level in the Huffman tree, finally arrive at the specific word as final predict. The Skip-gram doesn’t consider the sequence of the word in a sentence, only consider the distance toward the target word. First, the author get the likelihood function. When training the parameters, the goal is to maximum the likelihood function. The likelihood function consider the word within c radius. Then the traditional method is model the p(W_0|W_i) by using the softmax and compute the degree between the two word vector. However, this is found not practical when corpora is large, so the author introduce the method below.

The first method is using the Hierarchical softmax. This make the output layer look like a tree instead of a vector with |V| elements. The tree is obtained during the training process and the most frequently use words are put at the leftmost leaf. You can also put at right most leaf, here word2vec use leftmost. So then the p(W_0|W_i) can be understand as the possibility of from the root to the word W_0. At each node, the input W_i can compute the degree between the W_i and the node vector. If the path from the root to the W_0 require the walk to goto the right child node, then the possibility is set negative. Because that the most frequently used words are located leftmost. This is kind of penalty on the possibility. The degrees are map by the sigmoid function. By using this way, the computation amount is only proportional to the log(|V|). This reduce the computation a lot.

Another way to reduce it is using the so-called negative sampling. This use the technique called Noise contrastive Estimation. This method assume that a good model should be able to differentiate data from noise by the mean of the logistic regression. So other than the computation of teh degree between W_0 and W_i, this also randomly generate k noise word vectors which is not belong to this corpora. The degree between the noise vector and the target word should be very large, so that the sigmoid function can map this penalty to almost 0. By using this method, each prediction’s computation only consume (k+1).

Also the paper talk about the subsampling which can drop some frequent use but less meaningful word such as “a” and “the”. In the the subsampling, every word has a chance to be dropped and it is related to the frequence of the word. Finally the author talk about the phrase model. They think phrase model sometimes is more reliable than the word model. Since some phrase combination might be rare to see but the phrase itself is frequently used. They evaluated two words’ possibility of form a phrase using the basic count method. Here they only consider the bigram case.

One of the most interesting thing in the paper is the word vector calculation. They find that two set of word with same kind of relationship can be mapped to another by using a similar transfer function. Such that “Madrid”-”Spain”+”France”~”Paris”. This indicate that the distance between same relationship set of word might be same. This reveal an interesting way of studying nlp.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,117评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,963评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,897评论 0 240
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,805评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,208评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,535评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,797评论 2 311
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,493评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,215评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,477评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,988评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,325评论 2 252
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,971评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,807评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,544评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,455评论 2 266

推荐阅读更多精彩内容

  • 「传授工作」之后,就要让他做做看,那就是「试做」了。「试做」共分为四个主要的步骤: 一、让他试做,一一改正错误 示...
    周明达老师阅读 1,004评论 0 10
  • 童年,家,那个孩子! 人无完人,谁没有点阴暗面,谁不曾因年少无知而自私妄为地伤害过他人,或多或少!但是我想我确实是...
    安古阅读 213评论 0 0
  • 烦躁不安的时候,总想睡很长很长的觉,可以回避很多不想面对的事。 无聊低沉的时候,总会打很久很久的游戏,把负能量全部...
    虫鸣一夏阅读 77评论 0 0
  • 夜华拱手施了一礼:“有两位上神在此帮衬凤九,我和浅浅也放心了些。” 折颜和白真对视了一眼,神色皆凝重。 夜华心里一...
    狐狸木木阅读 4,763评论 0 14