0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【論文解説】Word2vecに関連する論文について(CBOW・Skip-gram・Negative Sampling)

Posted at

Word2vecに関連する論文はCBOWやSkip-gramについて取り扱ったEfficient Estimation of Word Representations in Vector SpaceとNegative Samplingについて取り扱ったDistributed Representations of Words and -Phrases and their Compositionalityの二つが有名です。当記事では以下、この二つの論文を中心にWord2vecに関連する論文について解説をまとめました。

前提・基本知識の確認

Word2vec以前の単語のベクトル化

NCE(Noise Contrastive Estimation)

階層的ソフトマックス(Hierarchical Softmax)

Word2vec

CBOWとSkip-gram(Log-linear Models)

Word2vecの学習にあたっては「単語は文脈によって規定される」という分布仮説(distributional hypothesis)に基づいて目的関数が設定されます。Word2vecの学習にあたってのタスクはCBOW(Continuous Bag-of-Words)とSkip-gramの二通りに大別されます。それぞれ下図を元に確認すると良いです。

Word2vec1.png
Efficient Estimation of Word Representations in Vector Space Figure.1

図より「文脈から単語を予測するのがCBOW」、「単語から文脈を予測するのがSkip-gram」であると読み取ると良いです。それぞれの計算の複雑さ(complexity)は下記のように計算できます。

\begin{align}
Q_{\mathrm{CBOW}} &= N \times D + D \times \log_{2}{V} \\
Q_{\mathrm{Skip-gram}} &= C \times ( D + D \times \log_{2}{V} )
\end{align}

従来研究(NNLM)からのCBOWやSkip-gramの学習時間やパフォーマンスの改善は下記の表を元に確認すると良いです。

Word2vec2.png
Efficient Estimation of Word Representations in Vector Space Table.6

Negative Sampling

Negative SamplingはWord2vecの学習の高速化にあたってボトルネックとなるSoftmax関数の計算を行わないように負例(Negative Sample)に基づいてlossを再構築した手法です。Negative Samplingのlossは雑音対照推定(NCE; Noise Contrastive Estimation)をベクトル表現(vector representation)のパフォーマンスが下がらないように単純化することで定義されたと理解すると良いです。

\begin{align}
\mathcal{L} &= \log{\sigma \left( v_{w_{O}}^{\mathrm{T}} v_{w_I} \right)} + \sum_{i=1}^{k} \mathbb{E}_{w_i \sim P_{n}(w)} \left[ \log{\sigma \left( -v_{w_{i}}^{\mathrm{T}} v_{w_I} \right)} \right] \\
\sigma(x) &= \frac{1}{1+\exp{(-x)}}
\end{align}

Negative Samplingは上記のような目的関数(Objective)を定義します。まず第1項によって入力の単語の$w_I$と出力の単語の$w_O$のベクトル表現の$v_{w_I}$と$v_{w_O}$が類似するように学習が行われると理解すると良いです。次に第2項については$P_n(w)$はノイズの分布であり、この分布に基づいてサンプリングされた$w_i$に基づく内積が小さくなるように学習が行われます。また、$k$は負例のサンプリングの数であり、基本的には5〜20(大きなデータセットの場合は2〜5)が有用であるとされます。

負例のサンプリングにあたっては単語の出現頻度に基づくユニグラム分布$U(w)$の3/4に基づいてサンプリングを行うと良いと記載されています。確率分布は正規化定数の$Z$を用いて下記のように立式されます。

\begin{align}
\frac{U(w)^{\frac{3}{4}}}{Z}
\end{align}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?