Lecture 5: Sequence to sequence
文章目录
Quick Introduction of Batch Normalization
Changing Landscape
我们认为 error surface \text{error surface} error surface 较为崎岖的时候,模型较难训练 —— batch normalization 的想法是“将山铲平”。
如下图所示,在 w 1 w_1 w1 方向上斜率较小,而在 w 2 w_2 w2 方向上斜率较大,这时候模型较难训练,往往需要 adaptive learning rate \text{adaptive learning rate} adaptive learning rate 或 Adam \text{Adam} Adam 的帮助;而本文主要关注于更改 error surface \text{error surface} error surface 的做法。
![image-20220929103243275](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291032981.png#pic_center%20=60x)
如下图所示,有一个较为简单模型。那么,该模型在什么情况下会出现上述模型不好训练的情况?
![image-20220929103443605](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291034784.png#pic_center%20=60x)
如下图所示,当我们仅改变 w 1 w_1 w1 ,且输入 x 1 x_1 x1 的值较小时,对 y , e , L y,\ e,\ L y, e, L 的改变都是小的。
![image-20220929103934077](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291039565.png#pic_center%20=60x)
![image-20220929104132470](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291041021.png#pic_center%20=60x)
如上图所示,而当我们同时改变 w 2 w_2 w2,且输入 x 2 x_2 x2 的值较大时,对 y , e , L y,\ e,\ L y, e, L 的改变都是大的。也就是,在线性模型中,当不同维度的输入规模差距较大时,会出现上述模型不好训练的情况。—— 一个很直观想法:让不同维度的输入处在同一数值范围。
Feature Normalization
![image-20220929105121687](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291051090.png#pic_center%20=60x)
Considering Deep Learning
![image-20220929113026758](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291130913.png#pic_center%20=60x)
在各个特征 x x x 输入到网络之前,需要进行 feature normalization \text{feature normalization} feature normalization 得到 x ~ \tilde x x~。同样,在输入到更深层网络之间的输出往往也需要 normalization \text{normalization} normalization(如果激活函数 s i g m o i d sigmoid sigmoid,那么往往在其前进行 normalization \text{normalization} normalization)。那么如何对 z z z 做 normalization \text{normalization} normalization 呢?
类似地,也进行求均值、标准差的操作,最后求出 z − s c o r e z-score z−score
![image-20220929144620952](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291446502.png#pic_center%20=60x)
![image-20220929145240481](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291452491.png#pic_center%20=60x)
对于一个很大的网络,不可能一次全部算出所有输入经过 normalization \text{normalization} normalization 后的值,而只能一个个 batch 地去计算,因此叫做 batch normalization \text{batch normalization} batch normalization。
Batch Normalization
![image-20220929150647784](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291506722.png#pic_center%20=60x)
在求出 z ~ \tilde z z~ 后,往往还做 z ^ = γ ⊙ z ~ + β \hat z=\gamma \odot \tilde z+\beta z^=γ⊙z~+β 的操作,以打破 z ~ \tilde z z~ 均值为 0 0 0 的限制, γ \gamma γ 和 β \beta β 初始分别是全 1 1 1 和全 0 0 0 的向量。
Testing
在测试阶段或实际应用中,我们不一定拥有 batch \text{batch} batch 的信息 —— 计算 moving average \text{moving average} moving average。
![image-20220929160301248](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291603919.png#pic_center%20=60x)
How does Batch Normalization Help Optimization?
How Does Batch Normalization Help Optimization? (arxiv.org)
![image-20220929161710779](https://ttypora.oss-cn-nanjing.aliyuncs.com/img/202209291617532.png#pic_center%20=60x)