Word2Vec
Neural language models leverage neural networks trained on extensive text data, enabling them to discern patterns and connections between terms and documents. Through this training, neural language models gain the ability to comprehend and generate human-like language with remarkable fluency and coherence.
Word2Vec is a neural language model that maps words into a high-dimensional embedding space, positioning similar words closer to each other.
Continuous Bag-of-Words
Consider a sequence of words, {wk−2,wk−1,wk,wk+1,wk+2}. We can predict wi by leveraging its contextual words using a generative model similar to the n-gram models discussed previously (V: a vocabulary list comprising all unique words in the corpus):
This objective can also be achieved by using a discriminative model such as Continuous Bag-of-Words (CBOW) using a multilayer perceptron. Let x∈R1×n be an input vector, where n=∣V∣. x is created by the bag-of-words model on a set of context words, I={wk−2,wk−1,wk+1,wk+2}, such that only the dimensions of x representing words in I have a value of 1; otherwise, they are set to 0.
Let y∈R1×n be an output vector, where all dimensions have the value of 0 except for the one representing wk, which is set to 1.
Let h∈R1×d be a hidden layer between x and y and Wx∈Rn×d be the weight matrix between x and h, where the sigmoid function is used as the activation function:
Finally, let Wh∈Rn×d be the weight matrix between h and y:
Thus, each dimension in y represents the probability of the corresponding word being wk given the set of context words I.
Q13: What are the advantages of using discriminative models like CBOW for constructing language models compared to generative models like n-gram models?
Skip-gram
In CBOW, a word is predicted by considering its surrounding context. Another approach, known as Skip-gram, reverses the objective such that instead of predicting a word given its context, it predicts each of the context words in I given wk. Formally, the objective of a Skip-gram model is as follows:
Let x∈R1×n be an input vector, where only the dimension representing wk is set to 1; all the other dimensions have the value of 0 (thus, x in Skip-gram is the same as y in CBOW). Let y∈R1×n be an output vector, where only the dimension representing wj∈I is set to 1; all the other dimensions have the value of 0. All the other components, such as the hidden layer h∈R1×d and the weight matrices Wx∈Rn×d and Wh∈Rn×d, stay the same as the ones in CBOW.
Q14: What are the advantages of CBOW models compared to Skip-gram models, and vice versa?
Distributional Embeddings
What does each dimension in the hidden layer h represent for CBOW? It represents a feature obtained by aggregating specific aspects from each context word in I, deemed valuable for predicting the target word wi. Formally, each dimension hj is computed as the sigmoid activation of the weighted sum between the input vector x and the column vector such that:
Then, what does each row vector rxi=Wx[i,:] ∈R1×d represent? The j'th dimension in rxi denotes the weight of the j'th feature in h with respect to the i'th word in the vocabulary. In other words, it indicates the importance of the corresponding feature in representing the i'th word. Thus, ri can serve as an embedding for the i'th word in V.
What about the other weight matrix Wh? The j'th column vector chj=Wh[:,j] ∈Rn×1 denotes the weights of the j'th feature in h for all words in the vocabulary. Thus, the i'th dimension of chj indicates the importance of j'th feature for the i'th word being predicted as the target word wk.
On the other hand, the i'th row vector rhi=Wx[i,:] ∈R1×d denotes the weights of all features for the i'th word in the vocabulary, enabling it to be utilized as an embedding for wi∈V. However, in practice, only the row vectors of the first weight matrix Wx are employed as word embeddings because the weights in Wh are often optimized for the downstream task, in this case predicting wk, whereas the weights in Wx are optimized for finding representations that are generalizable across various tasks.
Q15: What are the implications of the weight matrices Wx and Wh in the Skip-gram model?
Q16: What limitations does the Word2Vec model have, and how can these limitations be addressed?
References
Efficient Estimation of Word Representations in Vector Space, Tomas Mikolov, Kai Chen, Greg Corrado, Jeffrey Dean, Proceedings of the International Conference on Learning Representations (ICLR), 2013.
GloVe: Global Vectors for Word Representation, Jeffrey Pennington, Richard Socher, Christopher Manning, Proceedings of the Conference on Empirical Methods in Natural Language Processing (EMNLP), 2014.
Bag of Tricks for Efficient Text Classification, Armand Joulin, Edouard Grave, Piotr Bojanowski, Tomas Mikolov, Proceedings of the Conference of the European Chapter of the Association for Computational Linguistics (EACL), 2017.
Last updated
Was this helpful?