第15章自然言語処理:事前学習
15.2.1. Negative Sampling15.2.1 負例サンプリング
Negative sampling modifies the original objective function. Given the context window of a center word , the fact that any (context) word comes from this context window is considered as an event with the probability modeled by
英語のヒント
負例サンプリングは元の目的関数を変更する。中心語の文脈窓が与えられたとき、任意の(文脈)語がこの文脈窓から来るという事実を、次のようにモデル化した確率をもつ事象とみなす。
(15.2.1)
where uses the definition of the sigmoid activation function:
英語のヒント
ここで、にはシグモイド活性化関数の定義を使う。
(15.2.2)
Let’s begin by maximizing the joint probability of all such events in text sequences to train word embeddings. Specifically, given a text sequence of length , denote by the word at time step and let the context window size be , consider maximizing the joint probability
英語のヒント
単語埋め込みを訓練するため、まずテキストの系列の中のそうした事象すべての同時確率を最大化することから始めよう。具体的には、長さのテキストの系列が与えられたとき、時間ステップの単語をで表し、文脈窓の大きさをとして、次の同時確率を最大化することを考える。
(15.2.3)
However, (15.2.3) only considers those events that involve positive examples. As a result, the joint probability in (15.2.3) is maximized to 1 only if all the word vectors are equal to infinity. Of course, such results are meaningless. To make the objective function more meaningful, negative sampling adds negative examples sampled from a predefined distribution.
英語のヒント
Denote by the event that a context word comes from the context window of a center word . For this event involving , from a predefined distribution sample noise words that are not from this context window. Denote by the event that a noise word () does not come from the context window of . Assume that these events involving both the positive example and negative examples are mutually independent. Negative sampling rewrites the joint probability (involving only positive examples) in (15.2.3) as
英語のヒント
文脈語が中心語の文脈窓から来るという事象をで表す。を含むこの事象について、あらかじめ決めた分布から、この文脈窓から来たのではないノイズ語を個抜き出す。ノイズ語()がの文脈窓から来ないという事象をで表す。正例と負例の両方を含むこれらの事象は互いに独立であると仮定する。負例サンプリングは、(15.2.3)の(正例だけを含む)同時確率を次のように書き直す。
(15.2.4)
where the conditional probability is approximated through events :
英語のヒント
ここで、条件付き確率は事象を通じて近似される。
(15.2.5)
Denote by and the indices of a word at time step of a text sequence and a noise word , respectively. The logarithmic loss with respect to the conditional probabilities in (15.2.5) is
英語のヒント
テキストの系列の時間ステップにある単語のインデックスと、ノイズ語のインデックスを、それぞれとで表す。(15.2.5)の条件付き確率についての対数損失は次のとおりである。
(15.2.6)
We can see that now the computational cost for gradients at each training step has nothing to do with the dictionary size, but linearly depends on . When setting the hyperparameter to a smaller value, the computational cost for gradients at each training step with negative sampling is smaller.
英語のヒント
これで、各訓練ステップでの勾配の計算コストは辞書の大きさとは関係がなく、に線形に依存することがわかる。ハイパーパラメータをもっと小さな値に設定すると、負例サンプリングでの各訓練ステップの勾配の計算コストは小さくなる。