プリンキピア

第15章自然言語処理:事前学習

15.2.2. Hierarchical Softmax15.2.2 階層的ソフトマックス

As an alternative approximate training method, hierarchical softmax uses the binary tree, a data structure illustrated in Fig. 15.2.1, where each leaf node of the tree represents a word in dictionary 𝒱.
英語のヒント
もう一つの近似的な訓練方法として、階層的ソフトマックスは、図15.2.1に示したデータ構造である二分木を使う。そこでは、木の各葉ノードが辞書𝒱の単語を表す。
Fig. 15.2.1図15.2.1
Hierarchical softmax for approximate training, where each leaf node of the tree represents a word in the dictionary.
英語のヒント
近似的な訓練のための階層的ソフトマックス。木の各葉ノードは辞書の単語を表す。
Denote by L(w) the number of nodes (including both ends) on the path from the root node to the leaf node representing word w in the binary tree. Let n(w,j) be the jth node on this path, with its context word vector being 𝐮n(w,j). For example, L(w3)=4 in Fig. 15.2.1. Hierarchical softmax approximates the conditional probability in (15.1.4) as
英語のヒント
二分木で、根ノードから単語wを表す葉ノードまでの経路上にあるノードの数(両端を含む)をL(w)で表す。この経路上のjthのノードをn(w,j)とし、その文脈語ベクトルを𝐮n(w,j)とする。たとえば、図15.2.1ではL(w3)=4である。階層的ソフトマックスは、(15.1.4)の条件付き確率を次のように近似する。
P(wo∣wc)=∏j=1L(wo)−1σ([[n(wo,j+1)=leftChild(n(wo,j))]]⋅𝐮n(wo,j)⊤𝐯c),(15.2.7)
where function σ is defined in (15.2.2), and leftChild(n) is the left child node of node n: if x is true, [[x]]=1; otherwise [[x]]=−1.
英語のヒント
ここで、関数σは(15.2.2)で定義したものであり、leftChild(n)はノードnの左の子ノードである。xが真なら[[x]]=1、そうでなければ[[x]]=−1である。
To illustrate, let’s calculate the conditional probability of generating word w3 given word wc in Fig. 15.2.1. This requires dot products between the word vector 𝐯c of wc and non-leaf node vectors on the path (the path in bold in Fig. 15.2.1) from the root to w3, which is traversed left, right, then left:
英語のヒント
例として、図15.2.1で、単語wcが与えられたときに単語w3を生成する条件付き確率を計算しよう。これには、wcの単語ベクトル𝐯cと、根からw3までの経路(図15.2.1の太線の経路)上にある葉でないノードのベクトルとの内積が必要である。この経路は、左、右、左の順にたどられる。
P(w3∣wc)=σ(𝐮n(w3,1)⊤𝐯c)⋅σ(−𝐮n(w3,2)⊤𝐯c)⋅σ(𝐮n(w3,3)⊤𝐯c).(15.2.8)
Since σ(x)+σ(−x)=1, it holds that the conditional probabilities of generating all the words in dictionary 𝒱 based on any word wc sum up to one:
英語のヒント
σ(x)+σ(−x)=1なので、任意の単語wcにもとづいて辞書𝒱のすべての単語を生成する条件付き確率の和は1になる。
∑w∈𝒱P(w∣wc)=1.(15.2.9)
Fortunately, since L(wo)−1 is on the order of 𝒪(log2|𝒱|) due to the binary tree structure, when the dictionary size 𝒱 is huge, the computational cost for each training step using hierarchical softmax is significantly reduced compared with that without approximate training.
英語のヒント
幸い、二分木の構造のおかげでL(wo)−1は𝒪(log2|𝒱|)のオーダーなので、辞書の大きさ𝒱がとても大きいとき、階層的ソフトマックスを使った各訓練ステップの計算コストは、近似的な訓練をしない場合と比べて大幅に減る。