英文ok的同學(xué)直接看http://mccormickml.com/2016/04/19/word2vec-tutorial-the-skip-gram-model/。
這篇文章專門講細(xì)節(jié),集中于講清楚最簡單的word2vec 神經(jīng)網(wǎng)絡(luò)模型,方便WORD2VEC理解。
直入主題:SKIP-GRAM模型,假設(shè)字典有10000個token(token,比如語料庫里有“我”,“你”,"我",這個就有3個token,重復(fù)的也計算)。
每個token(也可以說是word),用one hot 表示,意思就是 【1,0,0,0.......0】代表“我”?!?,0,1,0,0】代表 “你”,以此類推。
ok,現(xiàn)在輸入層是10000個Unit,shape是【10000】
hidden layer,設(shè)定為300個神經(jīng)元(注意,這里word2vec沒有做非線性轉(zhuǎn)換),
現(xiàn)在輸入層到hidden layer的參數(shù)的shape 是【10000,300】,取個名字叫Input vectors(取這個名字是為了表明重點就是這個,等下回來再講)。
hidden layer到output層 是output vectors ,shape是【10000,300】
output層也是one hot ,shape是【10000】,使用softmax,每個Unit是某個token(word)的概率。
ok,整個框架圖如下

。
cost、梯度就不講了,太多文章說過了,提一下霍夫曼編碼,特別注意,不是必須的,只是為了減少計算量,對于word2vec來說,不是必選項,讀代碼時,這段特浪費時間,直接去掉不影響理解WORD2VEC。
接下來是重點來了,
input vectors 是一個矩陣,shape是【10000,300】,

作用如下:

就是查表了(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/