单词用向量表示,包含句法(即词性)和语义(即意义)结构。
CBOW模型continuous bag of words
在CBOW建模中,我们试图通过给定几个上下文单词(中心词周围的单词)来预测中心词。
例如,选择一个 C = 2 C=2 C=2的上下文,预测中间的单词happy,则上下文包含中心单词前面的两个单词和之后的两个单词:
C
C
C个单词前:【我,是】
C
C
C个单词后:【因为,我】
换句话说:
c o n t e x t = [ I , a m , b e c a u s e , I ] context=[I,am,because,I] context=[I,am,because,I] t a r g e t = h a p p y target=happy target=happy
模型结构如下:
softmax function:
softmax ( z i ) = e z i ∑ i = 0 V − 1 e z i (5) \text{softmax}(z_i) = \frac{e^{z_i} }{\sum_{i=0}^{V-1} e^{z_i} } \tag{5} softmax(zi)=∑i=0V−1eziezi(5)
Array indexing in code starts at 0.
V
V
V is the number of words in the vocabulary (which is also the number of rows of
z
z
z).
i
i
i goes from 0 to |V| - 1.
the Rectified Linear Unit (ReLU):
f ( h ) = max ( 0 , h ) (6) f(h)=\max (0,h) \tag{6} f(h)=max(0,h)(6)
x ˉ \bar x xˉ是上下文单词所有one-hot向量的平均。
一旦编码了所有上下文单词,就可以使用 x ˉ \bar x xˉ作为模型的输入。