プリンキピア

第5章多層パーセプトロン

5.3.4. Training Neural Networks5.3.4 ニューラルネットワークの訓練

When training neural networks, forward and backward propagation depend on each other. In particular, for forward propagation, we traverse the computational graph in the direction of dependencies and compute all the variables on its path. These are then used for backpropagation where the compute order on the graph is reversed.
英語のヒント
ニューラルネットワークを訓練するとき、順伝播と逆伝播は互いに依存している。特に、順伝播では、計算グラフを依存関係の向きにたどり、その経路上のすべての変数を計算する。それらは次に逆伝播で使われ、そこではグラフ上の計算の順序が逆になる。
Take the aforementioned simple network as an illustrative example. On the one hand, computing the regularization term (5.3.5) during forward propagation depends on the current values of model parameters 𝐖(1) and 𝐖(2). They are given by the optimization algorithm according to backpropagation in the most recent iteration. On the other hand, the gradient calculation for the parameter (5.3.11) during backpropagation depends on the current value of the hidden layer output 𝐡, which is given by forward propagation.
英語のヒント
前述の単純なネットワークを例にとろう。一方では、順伝播のあいだに正則化項(5.3.5)を計算するのは、モデルのパラメータ𝐖(1)と𝐖(2)の現在の値に依存する。それらは、直前の反復での逆伝播にもとづいて、最適化アルゴリズムによって与えられる。他方では、逆伝播のあいだのパラメータの勾配の計算(5.3.11)は、隠れ層の出力𝐡の現在の値に依存し、それは順伝播によって与えられる。
Therefore when training neural networks, once model parameters are initialized, we alternate forward propagation with backpropagation, updating model parameters using gradients given by backpropagation. Note that backpropagation reuses the stored intermediate values from forward propagation to avoid duplicate calculations. One of the consequences is that we need to retain the intermediate values until backpropagation is complete. This is also one of the reasons why training requires significantly more memory than plain prediction. Besides, the size of such intermediate values is roughly proportional to the number of network layers and the batch size. Thus, training deeper networks using larger batch sizes more easily leads to out-of-memory errors.
英語のヒント
したがって、ニューラルネットワークを訓練するときには、モデルのパラメータを初期化したら、順伝播と逆伝播を交互に行い、逆伝播で得られた勾配を使ってモデルのパラメータを更新する。逆伝播は、重複した計算を避けるため、順伝播で保存した中間の値を再利用することに注意してほしい。その結果の一つとして、逆伝播が終わるまで中間の値を保持しておく必要がある。これは、訓練が単なる予測よりもかなり多くのメモリを必要とする理由の一つでもある。さらに、こうした中間の値の大きさは、ネットワークの層の数とバッチサイズにおおよそ比例する。そのため、より大きなバッチサイズでより深いネットワークを訓練すると、メモリ不足のエラーが起きやすくなる。