プリンキピア

第9章リカレントニューラルネットワーク

9.4.3. RNN-Based Character-Level Language Models9.4.3 RNNにもとづく文字単位の言語モデル

Recall that for language modeling in Section 9.3, we aim to predict the next token based on the current and past tokens; thus we shift the original sequence by one token as the targets (labels). Bengio et al. (2003) first proposed to use a neural network for language modeling. In the following we illustrate how RNNs can be used to build a language model. Let the minibatch size be one, and the sequence of the text be “machine”. To simplify training in subsequent sections, we tokenize text into characters rather than words and consider a character-level language model. Fig. 9.4.2 demonstrates how to predict the next character based on the current and previous characters via an RNN for character-level language modeling.
英語のヒント
9.3節の言語のモデリングでは、現在と過去のトークンにもとづいて次のトークンを予測することを目指し、そのため元の系列を1トークンずらしたものを目標(ラベル)とすることを思い出そう。Bengio et al. (2003)は、言語のモデリングにニューラルネットワークを使うことを初めて提案した。以下では、RNNを使って言語モデルを作る方法を示す。ミニバッチのサイズを1とし、テキストの系列を「machine」としよう。以降の節での訓練を単純にするため、テキストを単語ではなく文字にトークン化し、文字単位の言語モデルを考える。図9.4.2は、文字単位の言語のモデリングのために、RNNを使って現在と前の文字にもとづいて次の文字を予測する方法を示している。
Fig. 9.4.2図9.4.2
A character-level language model based on the RNN. The input and target sequences are “machin” and “achine”, respectively.
英語のヒント
RNNにもとづく文字単位の言語モデル。入力系列と目標系列は、それぞれ「machin」と「achine」である。
During the training process, we run a softmax operation on the output from the output layer for each time step, and then use the cross-entropy loss to compute the error between the model output and the target. Because of the recurrent computation of the hidden state in the hidden layer, the output, 𝐎3, of time step 3 in Fig. 9.4.2 is determined by the text sequence “m”, “a”, and “c”. Since the next character of the sequence in the training data is “h”, the loss of time step 3 will depend on the probability distribution of the next character generated based on the feature sequence “m”, “a”, “c” and the target “h” of this time step.
英語のヒント
訓練の過程では、各時間ステップで出力層からの出力にソフトマックス演算を行い、交差エントロピー損失を使ってモデルの出力と目標の誤差を計算する。隠れ層の隠れ状態は再帰的に計算されるので、図9.4.2の時間ステップ3の出力𝐎3は、テキストの系列「m」「a」「c」によって決まる。訓練データの系列の次の文字は「h」なので、時間ステップ3の損失は、特徴量の系列「m」「a」「c」にもとづいて生成された次の文字の確率分布と、この時間ステップの目標「h」に依存する。
In practice, each token is represented by a d-dimensional vector, and we use a batch size n>1. Therefore, the input 𝐗t at time step t will be an n×d matrix, which is identical to what we discussed in Section 9.4.2.
英語のヒント
実際には、各トークンはd次元のベクトルで表され、バッチサイズはn>1を使う。そのため、時間ステップtの入力𝐗tはn×dの行列になり、これは9.4.2節で論じたものと同じである。
In the following sections, we will implement RNNs for character-level language models.
英語のヒント
以下の節では、文字単位の言語モデルのためのRNNを実装する。