プリンキピア

第8章現代の畳み込みニューラルネットワーク

8.5.1. Training Deep Networks8.5.1 深いネットワークの訓練

When working with data, we often preprocess before training. Choices regarding data preprocessing often make an enormous difference in the final results. Recall our application of MLPs to predicting house prices (Section 5.7). Our first step when working with real data was to standardize our input features to have zero mean 𝝁=0 and unit variance 𝚺=𝟏 across multiple observations (Friedman, 1987), frequently rescaling the latter so that the diagonal is unity, i.e., Σii=1. Yet another strategy is to rescale vectors to unit length, possibly zero mean per observation. This can work well, e.g., for spatial sensor data. These preprocessing techniques and many others, are beneficial for keeping the estimation problem well controlled. For a review of feature selection and extraction see the article of Guyon et al. (2008), for example. Standardizing vectors also has the nice side-effect of constraining the function complexity of functions that act upon it. For instance, the celebrated radius-margin bound (Vapnik, 1995) in support vector machines and the Perceptron Convergence Theorem (Novikoff, 1962) rely on inputs of bounded norm.
英語のヒント
データを扱うとき、訓練の前に前処理をすることが多い。データの前処理についての選択は、しばしば最終的な結果に大きな違いを生む。住宅価格の予測にMLPを当てはめたこと(5.7節)を思い出そう。実データを扱うときの最初の手順は、入力の特徴量を、複数の観測にわたって平均が0(𝝁=0)、分散が1(𝚺=𝟏)になるよう標準化することだった(Friedman, 1987)。後者はしばしば、対角成分が1、つまりΣii=1となるようにスケールし直した。さらに別の戦略として、ベクトルを長さ1にスケールし直し、場合によっては観測ごとに平均を0にすることもある。これは、たとえば空間的なセンサーのデータでうまく働く。こうした前処理の手法やほかの多くの手法は、推定の問題をうまく制御するのに役立つ。特徴量の選択と抽出の概観については、たとえばGuyon et al. (2008)の記事を見てほしい。ベクトルを標準化することには、それに作用する関数の複雑さを制約するという、うれしい副作用もある。たとえば、サポートベクターマシンにおける有名な半径マージン上界(Vapnik, 1995)や、パーセプトロンの収束定理(Novikoff, 1962)は、ノルムが有界な入力に依存している。
Intuitively, this standardization plays nicely with our optimizers since it puts the parameters a priori on a similar scale. As such, it is only natural to ask whether a corresponding normalization step inside a deep network might not be beneficial. While this is not quite the reasoning that led to the invention of batch normalization (Ioffe and Szegedy, 2015), it is a useful way of understanding it and its cousin, layer normalization (Ba et al., 2016), within a unified framework.
英語のヒント
直観的には、この標準化はパラメータを前もって似たスケールにそろえるので、オプティマイザとの相性がよい。そうであれば、深いネットワークの内部で、これに対応する正規化の手順が役に立たないかと問うのはごく自然である。これはバッチ正規化(Ioffe and Szegedy, 2015)の発明につながった理屈そのものではないが、バッチ正規化とその親類である層正規化(Ba et al., 2016)を統一的な枠組みの中で理解する役に立つ考え方である。
Second, for a typical MLP or CNN, as we train, the variables in intermediate layers (e.g., affine transformation outputs in MLP) may take values with widely varying magnitudes: whether along the layers from input to output, across units in the same layer, and over time due to our updates to the model parameters. The inventors of batch normalization postulated informally that this drift in the distribution of such variables could hamper the convergence of the network. Intuitively, we might conjecture that if one layer has variable activations that are 100 times that of another layer, this might necessitate compensatory adjustments in the learning rates. Adaptive solvers such as AdaGrad (Duchi et al., 2011), Adam (Kingma and Ba, 2014), Yogi (Zaheer et al., 2018), or Distributed Shampoo (Anil et al., 2020) aim to address this from the viewpoint of optimization, e.g., by adding aspects of second-order methods. The alternative is to prevent the problem from occurring, simply by adaptive normalization.
英語のヒント
第二に、典型的なMLPやCNNでは、訓練するにつれて、中間層の変数(たとえばMLPのアフィン変換の出力)が、大きさの大きく異なる値をとることがある。入力から出力へ層をたどるにつれて、同じ層のユニットのあいだで、そしてモデルのパラメータを更新することで時間とともに、である。バッチ正規化の発明者たちは、こうした変数の分布のずれがネットワークの収束を妨げうると、略式に仮定した。直観的には、ある層の活性値が別の層の100倍の大きさなら、学習率を埋め合わせるように調整する必要があるかもしれない、と推測できる。AdaGrad(Duchi et al., 2011)、Adam(Kingma and Ba, 2014)、Yogi(Zaheer et al., 2018)、Distributed Shampoo(Anil et al., 2020)のような適応的なソルバーは、たとえば2次の手法の要素を加えることで、最適化の観点からこれに対処することを狙っている。もう一つの道は、単に適応的な正規化によって、問題が起きるのを防ぐことである。
Third, deeper networks are complex and tend to be more liable to overfitting. This means that regularization becomes more critical. A common technique for regularization is noise injection. This has been known for a long time, e.g., with regard to noise injection for the inputs (Bishop, 1995). It also forms the basis of dropout in Section 5.6. As it turns out, quite serendipitously, batch normalization conveys all three benefits: preprocessing, numerical stability, and regularization.
英語のヒント
第三に、深いネットワークは複雑で、過学習しやすい傾向がある。つまり、正則化がもっと重要になる。正則化のよくある手法は、ノイズの注入である。これは、たとえば入力へのノイズの注入について、昔から知られてきた(Bishop, 1995)。これは5.6節のドロップアウトの基礎にもなっている。ふたを開けてみると、まったく思いがけないことに、バッチ正規化は三つの利点をすべてもたらす。前処理、数値的な安定性、正則化である。
Batch normalization is applied to individual layers, or optionally, to all of them: In each training iteration, we first normalize the inputs (of batch normalization) by subtracting their mean and dividing by their standard deviation, where both are estimated based on the statistics of the current minibatch. Next, we apply a scale coefficient and an offset to recover the lost degrees of freedom. It is precisely due to this normalization based on batch statistics that batch normalization derives its name.
英語のヒント
バッチ正規化は個々の層に、あるいは選んで全部の層に当てはめられる。各訓練反復では、まず(バッチ正規化への)入力を、その平均を引いて標準偏差で割ることで正規化する。平均と標準偏差はどちらも、現在のミニバッチの統計量にもとづいて推定する。次に、失われた自由度を取り戻すため、スケールの係数とオフセットを当てはめる。バッチ正規化という名前は、まさにこのバッチの統計量にもとづく正規化に由来する。
Note that if we tried to apply batch normalization with minibatches of size 1, we would not be able to learn anything. That is because after subtracting the means, each hidden unit would take value 0. As you might guess, since we are devoting a whole section to batch normalization, with large enough minibatches the approach proves effective and stable. One takeaway here is that when applying batch normalization, the choice of batch size is even more significant than without batch normalization, or at least, suitable calibration is needed as we might adjust batch size.
英語のヒント
サイズ1のミニバッチでバッチ正規化を当てはめようとすると、何も学習できないことに注意してほしい。平均を引いた後では、各隠れユニットの値が0になってしまうからである。想像がつくだろうが、バッチ正規化に1節を丸ごと割いているのだから、十分に大きいミニバッチではこの手法は効果的で安定していることがわかる。ここで持ち帰るべき教訓の一つは、バッチ正規化を当てはめるときには、バッチサイズの選択が、バッチ正規化を使わないときよりもさらに重要になる、あるいは少なくとも、バッチサイズを調整するたびに適切な較正が必要になる、ということである。
Denote by ℬ a minibatch and let 𝐱∈ℬ be an input to batch normalization (BN). In this case the batch normalization is defined as follows:
英語のヒント
ℬをミニバッチとし、𝐱∈ℬをバッチ正規化(BN)への入力とする。このとき、バッチ正規化は次のように定義される。
BN(𝐱)=𝜸⊙𝐱−𝝁ˆℬ𝝈ˆℬ+𝜷.(8.5.1)
In (8.5.1), 𝝁ˆℬ is the sample mean and 𝝈ˆℬ is the sample standard deviation of the minibatch ℬ. After applying standardization, the resulting minibatch has zero mean and unit variance. The choice of unit variance (rather than some other magic number) is arbitrary. We recover this degree of freedom by including an elementwise scale parameter 𝜸 and shift parameter 𝜷 that have the same shape as 𝐱. Both are parameters that need to be learned as part of model training.
英語のヒント
(8.5.1)で、𝝁ˆℬはミニバッチℬの標本平均、𝝈ˆℬは標本標準偏差である。標準化を当てはめた後、得られるミニバッチは平均が0、分散が1になる。分散を1に選ぶこと(ほかの魔法の数ではなく)は恣意的である。この自由度は、𝐱と同じ形状をもつ要素ごとのスケールのパラメータ𝜸とシフトのパラメータ𝜷を含めることで取り戻す。どちらも、モデルの訓練の一部として学習する必要のあるパラメータである。
The variable magnitudes for intermediate layers cannot diverge during training since batch normalization actively centers and rescales them back to a given mean and size (via 𝝁ˆℬ and 𝝈ˆℬ). Practical experience confirms that, as alluded to when discussing feature rescaling, batch normalization seems to allow for more aggressive learning rates. We calculate 𝝁ˆℬ and 𝝈ˆℬ in (8.5.1) as follows:
英語のヒント
バッチ正規化は、中間層の変数の大きさを、(𝝁ˆℬと𝝈ˆℬを通じて)与えられた平均と大きさへと能動的に中心化し、スケールし直すので、訓練中にそれらが発散することはない。実地の経験からも、特徴量のスケールのし直しを論じたときにほのめかしたように、バッチ正規化はもっと積極的な学習率を許すらしいことが確かめられている。(8.5.1)の𝝁ˆℬと𝝈ˆℬは次のように計算する。
𝝁ˆℬ=1|ℬ|∑𝐱∈ℬ𝐱 and 𝝈ˆℬ2=1|ℬ|∑𝐱∈ℬ(𝐱−𝝁ˆℬ)2+ϵ.(8.5.2)
Note that we add a small constant ϵ>0 to the variance estimate to ensure that we never attempt division by zero, even in cases where the empirical variance estimate might be very small or vanish. The estimates 𝝁ˆℬ and 𝝈ˆℬ counteract the scaling issue by using noisy estimates of mean and variance. You might think that this noisiness should be a problem. On the contrary, it is actually beneficial.
英語のヒント
経験的な分散の推定値がとても小さかったり0になったりする場合でも、0で割ろうとすることがないよう、分散の推定値に小さな定数ϵ>0を加えることに注意してほしい。推定値𝝁ˆℬと𝝈ˆℬは、ノイズのある平均と分散の推定値を使って、スケールの問題を打ち消す。このノイズの多さは問題になるはずだと思うかもしれない。それどころか、実際には役に立つ。
This turns out to be a recurring theme in deep learning. For reasons that are not yet well-characterized theoretically, various sources of noise in optimization often lead to faster training and less overfitting: this variation appears to act as a form of regularization. Teye et al. (2018) and Luo et al. (2018) related the properties of batch normalization to Bayesian priors and penalties, respectively. In particular, this sheds some light on the puzzle of why batch normalization works best for moderate minibatch sizes in the 50–100 range. This particular size of minibatch seems to inject just the “right amount” of noise per layer, both in terms of scale via 𝝈ˆ, and in terms of offset via 𝝁ˆ: a larger minibatch regularizes less due to the more stable estimates, whereas tiny minibatches destroy useful signal due to high variance. Exploring this direction further, considering alternative types of preprocessing and filtering may yet lead to other effective types of regularization.
英語のヒント
これは、深層学習で繰り返し現れるテーマであることがわかる。理論的にはまだよく説明されていない理由で、最適化におけるさまざまなノイズ源は、しばしば訓練を速くし、過学習を減らす。この変動は、一種の正則化として働くように見える。Teye et al. (2018)とLuo et al. (2018)は、バッチ正規化の性質を、それぞれベイズ的な事前分布と罰則に関係づけた。特に、これは、なぜバッチ正規化が50〜100の範囲のほどほどのミニバッチサイズで最もよく働くのかという謎に、いくらか光を当てる。この特定のミニバッチのサイズは、𝝈ˆによるスケールの点でも、𝝁ˆによるオフセットの点でも、層ごとにちょうど「適量」のノイズを注入するらしい。ミニバッチが大きいと推定が安定するので正則化が弱まり、一方、ごく小さいミニバッチは分散が大きいので有用な信号を壊してしまう。この方向をさらに探り、ほかの種類の前処理やフィルタリングを考えれば、ほかの効果的な種類の正則化にたどり着くかもしれない。
Fixing a trained model, you might think that we would prefer using the entire dataset to estimate the mean and variance. Once training is complete, why would we want the same image to be classified differently, depending on the batch in which it happens to reside? During training, such exact calculation is infeasible because the intermediate variables for all data examples change every time we update our model. However, once the model is trained, we can calculate the means and variances of each layer’s variables based on the entire dataset. Indeed this is standard practice for models employing batch normalization; thus batch normalization layers function differently in training mode (normalizing by minibatch statistics) than in prediction mode (normalizing by dataset statistics). In this form they closely resemble the behavior of dropout regularization of Section 5.6, where noise is only injected during training.
英語のヒント
訓練済みのモデルを固定するなら、平均と分散の推定にはデータセット全体を使いたいと思うかもしれない。訓練が済んだら、同じ画像が、たまたまどのバッチに入っているかによって違うように分類されてほしくはないだろう。訓練中は、モデルを更新するたびにすべてのデータ事例の中間変数が変わるので、そうした正確な計算はできない。しかし、モデルを訓練し終えたら、データセット全体にもとづいて、各層の変数の平均と分散を計算できる。実際、これはバッチ正規化を使うモデルでの標準的なやり方である。そのため、バッチ正規化層は、訓練モード(ミニバッチの統計量で正規化する)と予測モード(データセットの統計量で正規化する)とで、違うふるまいをする。この形では、ノイズが訓練中にだけ注入される5.6節のドロップアウトによる正則化のふるまいによく似ている。