The early work on representing words in a vector space is exploited in Information Retrieval as a side effect, where the feature vectors of words is learned based on the word-document co-occurrence(LSI). Then Y. Bengio et. al. proposed a neural network based model(NNLM, ) that learns the word vectors and the language model at the same time. Mikolov propose the CBOW and Skip-Gram model which simplifies the NNLM by removing the hidden layer, and accelerate the training by Hierarchical SoftMax or Negative Sampling. Finally J. Pennington propose the GloVe which combines the global matrix factorization methods(LSI) and local context window methods(Skip-Gram).
Latent Semantic Indexing
LSI first arise in the information retrieval literature to match documents for each query, it does a matrix factorization based on the word-document co-occurrence matrix:
where , and is a rectangular diagonal matrix.
If we only keep the largest value of the matrix, then we can get:
So each row of the is the word embedding vector for each word.
Neural Net Language Model(NNLM)
Y. Bengio et. al. propose a probabilistic feedforward neural network language model, which learns the language model as well as word embeddings at the same time. The network consists of input, hidden and output layers, as below:
The NNLM learns the language model as well as word embedding by go through the training data using a window of size , at each time the NNLM predict the last word in the window based on the first words. So the input is a -dimension vector, which is the concatenation of the word vectors of the first words. The hidden layer consists of hidden nodes, with sigmoid or tanh activation function. The output layer is a softmax layer with dimension , e.g., the number of unique words.
Skip-Gram & CBow
While the NNLM can learn meaningful word embeddings, it's computational complexity is quite high, e.g. for each training sample(window), the model must learn parameters. T. Mikolov propose two more efficient neural network architectures which can learn the word embedding much faster: CBoW and Skip-Gram.
The main difference between these two new methods and the NNLM is that, there is no hidden layer any more. The COBW model predict a word based on the context words(words around the target word), while the Skip-Gram predict the context words based on the current word, as below:
The GloVe looks very similar with the LSA, but is explicitly designed to model semantic and syntactic regularities. Instead of factorize the document-word co-occurrence, the GloVe models the logarithm of the co-occurrence of a word and its context words as:
where and is the word embeddings of a word and its context word, while and are the corresponding biases. The is their co-occurrence of word appears in the context of word .
So the loss function of the GloVe is:
where is a weighting function:
Why does it works?
J. Pennington et. at have done some interesting analysis of word embedding algorithms. They classify these algorithms to Global Matrix Factorization Methods such as LSA and Local Context Window Methods such as NNLM, CBOW and Skip-Gram, while at last they propose the GloVe algorithm which combines the advantage of both.
Global Matrix Factorization Methods utilize the global statistics information of the corpus. For example, the LSA does the matrix factorization on the document-word co-occurrence matrix to get the word vectors. However, LSA performs poor on the word analogy task.
Local Context Window Methods are trained on the local context windows instead of the statistics of the whole corpus and perform good on the word analogy task. However, P. Pennington proved that the Skip-Gram is just an on-line version of the GloVe.
The Skip-Gram models the probability that word appears in the context of word as
Skip-Gram is trained in an on-line, stochastic way, but the implied global objective function can be written as
The above equation can be evaluated much more efficiently if we group those terms that have the same values for and :
Since and , so can be rewritten as
We can find that the above equation is very similar with . While the Skip-Gram uses the cross entropy error while GloVe use the lease square error.
So why does the above word embedding methods can perform so good on the word analogy task? Is there any intuitive interpretation?
Absolutely yes, here we take Skip-Gram as example, since the other methods are very similar with it. Say that the word pear and orange is very similar. For two words to be similar, we mean that they often appears in the same context. For the pear-orange case, a very common context can be She eat some pear/orange, or I want a glass of pear/orange juice. Since they often share the same context, so in training, their word vectors should be very similar with each other so that they can predict their common context words well.
Another very interesting property of the word embedding is that the offset of the word vectors is also meaning full, for example, . An intuitive interpretation is that, we can think each word as a compose of concepts, e.g. . So
. Indexing by latent semantic analysis. S. Deerwester, S.T. Dumais, G.W. Furnas, T.K. Landauer, R. Harshman. JASIS. 1990.
. A Neural Probabilistic Language Model. Y. Bengio, R. Ducharme, P. Voncent, C. Jauvin. JMLR. 2003.
. Efficient Estimation of Word Representation in Vector Space. T. Mikolov, K. Chen, G. Corrado, J. Dean. arXiv:1301.3781v3
. Distributed Representations of Words and Phrases and their Compositionality. T. Mikolov, I. Sutskever, K. Chen, G. Corrado, J. Dean. arXiv:1310.4546v1.
. GloVe: Global Vectors for Word Representation. J. Pennington, R. Socher, C. D. Manning.