プリンキピア

第10章現代のリカレントニューラルネットワーク

10.8.3. Beam Search10.8.3 ビームサーチ

You could view sequence decoding strategies as lying on a spectrum, with beam search striking a compromise between the efficiency of greedy search and the optimality of exhaustive search. The most straightforward version of beam search is characterized by a single hyperparameter, the beam size, k. Let’s explain this terminology. At time step 1, we select the k tokens with the highest predicted probabilities. Each of them will be the first token of k candidate output sequences, respectively. At each subsequent time step, based on the k candidate output sequences at the previous time step, we continue to select k candidate output sequences with the highest predicted probabilities from k|𝒴| possible choices.
英語のヒント
系列の復号の戦略は、一つのスペクトルの上に並んでいるとみなせる。そこでは、ビームサーチが、貪欲探索の効率と全探索の最適性のあいだの折り合いをつける。最も素直な版のビームサーチは、一つのハイパーパラメータ、ビームサイズkで特徴づけられる。この用語を説明しよう。時間ステップ1では、予測確率が最も高いk個のトークンを選ぶ。それぞれが、k個の候補の出力系列のそれぞれ最初のトークンになる。続く各時間ステップでは、前の時間ステップのk個の候補の出力系列にもとづいて、k|𝒴|通りのありうる選択から、予測確率が最も高いk個の候補の出力系列を選び続ける。
Fig. 10.8.3図10.8.3
The process of beam search (beam size =2; maximum length of an output sequence =3). The candidate output sequences are 𝐴, 𝐶, 𝐴𝐵, 𝐶𝐸, 𝐴𝐵𝐷, and 𝐶𝐸𝐷.
英語のヒント
ビームサーチの過程(ビームサイズ=2、出力系列の最大の長さ=3)。候補の出力系列は𝐴、𝐶、𝐴𝐵、𝐶𝐸、𝐴𝐵𝐷、𝐶𝐸𝐷である。
Fig. 10.8.3 demonstrates the process of beam search with an example. Suppose that the output vocabulary contains only five elements: 𝒴={A,B,C,D,E}, where one of them is “<eos>”. Let the beam size be two and the maximum length of an output sequence be three. At time step 1, suppose that the tokens with the highest conditional probabilities P(y1∣𝐜) are A and C. At time step 2, for all y2∈𝒴, we compute
英語のヒント
図10.8.3は、例を使ってビームサーチの過程を示している。出力の語彙が五つの要素𝒴={A,B,C,D,E}だけを含み、そのうちの一つが「<eos>」だとする。ビームサイズを2、出力系列の最大の長さを3とする。時間ステップ1で、条件付き確率P(y1∣𝐜)が最も高いトークンがAとCだとする。時間ステップ2では、すべてのy2∈𝒴について次を計算する。
P(A,y2∣𝐜)=P(A∣𝐜)P(y2∣A,𝐜),P(C,y2∣𝐜)=P(C∣𝐜)P(y2∣C,𝐜),(10.8.2)
and pick the largest two among these ten values, say P(A,B∣𝐜) and P(C,E∣𝐜). Then at time step 3, for all y3∈𝒴, we compute
英語のヒント
そして、これら10個の値のうち最も大きい二つ、たとえばP(A,B∣𝐜)とP(C,E∣𝐜)を選ぶ。次に時間ステップ3で、すべてのy3∈𝒴について次を計算する。
P(A,B,y3∣𝐜)=P(A,B∣𝐜)P(y3∣A,B,𝐜),P(C,E,y3∣𝐜)=P(C,E∣𝐜)P(y3∣C,E,𝐜),(10.8.3)
and pick the largest two among these ten values, say P(A,B,D∣𝐜) and P(C,E,D∣𝐜). As a result, we get six candidates output sequences: (i) A; (ii) C; (iii) A, B; (iv) C, E; (v) A, B, D; and (vi) C, E, D.
英語のヒント
そして、これら10個の値のうち最も大きい二つ、たとえばP(A,B,D∣𝐜)とP(C,E,D∣𝐜)を選ぶ。その結果、六つの候補の出力系列が得られる。(i)A、(ii)C、(iii)A、B、(iv)C、E、(v)A、B、D、(vi)C、E、D。
In the end, we obtain the set of final candidate output sequences based on these six sequences (e.g., discard portions including and after “<eos>”). Then we choose the output sequence which maximizes the following score:
英語のヒント
最後に、これら六つの系列にもとづいて、最終的な候補の出力系列の集合を得る(たとえば、「<eos>」とその後の部分を捨てる)。そして、次のスコアを最大にする出力系列を選ぶ。
1Lαlog⁡P(y1,…,yL∣𝐜)=1Lα∑t′=1Llog⁡P(yt′∣y1,…,yt′−1,𝐜);(10.8.4)
here L is the length of the final candidate sequence and α is usually set to 0.75. Since a longer sequence has more logarithmic terms in the summation of (10.8.4), the term Lα in the denominator penalizes long sequences.
英語のヒント
ここで、Lは最終的な候補の系列の長さであり、αはふつう0.75に設定される。長い系列ほど(10.8.4)の和の中の対数の項が多いので、分母の項Lαが長い系列にペナルティを与える。
The computational cost of beam search is 𝒪(k|𝒴|T′). This result is in between that of greedy search and that of exhaustive search. Greedy search can be treated as a special case of beam search arising when the beam size is set to 1.
英語のヒント
ビームサーチの計算の費用は𝒪(k|𝒴|T′)である。この結果は、貪欲探索と全探索のあいだにある。貪欲探索は、ビームサイズを1に設定したときに生じるビームサーチの特別な場合として扱える。