WORD2VEC 神经网络 模型细节。

英文ok的同学直接看http://mccormickml.com/2016/04/19/word2vec-tutorial-the-skip-gram-model/。

这篇文章专门讲细节,集中于讲清楚最简单的word2vec 神经网络模型,方便WORD2VEC理解。

直入主题:SKIP-GRAM模型,假设字典有10000个token(token,比如语料库里有“我”,“你”,"我",这个就有3个token,重复的也计算)。

每个token(也可以说是word),用one hot 表示,意思就是 【1,0,0,0.......0】代表“我”。【0,0,1,0,0】代表 “你”,以此类推。

ok,现在输入层是10000个Unit,shape是【10000】

hidden layer,设定为300个神经元(注意,这里word2vec没有做非线性转换),

现在输入层到hidden layer的参数的shape 是【10000,300】,取个名字叫Input vectors(取这个名字是为了表明重点就是这个,等下回来再讲)。

hidden layer到output层 是output vectors ,shape是【10000,300】

output层也是one hot ,shape是【10000】,使用softmax,每个Unit是某个token(word)的概率。

ok,整个框架图如下


WORD2VEC 神经网络 模型细节。_第1张图片

cost、梯度就不讲了,太多文章说过了,提一下霍夫曼编码,特别注意,不是必须的,只是为了减少计算量,对于word2vec来说,不是必选项,读代码时,这段特浪费时间,直接去掉不影响理解WORD2VEC。

接下来是重点来了,

input vectors 是一个矩阵,shape是【10000,300】,


WORD2VEC 神经网络 模型细节。_第2张图片

作用如下:


WORD2VEC 神经网络 模型细节。_第3张图片

就是查表了(lookup table),因此最后有作用的就是计算出input vectors ,It turns out ,input vectors 就是embedding vectors。

ok,跑一下模型,计算完毕之后,output vectors 扔掉,目前看起来没啥作用(以后说不定有大神专门去研究,那就不知道),

done.


Reference:

A Neural Probabilistic Language Model by Joshua Bengio

Distributed Representations of Words and Phrases and their Compositionally by Tomas Mikolov

Efficient Estimation of Word Representations in Vector Space  by Tomas Mikolov

http://mccormickml.com/2016/04/19/word2vec-tutorial-the-skip-gram-model/

你可能感兴趣的:(WORD2VEC 神经网络 模型细节。)