Batch Norm、Layer Norm、Weight Norm與SELU


加速網絡收斂——BN、LN、WN與selu

自Batch Norm出現之后,Layer Norm和Weight Norm作為Batch Norm的變體相繼出現。最近又出來一個很”簡單”的激活函數Selu,能夠實現automatic rescale and shift。這些結構都是為了保證網絡能夠堆疊的更深的基本條件之一。除了這四種,還有highway network與resnet。

Batch Norm

BN對某一層激活值做batch維度的歸一化,也就是對於每個batch,該層相應的output位置歸一化所使用的mean和variance都是一樣的。

  • BN的學習參數包含rescale和shift兩個參數;訓練的時候不斷更新這兩個參數和moving average mean and variance
  • BN在單獨的層級之間使用比較方便,比如CNN
  • 像RNN這樣unroll之后層數不定,直接用BN不太方便,需要對每一層(每個time step)做BN,並保留每一層的mean和variance。不過由於RNN輸入不定長(time step長度不定),可能會有validation或test的time step比train set里面的任何數據都長,因此會造成mean和variance不存在的情況。針對這個情況,需要對每個time step獨立做統計。在BN-LSTM中是這么做的:Generalizing the model to sequences longer than those seen during training is straightforward thanks to the rapid convergence of the activations to their steady-state distributions (cf. Figure 5). For our experiments we estimate the population statistics separately for each timestep 1, . . . , Tmax where Tmax is the length of the longest training sequence. When at test time we need to generalize beyond Tmax, we use the population statistic of time Tmax for all time steps beyond it. During training we estimate the statistics across the minibatch, independently for each timestep. At test time we use estimates obtained by averaging the minibatch estimates over the training set.當然,也可以只對輸入-隱層進行BN,或者stack RNN中同一個time step的不同層之間做BN
  • BN會引入噪聲(因為是mini batch而不是整個training set),所以對於噪聲敏感的方法(如RL)不太適用

BN算法思路如下(注意training和inference時候的區別)。

Layer Norm

LN也是對輸出歸一化的。LN也是為了消除各層的covariate shift,加快收斂速度。LN相對於BN就簡單多了。

  • 它在training和inference時沒有區別,只需要對當前隱藏層計算mean and variance就行
  • 不需要保存每層的moving average mean and variance
  • 不受batch size的限制,可以通過online learning的方式一條一條的輸入訓練數據
  • LN可以方便的在RNN中使用
  • LN增加了gain和bias作為學習的參數,μ和σ分別是該layer的隱層維度的均值和方差

Weight Norm

WN是使用參數重寫(reparameterization weight normalization)的方法來做歸一化的。哪里有weight,哪里就可以用WN來歸一化。WN也是用來加速收斂的。通過對weight進行normalization,可以保證在梯度回傳的時候,如果梯度越noisy(梯度越大),v的norm就越大,那么g/||v||就越小,從而就會抑制梯度。做到了梯度的自穩定(self-stabilize)。

  • 與LN稍不一樣,WN只有gain這一個學習參數

  • 前向傳播時,BN就是簡單的normalization

  • 梯度回傳的時候,會對梯度做自穩定

  • 論文里提到了WN能夠讓learning rate自適應/自穩定

If the learning rate is too large, the norm of the unnormalized weights grows quickly until an appropriate effective learning rate is reached. Once the norm of the weights has grown large with respect to the norm of the updates, the effective learning rate stabilizes.

  • WN與BN一樣,只不過BN直接從輸出角度出發,WN從weight角度出發

  • 注意WN的初始化,需要用第一個minibatch的均值和方差來初始化g和b。

  • Mean-only BN

考慮到BN並不能保證參數v的協方差矩陣為單位矩陣,也就是BN不能保證激活值與v獨立。而WN能做到,因此可以結合WN與BN,此時的BN經過修改,只進行去均值操作。

selu

最理想的結果就是讓每一層輸出的激活值為零均值、單位方差,從而能夠使得張量在傳播的過程當中,不會出現covariant shift,保證回傳梯度的穩定性,不會有梯度爆炸或彌散的問題。selu能夠很好的實現automatically shift and rescale neuron activations towards zero mean and unit variance without explicit normalization like what batch normalization technique does.

並且可以參考References中的Selus與Leaky Relu以及Relu之間的對比。selu 推薦用在大訓練樣本的數據集上。

References

Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks
Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift
RECURRENT BATCH NORMALIZATION
Layer Normalization
深度學習加速策略BN、WN和LN的聯系與區別,各自的優缺點和適用的場景?
SELUs (scaled exponential linear units) - Visualized and Histogramed Comparisons among ReLU and Leaky ReLU
引爆機器學習圈:「自歸一化神經網絡」提出新型激活函數SELU

 

 

來源: http://skyhigh233.com/blog/2017/07/21/norm/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM