第9章リカレントニューラルネットワーク
9.7. Backpropagation Through Time9.7 時間をさかのぼる逆伝播
If you completed the exercises in Section 9.5, you would have seen that gradient clipping is vital for preventing the occasional massive gradients from destabilizing training. We hinted that the exploding gradients stem from backpropagating across long sequences. Before introducing a slew of modern RNN architectures, let’s take a closer look at how backpropagation works in sequence models in mathematical detail. Hopefully, this discussion will bring some precision to the notion of vanishing and exploding gradients. If you recall our discussion of forward and backward propagation through computational graphs when we introduced MLPs in Section 5.3, then forward propagation in RNNs should be relatively straightforward. Applying backpropagation in RNNs is called backpropagation through time (Werbos, 1990). This procedure requires us to expand (or unroll) the computational graph of an RNN one time step at a time. The unrolled RNN is essentially a feedforward neural network with the special property that the same parameters are repeated throughout the unrolled network, appearing at each time step. Then, just as in any feedforward neural network, we can apply the chain rule, backpropagating gradients through the unrolled net. The gradient with respect to each parameter must be summed across all places that the parameter occurs in the unrolled net. Handling such weight tying should be familiar from our chapters on convolutional neural networks.
英語のヒント
9.5節の練習問題をやり終えていれば、ときおり生じる巨大な勾配が訓練を不安定にするのを防ぐうえで、勾配クリッピングが欠かせないことがわかっただろう。勾配の爆発は長い系列にわたって逆伝播することから生じるとほのめかした。現代のRNNの構造を次々と紹介する前に、系列モデルで逆伝播がどう働くかを、数学的に詳しく見てみよう。この議論によって、勾配の消失と爆発という概念がいくらか正確になることを期待する。5.3節でMLPを紹介したときの、計算グラフを通じた順伝播と逆伝播の議論を覚えていれば、RNNの順伝播は比較的素直なはずである。RNNに逆伝播を当てはめることは、時間をさかのぼる逆伝播と呼ばれる(Werbos, 1990)。この手順では、RNNの計算グラフを一度に1時間ステップずつ展開する必要がある。展開したRNNは本質的に、同じパラメータが展開したネットワーク全体で繰り返され、各時間ステップに現れるという特別な性質をもつ順伝播型ニューラルネットワークである。そうすれば、どの順伝播型ニューラルネットワークとも同じように、連鎖律を当てはめ、展開したネットワークを通じて勾配を逆伝播できる。各パラメータについての勾配は、展開したネットワークでそのパラメータが現れるすべての場所にわたって足し合わせなければならない。こうした重みの共有の扱いは、畳み込みニューラルネットワークの章でおなじみのはずである。
Complications arise because sequences can be rather long. It is not unusual to work with text sequences consisting of over a thousand tokens. Note that this poses problems both from a computational (too much memory) and optimization (numerical instability) standpoint. Input from the first step passes through over 1000 matrix products before arriving at the output, and another 1000 matrix products are required to compute the gradient. We now analyze what can go wrong and how to address it in practice.
英語のヒント
系列はかなり長くなりうるので、厄介なことが生じる。1000を超えるトークンからなるテキスト系列を扱うことも珍しくない。これは、計算(メモリが多すぎる)と最適化(数値的な不安定さ)の両方の観点から問題を生むことに注意してほしい。最初のステップからの入力は、出力に届くまでに1000を超える行列の積を通り、勾配を計算するにはさらに1000の行列の積が必要になる。ここでは、何がまずくなりうるか、そして実際にはそれにどう対処するかを分析する。