第15章自然言語処理:事前学習
15.1.3. The Skip-Gram Model15.1.3 スキップグラムモデル
The skip-gram model assumes that a word can be used to generate its surrounding words in a text sequence. Take the text sequence “the”, “man”, “loves”, “his”, “son” as an example. Let’s choose “loves” as the center word and set the context window size to 2. As shown in Fig. 15.1.1, given the center word “loves”, the skip-gram model considers the conditional probability for generating the context words: “the”, “man”, “his”, and “son”, which are no more than 2 words away from the center word:
英語のヒント
スキップグラムモデルは、テキストの系列の中で、ある単語を使ってその周りの単語を生成できると仮定する。テキストの系列「the」「man」「loves」「his」「son」を例にとろう。「loves」を中心語に選び、文脈窓の大きさを2にする。図15.1.1に示すように、中心語「loves」が与えられたとき、スキップグラムモデルは、中心語から2語以内の距離にある文脈語「the」「man」「his」「son」を生成する、次の条件付き確率を考える。
(15.1.2)
Assume that the context words are independently generated given the center word (i.e., conditional independence). In this case, the above conditional probability can be rewritten as
英語のヒント
中心語が与えられたとき、文脈語は独立に生成されると仮定する(つまり条件付き独立性)。この場合、上の条件付き確率は次のように書き直せる。
(15.1.3)
Fig. 15.1.1図15.1.1
The skip-gram model considers the conditional probability of generating the surrounding context words given a center word.
英語のヒント
スキップグラムモデルは、中心語が与えられたときに周りの文脈語を生成する条件付き確率を考える。
In the skip-gram model, each word has two -dimensional-vector representations for calculating conditional probabilities. More concretely, for any word with index in the dictionary, denote by and its two vectors when used as a center word and a context word, respectively. The conditional probability of generating any context word (with index in the dictionary) given the center word (with index in the dictionary) can be modeled by a softmax operation on vector dot products:
英語のヒント
スキップグラムモデルでは、各単語は、条件付き確率を計算するための次元のベクトル表現を二つ持つ。もっと具体的には、辞書でのインデックスがの任意の単語について、それが中心語として使われるときと文脈語として使われるときの二つのベクトルを、それぞれとで表す。中心語(辞書でのインデックスは)が与えられたときに任意の文脈語(辞書でのインデックスは)を生成する条件付き確率は、ベクトルの内積へのソフトマックス演算でモデル化できる。
(15.1.4)
where the vocabulary index set . Given a text sequence of length , where the word at time step is denoted as . Assume that context words are independently generated given any center word. For context window size , the likelihood function of the skip-gram model is the probability of generating all context words given any center word:
英語のヒント
ここで、語彙のインデックスの集合はである。長さのテキストの系列が与えられ、時間ステップの単語をで表すとする。任意の中心語が与えられたとき、文脈語は独立に生成されると仮定する。文脈窓の大きさがのとき、スキップグラムモデルの尤度関数は、任意の中心語が与えられたときにすべての文脈語を生成する確率である。
(15.1.5)
where any time step that is less than or greater than can be omitted.
英語のヒント
ここで、より小さいかより大きい時間ステップはどれも省いてよい。
15.1.3.1. Training15.1.3.1 訓練
The skip-gram model parameters are the center word vector and context word vector for each word in the vocabulary. In training, we learn the model parameters by maximizing the likelihood function (i.e., maximum likelihood estimation). This is equivalent to minimizing the following loss function:
英語のヒント
スキップグラムモデルのパラメータは、語彙の各単語の中心語ベクトルと文脈語ベクトルである。訓練では、尤度関数を最大化すること(つまり最尤推定)によってモデルのパラメータを学習する。これは、次の損失関数を最小化することと同値である。
(15.1.6)
When using stochastic gradient descent to minimize the loss, in each iteration we can randomly sample a shorter subsequence to calculate the (stochastic) gradient for this subsequence to update the model parameters. To calculate this (stochastic) gradient, we need to obtain the gradients of the log conditional probability with respect to the center word vector and the context word vector. In general, according to (15.1.4) the log conditional probability involving any pair of the center word and the context word is
英語のヒント
確率的勾配降下法を使って損失を最小化するときは、各反復で、もっと短い部分系列をランダムに抜き出し、この部分系列についての(確率的な)勾配を計算して、モデルのパラメータを更新できる。この(確率的な)勾配を計算するには、中心語ベクトルと文脈語ベクトルについての対数条件付き確率の勾配を得る必要がある。一般に、(15.1.4)によれば、中心語と文脈語の任意の組を含む対数条件付き確率は次のとおりである。
(15.1.7)
Through differentiation, we can obtain its gradient with respect to the center word vector as
英語のヒント
微分によって、中心語ベクトルについてのその勾配は次のように得られる。
(15.1.8)
Note that the calculation in (15.1.8) requires the conditional probabilities of all words in the dictionary with as the center word. The gradients for the other word vectors can be obtained in the same way.
英語のヒント
(15.1.8)の計算には、を中心語とする辞書のすべての単語の条件付き確率が必要であることに注意しよう。ほかの単語ベクトルについての勾配も同じやり方で得られる。
After training, for any word with index in the dictionary, we obtain both word vectors (as the center word) and (as the context word). In natural language processing applications, the center word vectors of the skip-gram model are typically used as the word representations.
英語のヒント
訓練の後、辞書でのインデックスがの任意の単語について、二つの単語ベクトル(中心語として)と(文脈語として)が得られる。自然言語処理の応用では、ふつう、スキップグラムモデルの中心語ベクトルが単語の表現として使われる。