Learning Word Embeddings: Word2vec & GloVe
Learning Word Embeddings
[Bengio et. al., 2003, A neural probabilistic language model]에서는 4개의 단어를 word embedding 한 것을 사용하여 다음 단어를 예측하는 language model을 만들었다.
이를 통해 word embedding matrix를 구하였다.
Context를 다양한 방법으로 얻을 수 있다. (4개 단어로 다음 단어, 예측하려는 단어 앞 뒤 4 단어를 사용해서 등등)
Word2Vec
Skip-grams: 한 문장이 있다고 했을 때, 한 단어를 예측할 때 아무 위치에 있는 단어를 사용한다.
이를 통해 word embedding matrix를 구한다.
skip-gram의 문제로는 마지막 단어가 나올 probability를 계산할 때 softmax의 computation이 너무 크다는 것인데 hierarchical softmax로 computation을 줄일 수 있다
context를 결정하는 단어 c를 sampling을 어떻게 할 것인가는 uniform하게 확률을 적용시킬 수 있겠지만 'the', 'a'와 같은 단어들은 선택하지 않는 것이 좋기 때문에 단어에 따른 heuristic한 probability를 사용하는 것이 좋을 것이다.
Negative Sampling
한 context word에 대해서 다른 한 단어만 target으로 잡고 그 외의 k개의 단어들은 target이 아닌 것으로(negative) training set을 잡는다.
그리고 \( P(y = 1 | c, t) \)를 구하는 model(binary classification model)을 \( \sigma(\theta_t^T e_c) \)로 구해준다.
아까보다는 computation이 적은 binary classification으로 문제를 바꾸어 word embedding matrix을 얻을 수 있다.
negative example을 선택하는 방법으로 w_i를 뽑는 확률을 uniform하게 적용시킬수도 있겠지만 단어가 나오는 빈도수에 따라 \( P(w_i) = \frac{ f(w_i)^{\frac{3}{4}}}{\sum_{j = 1}^{10000} f(w_j)^{\frac{3}{4}}} \) 으로 정해서 구할 수도 있다.
GloVe Word Vectors
\( X_{ij} \) = # times \( j \) appears in context of \( i \) ( \( X_{ij} = X_{ji} \) )
\( \text{minimize} \sum_{i = 1}^{10000} \sum_{j = 1}^{10000} f(X_{ij}) ( \theta_i^Te_j + b_i + b'_j - log X_{ij} )^2 \)
\( f(X_{ij}) = 0 \) if \( X_{ij} = 0 \)
\( \theta_i \), \( e_j \) are symmetric => \( e_w^{(\text{final})} = \frac{ e_w + \theta_w }{2} \)
너무 생략된 것들이 많은 것 같다.
'Google Machine Learning Bootcamp 2022 > Sequence Models' 카테고리의 다른 글
3. Sequence Models & Attention Mechanism #2 (0) | 2022.08.15 |
---|---|
3. Sequence Models & Attention Mechanism #1 (0) | 2022.08.15 |
2. Natural Language Processing & Word Embeddings #3 (0) | 2022.08.12 |
2. Natural Language Processing & Word Embeddings #1 (0) | 2022.08.12 |
1. Recurrent Neural Networks (0) | 2022.08.11 |
댓글