word2vec: Efficient Estimation of Word Representations in Vector Space - Deepest-Project/Greedy-Survey GitHub Wiki
Resources
word2vec: Efficient Estimation of Word Representations in Vector Space arXiv
More dercription about representations in word2vec:
Distributed Representations of Words and Phrases and their Compositionality
link
์ ๋ฆฌํด ๋์ ๊ธ + ์์
shuuki4's wordpress
YouTube
Background
Softmax with very large label
Hierarchical Softmax
Softmax์์ V๊ฐ์ ๋ถ๋ฅ๋ฅผ ํ๋ค๊ณ ํ์ ๋, ์ ์ฒด ํฉ์ ๊ตฌํด ๋๋ ์ฃผ๋ ๊ณผ์ ์ด ๋งค์ฐ Costlyํจ(V๊ฐ ๋งค์ฐ ํด ๋).
Hierarchical Softmax์ ์ ์ฒด ํฉ์ ๊ตฌํด์ ๋๋๋ ๊ณผ์ ์์ด๋ ์ ์ฒด ํฉ์ด ์ฒ์๋ถํฐ 1์ด ๋๊ฒ ๋ง๋๋ ๋ฐฉ๋ฒ.
Softmax์ Computational Complexity๊ฐ V ์์ log2(V)๋ก ๊ฐ์ํ๋ค.
Negative Sampling
Softmax์์ Cross Entrophy๋ฅผ ๊ตฌํ ๋, 1์ด ๊ณฑํด์ง๋ "Positive Sample"์ ์ค์ํ์ง๋ง, 0์ด ๊ณฑํด์ง๋ "Negative Sample"์ ๊ทธ๋ค์ง ์ค์ํ์ง ์๋ค.
๊ทธ๋ฆฌํ์ฌ Neative Sample ๋ชจ๋์ ๋ํด ๊ณ์ฐ์ ํ์ง ์๊ณ , K๊ฐ์ Sample์ ์ ํํ์ฌ ์ฌ์ฉํ๋ค.
word2vec์์๋ ๊ธฐ์กด์ ๋ฐฉ๋ฒ๊ณผ๋ ์กฐ๊ธ ๋ค๋ฅธ Loss Function์ ์ ์ํ๋ค.
์๋ Loss Function์๋ ์๋์์ ๋งํ๋ $\mathbb{E}_{w_i \sim P_n(w)}[\sim]$๊ฐ ์์ด, ๊ทธ๋ฅ Sum์ ํ๋ค.
$\mathbb{E}_{w_i \sim P_n(w)}[\sim]$๋, Negative Sample์๋ ๊ฐ๊ฐ ๋ฑ์ฅ ๋น๋์ ๋ฐ๋ผ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํ์์ ์๋ฏธํ๋ค. ์๋ฅผ ๋ค์ด, ์ด๋ค ๋จ์ด ๊ทผ์ฒ์ "๋ง" ์ด๋ผ๋ ๋น๋์๊ฐ ๊ต์ฅํ ๋์ ๋จ์ด๊ฐ ๋ฑ์ฅํ์ง ์์๋ค๋ฉด, ์ด๋ ๊ฝค๋ ์๋ฏธ ์๋ ์ ๋ณด์ด๋ค. ๋ฐ๋ฉด์ ์ด๋ค ๋จ์ด ๊ทผ์ฒ์ "์งํ์ฆ" ์ด๋ผ๋ ๋น๋์๊ฐ ๊ต์ฅํ ๋ฎ์ ๋จ์ด๊ฐ ๋ฑ์ฅํ์ง ์์๋ค๋ฉด, ์ด๋ ์ ์์ ๋นํด ํฌ๊ฒ ์๋ฏธ์๋ ์ ๋ณด๊ฐ ์๋ ๊ฒ์ด๋ค. ๋ฐ๋ผ์, ์ ์ฒด ๋น๋์๋ฅผ ๊ฐ์ค์น๋ก ํ์ฌ Negative Sample์ ํฉ์ฐํ๋ค.
Introduction
Word Vector Representation
Cons of one-hot encoding:
- Use Too Many Memories.
- It can not represent the relationships between words.
Vector Representation vectorizes the words by their "meaning".
For example,
- vector("Seoul") - vector("Korea") + vector("Japan") = vector("Tokyo")
- average(vector("Man"), vector("Woman"), vector("Kid"), vector("Adult")) = vector("Person")
Previous Models on Word Vector Representation
- Feedforward Neural Net Language Model(NNLM)
- Recurrent Neural Net Language Model(RNNLM)
NNLM
In the image, the the dimension of projection layer is written in P but in the paper it is written in D so I'll use D for that dimension below.
V : Size of dictionary D : Dimension of word vector
- N previous words from target word are encoded using one-hot encoding(Input layer would be the matrix (N * V) ).
- Input layer projected to a projection layer P that has dimensionality (N * D) , and then this layer get to be flattened.
- By using the projection layer P as input, through hidden layer output layer (V, ) is computed.
- Softmax, Cross-Entrophy, Back-Prop!
- Each row vectors of projection layer are used as "word vector"
Computational Complexity
$Q = N \times D + N \times D \times H + H \times V $
$V$ can be reduced to $log_2(V)$, so bottleneck term is $N \times D \times H$
Cons
- Too slow Usually, N=10, D=500, H=500 -> $Q \approx 2.5M$
RNNLM
Computational Complexity
$Q = H \times H + H \times V $
Cons
- Still... slow bottleneck term is $H \times H$ so, $ Q \approx 250K$
word2vec Models
- Continuous Bag-of-Words Model(CBOW)
- Continuous Skip-gram Model
CBOW
๋๋ ๋กฏ๋ฐ๋ฆฌ์์์ ๊ฐ์ํ๊น์ ___ ์ ์ฐ์ด ๋จน์๋ค.
___ ์ ๋ค์ด์ฌ ๋จ์ด๋ฅผ ๋ง์ถ๊ธฐ!
Target Word์ ์๋ค ํฉ์ณ์ C๊ฐ์ ๋จ์ด๋ฅผ ํ์ธํ๋ค.
$W = \begin{bmatrix} \bm{v_{w_1}} \ \vdots \ \bm{v_{w_V}} \end{bmatrix}$
(V, N) shape
$W' = \begin{bmatrix} \bm{v'_ {w_1}} & \cdots & \bm{v'_ {w_V}} \end{bmatrix}$
(N, V) shape
์ฌ๊ธฐ์, W์ Row vector๋ค์ด word vector๋ก ์ฌ์ฉ๋๋ค.
Computational Complexity
$Q = C \times D + D \times log_2(V) $
C=10, D=500, V=1,000,000 -> $Q \approx 10K$
Skip-gram
CBOW๋ฅผ ๋ฐ๋๋ก ๋ค์ง์ ๋ชจ๋ธ.
Input: ์ผ์ฐน
์ฃผ๋ณ์ ๊ฐ์ํ๊น, ๋กฏ๋ฐ๋ฆฌ์, ์ฐ์ด ๊ฐ ๋ฑ์ฅํ๋๊ฐ?
$W = \begin{bmatrix} \bm{v_{w_1}} \ \vdots \ \bm{v_{w_V}} \end{bmatrix}$
(V, N) shape
$W' = \begin{bmatrix} \bm{v'_ {w_1}} & \cdots & \bm{v'_ {w_V}} \end{bmatrix}$
(N, V) shape
์ฌ๊ธฐ์, W์ Row vector๋ค์ด word vector๋ก ์ฌ์ฉ๋๋ค.
Computational Complexity
$Q = C \times (D + D \times log_2(V)) $
C=10, D=500, V=1,000,000 -> $Q \approx 100K$
CBOW ๋ชจ๋ธ๊ณผ Skip-gram ๋ชจ๋ธ์ ๋น๊ตํ๋ฉด CBOW์ ๋ชจ๋ธ์ด ์กฐ๊ธ ๋ ๋ ผ๋ฆฌ์ ์ด๋ผ๊ณ ๊ฐ์ธ์ ์ผ๋ก ์๊ฐํ์ง๋ง, ์ค์ ์คํ ๊ฒฐ๊ณผ์์๋ Skip-gram์ด CBOW์ ๋นํด ์ ์ฒด์ ์ผ๋ก ๋ค์ ์ข์ ๊ฒฐ๊ณผ๋ฅผ ๋ด๋ ์ถ์ธ๋ฅผ ๋ณด์ธ๋ค. ํ์ฌ๋ ๋๋ถ๋ถ์ ์ฌ๋๋ค์ด Skip-gram ๋ชจ๋ธ์ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ๋ค [3].
์ด๋ ๊ฒ ์์ฑ๋ Vector๋ค์, cosine similarity๋ฅผ ํตํด ์ฐ์ฐ๋๋ค. ์ฆ์จ, v = vector("Seoul") - vector("Korea") + vector("Japan")์ด๋ฉด,
vector space์์ v์ cosine distance๊ฐ ๊ฐ์ฅ ์์ vector(์๋ง๋ vector("Tokyo")๊ฐ ๋ ๊ฒ์ด๋ค.)๋ฅผ ์ฑํํ๋ค.
Training
Training Wordset: Semmantic, Syntactic ๋ ์นดํ ๊ณ ๋ฆฌ๋ก ๋๋ ์ ์งํ
Corpus: Google News(About 6B Words)
Trainingํ ๋ 100M Words, 3 Epochs ๋ณด๋ค 300M Words๋ฅผ 1 Epoch ์ด ๋ ์ข์ ์ฑ๋ฅ์ ๋ณด์์.
Performance
Examples of the Learned Relationships
- uranium: plutonium ๊ฐ์ ์ค๋ต์ ๋ณผ ์ ์๋ค.
- USA:pizza, ์ฆ USA๋ฅผ ๋ํํ๋ ์์์ด pizza๋ผ๋ ๋ป์ธ๋ฐ, ์ด์ฒ๋ผ word vector๋ฅผ ์ด์ฉํ๋ฉด ์ฝ๊ฒ ์๊ฐํ ์ ์๋ ์ฌ์ค์ ์ ์ถํ ์ ์๋ค.
Discussion
- Emoji์ vector representation์ ์ด๋ป๊ฒ ๋ํ๋ ๊ฒ์ธ๊ฐ?
- ์ฌ๋ฌ ๊ฐ์ง ์ธ์ด์ vector space ๊ฐ์ ๊ด๊ณ๋ฅผ ์ด๋ป๊ฒ ์ฐ๊ตฌํ ์ ์์๊น?