プリンキピア

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

8.5.2. Batch Normalization Layers8.5.2 バッチ正規化層

Batch normalization implementations for fully connected layers and convolutional layers are slightly different. One key difference between batch normalization and other layers is that because the former operates on a full minibatch at a time, we cannot just ignore the batch dimension as we did before when introducing other layers.
英語のヒント
全結合層と畳み込み層とでは、バッチ正規化の実装が少し異なる。バッチ正規化とほかの層との鍵となる違いの一つは、前者が一度にミニバッチ全体に働くので、ほかの層を紹介したときのようにバッチの次元を無視するわけにはいかないことである。

8.5.2.1. Fully Connected Layers8.5.2.1 全結合層

When applying batch normalization to fully connected layers, Ioffe and Szegedy (2015), in their original paper inserted batch normalization after the affine transformation and before the nonlinear activation function. Later applications experimented with inserting batch normalization right after activation functions. Denoting the input to the fully connected layer by 𝐱, the affine transformation by 𝐖𝐱+𝐛 (with the weight parameter 𝐖 and the bias parameter 𝐛), and the activation function by ϕ, we can express the computation of a batch-normalization-enabled, fully connected layer output 𝐡 as follows:
英語のヒント
全結合層にバッチ正規化を当てはめるとき、Ioffe and Szegedy (2015)は元の論文で、バッチ正規化をアフィン変換の後、非線形の活性化関数の前に挿入した。後の応用では、活性化関数のすぐ後にバッチ正規化を挿入することも試された。全結合層への入力を𝐱、アフィン変換を𝐖𝐱+𝐛(重みパラメータ𝐖とバイアスパラメータ𝐛をもつ)、活性化関数をϕと表すと、バッチ正規化を備えた全結合層の出力𝐡の計算は次のように表せる。
𝐡=ϕ(BN(𝐖𝐱+𝐛)).(8.5.3)
Recall that mean and variance are computed on the same minibatch on which the transformation is applied.
英語のヒント
平均と分散は、変換を当てはめるのと同じミニバッチで計算されることを思い出そう。

8.5.2.2. Convolutional Layers8.5.2.2 畳み込み層

Similarly, with convolutional layers, we can apply batch normalization after the convolution but before the nonlinear activation function. The key difference from batch normalization in fully connected layers is that we apply the operation on a per-channel basis across all locations. This is compatible with our assumption of translation invariance that led to convolutions: we assumed that the specific location of a pattern within an image was not critical for the purpose of understanding.
英語のヒント
同じように、畳み込み層では、畳み込みの後、非線形の活性化関数の前にバッチ正規化を当てはめられる。全結合層のバッチ正規化との鍵となる違いは、演算をチャネルごとに、すべての位置にわたって当てはめることである。これは、畳み込みにつながった平行移動の不変性という仮定と両立する。つまり、画像の中でのパターンの具体的な位置は、理解という目的にとって決定的ではないと仮定したのである。
Assume that our minibatches contain m examples and that for each channel, the output of the convolution has height p and width q. For convolutional layers, we carry out each batch normalization over the m⋅p⋅q elements per output channel simultaneously. Thus, we collect the values over all spatial locations when computing the mean and variance and consequently apply the same mean and variance within a given channel to normalize the value at each spatial location. Each channel has its own scale and shift parameters, both of which are scalars.
英語のヒント
ミニバッチがm個の事例を含み、各チャネルについて畳み込みの出力の高さがp、幅がqだとする。畳み込み層では、各バッチ正規化を、出力チャネルあたりm⋅p⋅q個の要素にわたって同時に行う。したがって、平均と分散を計算するときにはすべての空間的な位置にわたって値を集め、その結果として、一つのチャネルの中では同じ平均と分散を当てはめて各空間位置の値を正規化する。各チャネルは自分のスケールとシフトのパラメータをもち、どちらもスカラーである。

8.5.2.3. Layer Normalization8.5.2.3 層正規化

Note that in the context of convolutions the batch normalization is well defined even for minibatches of size 1: after all, we have all the locations across an image to average. Consequently, mean and variance are well defined, even if it is just within a single observation. This consideration led Ba et al. (2016) to introduce the notion of layer normalization. It works just like a batch norm, only that it is applied to one observation at a time. Consequently both the offset and the scaling factor are scalars. For an n-dimensional vector 𝐱, layer norms are given by
英語のヒント
畳み込みの文脈では、バッチ正規化はサイズ1のミニバッチでもうまく定義されることに注意してほしい。結局のところ、平均をとるための画像全体にわたる位置がすべてあるからである。その結果、たとえ一つの観測の中だけであっても、平均と分散はうまく定義される。この考察から、Ba et al. (2016)は層正規化という概念を導入した。これはバッチ正規化とまったく同じように働くが、一度に一つの観測に当てはめられる点だけが違う。その結果、オフセットとスケールの係数はどちらもスカラーになる。n次元のベクトル𝐱に対して、層正規化は次で与えられる。
𝐱→LN(𝐱)=𝐱−μˆσˆ,(8.5.4)
where scaling and offset are applied coefficient-wise and given by
英語のヒント
ここで、スケールとオフセットは係数ごとに当てはめられ、次で与えられる。
μˆ=def1n∑i=1nxi and σˆ2=def1n∑i=1n(xi−μˆ)2+ϵ.(8.5.5)
As before we add a small offset ϵ>0 to prevent division by zero. One of the major benefits of using layer normalization is that it prevents divergence. After all, ignoring ϵ, the output of the layer normalization is scale independent. That is, we have LN(𝐱)≈LN(α𝐱) for any choice of α≠0. This becomes an equality for |α|→∞ (the approximate equality is due to the offset ϵ for the variance).
英語のヒント
前と同じく、0での割り算を防ぐために、小さなオフセットϵ>0を加える。層正規化を使う大きな利点の一つは、発散を防ぐことである。結局のところ、ϵを無視すれば、層正規化の出力はスケールに依存しない。つまり、α≠0をどう選んでもLN(𝐱)≈LN(α𝐱)となる。|α|→∞では、これは等式になる(近似的な等号になるのは、分散に対するオフセットϵのためである)。
Another advantage of the layer normalization is that it does not depend on the minibatch size. It is also independent of whether we are in training or test regime. In other words, it is simply a deterministic transformation that standardizes the activations to a given scale. This can be very beneficial in preventing divergence in optimization. We skip further details and recommend that interested readers consult the original paper.
英語のヒント
層正規化のもう一つの利点は、ミニバッチのサイズに依存しないことである。また、訓練の状況かテストの状況かにも依存しない。言い換えれば、層正規化は、活性値を与えられたスケールに標準化する、単なる決定的な変換である。これは、最適化での発散を防ぐのにとても役立ちうる。これ以上の詳細は省くので、興味のある読者は元の論文を参照してほしい。

8.5.2.4. Batch Normalization During Prediction8.5.2.4 予測時のバッチ正規化

As we mentioned earlier, batch normalization typically behaves differently in training mode than in prediction mode. First, the noise in the sample mean and the sample variance arising from estimating each on minibatches is no longer desirable once we have trained the model. Second, we might not have the luxury of computing per-batch normalization statistics. For example, we might need to apply our model to make one prediction at a time.
英語のヒント
前に述べたように、バッチ正規化はふつう、訓練モードと予測モードとで違うふるまいをする。第一に、ミニバッチごとに推定することから生じる標本平均と標本分散のノイズは、モデルを訓練し終えたらもう望ましくない。第二に、バッチごとの正規化の統計量を計算する余裕がないかもしれない。たとえば、一度に一つの予測をするためにモデルを当てはめる必要があるかもしれない。
Typically, after training, we use the entire dataset to compute stable estimates of the variable statistics and then fix them at prediction time. Hence, batch normalization behaves differently during training than at test time. Recall that dropout also exhibits this characteristic.
英語のヒント
ふつう、訓練の後、データセット全体を使って変数の統計量の安定した推定値を計算し、予測時にはそれを固定する。そのため、バッチ正規化は、訓練中とテスト時とで違うふるまいをする。ドロップアウトもこの特徴を示すことを思い出そう。