Chapter VII network optimization and regularization

Chapter VII network optimization and regularization

Although the neural network has very strong skills, but when applied to machine learning neural network model still has some difficult problems. Divided into two categories:

(1) optimization problems: non-neural network model is a convex function, together with a depth gradient disappearing network, it is difficult to optimize; Further, the depth of the neural network model is generally more parameters, the training data is relatively large, will training leading to efficiency is relatively low.

(2) the generalization problem: because of the strong ability of neural networks fit, but prone to over-fitting in the training set. Therefore, when the depth of training the neural network, but also need to improve the generalization ability of the network through a certain regularization method.

Currently, researchers concluded from a large number of practical experience in a number of skills, from optimization and regularization two aspects to improve learning efficiency and get a good network model.

Network Optimization

Depth is a highly non-linear neural network model, the hazard function which is a non-convex function, thus minimizing the risk of a non-convex optimization problem, there will be many local optima.

Mesh optimization of difficulty

Depth parameters effective learning neural network is a challenging problem, mainly in the following areas.

Network structural diversity

Type neural network is very large, such as a convolutional network, and other network cycle, its structure is very different. Some are deep, some relatively wide. The role of different parameters in the network there are big differences, such as different weights and bias of the connection, and a circulation loop network and other heavy weights different weights on the connection.

Because of the diversity of the network structure, it is difficult to find a common optimization methods. Differences in the different methods of optimizing the structure of the network is also relatively large.

In addition, ultra-parameters of the network more generally, it also brings great challenges to optimization.

Non-high-dimensional convex optimization variables

Non-convex optimization problem is mainly low-dimensional space, there are some local optima. Fall into local minima optimization methods based on gradient descent, so the main difficulties in the low dimensional space is a non-convex optimization initialization parameters and how to select escape local minima. Parameters depth neural network is very large, its parameter learning is non-convex optimization problem in a very high-dimensional space, its challenges and different non-convex optimization problem in low-dimensional space.

Here Insert Picture Description
Here Insert Picture Description

Currently, the depth parameter learning neural network is mainly to find a set of parameters can minimize the risk of the structure by gradient descent. In a specific implementation, the gradient descent method can be divided into: batch gradient descent, and small quantities of stochastic gradient descent gradient descent three forms. Depending on the amount of the amount of data and parameters may be selected to achieve a particular form.

In addition to differences in convergence effect and efficiency, these three methods have common problems, such as 1) how to improve optimization algorithm; 2) how to initialize parameters; 3) how the pre-data and the like.

optimization

Small batch gradient descent

Depth in training the neural network, the size of the training data is usually relatively large. If the gradient descent
, the gradient is calculated for each iteration on the entire training data, which requires more computing resources. In addition large-scale training set of data is often very redundant, there is no need to calculate gradient across the training set. Therefore, when the depth of training the neural network, often using small batch gradient descent (Mini-Batch Gradient Descent).
Here Insert Picture Description
Here Insert Picture Description

Batch size selection

In small quantities gradient descent method, the effect of batch size (Batch Size) for network optimization is also very large. In general, batch size does not affect the desired stochastic gradient, but it will affect the stochastic gradient variance. The larger the batch size , the smaller the variance of the stochastic gradient, the smaller the noise introduced, training is also more stable , it is possible to set a larger learning rate .

While a smaller batch size, we need to set a smaller learning rate, otherwise the model will not converge. Learning rate usually increases as the size of the batch and accordingly increases.

一个简单有效的方法是线性缩放规则(Linear Scaling Rule)[Goyal等人,2017]:当批量大小增加m倍时,学习率也增加 m 倍。线性缩放规则往往在批量大小比较小时适用,当批量大小非常大时,线性缩放会使得训练不稳定。

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

学习率调整

学习率是神经网络优化时的重要超参数。在梯度下降法中,学习率 α 的取值 非常关键,如果过大就不会收敛,如果过小则收敛速度太慢。常用的学习率调整 方法包括学习率衰减、学习率预热、周期性学习率调整以及一些自适应调整学习 率的方法,比如 AdaGrad、RMSprop、AdaDelta 等。自适应学习率方法可以针对 每个参数设置不同的学习率。

学习率衰减

Here Insert Picture Description
Here Insert Picture Description

学习率预热

Here Insert Picture Description
Here Insert Picture Description

周期性学习率调整

为了使得梯度下降法能够逃离局部最小值或鞍点,一种经验性的方式是在 训练过程中周期性地增大学习率。虽然增大学习率可能短期内有损网络的收敛 稳定性,但从长期来看有助于找到更好的局部最优解。一般而言,当一个模型收敛一个平坦(Flat)的局部最小值时,其鲁棒性会更好,即微小的参数变动不会剧 烈影响模型能力;而当模型收敛到一个尖锐(Sharp)的局部最小值时,其鲁棒性也会比较差。具备良好泛化能力的模型通常应该是鲁棒的,因此理想的局部最小 值应该是平坦的。周期性学习率调整可以使得梯度下降法在优化过程中跳出尖锐的局部极小值,虽然会短期内会损害优化过程,但最终会收敛到更加理想的局部极小值。

本节介绍两种常用的周期性调整学习率的方法:循环学习率带热重启的随机梯度下降
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

AdaGrad 算法

Here Insert Picture Description
Here Insert Picture Description

RMSprop 算法

Here Insert Picture Description

AdaDelta 算法

Here Insert Picture Description
Here Insert Picture Description

梯度估计修正

除了调整学习率之外,还可以进行梯度估计(Gradient Estimation)的修正。 从图7.3看出,在随机(小批量)梯度下降法中,如果每次选取样本数量比较小,损 失会呈现震荡的方式下降。也就是说,随机梯度下降方法中每次迭代的梯度估计 和整个训练集上的最优梯度并不一致,具有一定的随机性。一种有效地缓解梯度 估计随机性的方式是通过使用最近一段时间内的平均梯度来代替当前时刻的随 机梯度来作为参数更新的方向,从而提高优化速度。

动量法

Here Insert Picture Description

Nesterov 加速梯度

Here Insert Picture Description
Here Insert Picture Description

Adam 算法

自适应动量估计(Adaptive Moment Estimation,Adam)算法[Kingma等 人,2015] 可以看作是动量法和 RMSprop 算法的结合,不但使用动量作为参数更 新方向,而且可以自适应调整学习率。
Here Insert Picture Description

梯度截断

在深度神经网络或循环神经网络中,除了梯度消失之外,梯度爆炸也是影响学习效率的主要因素。在基于梯度下降的优化过程中,如果梯度突然增大,用大 的梯度更新参数反而会导致其远离最优点。为了避免这种情况,当梯度的模大于 一定阈值时,就对梯度进行截断,称为梯度截断(Gradient Clipping)[Pascanu等 人,2013]。
Here Insert Picture Description

梯度截断是一种比较简单的启发式方法,把梯度的模限定在一个区间,当梯 度的模小于或大于这个区间时就进行截断。一般截断的方式有以下几种:
Here Insert Picture Description
Here Insert Picture Description

优化算法小结

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

参数初始化

神经网络训练过程中的参数学习是基于梯度下降法进行优化的。梯度下降法需要在开始训练时给每一个参数赋一个初始值。这个初始值的选取十分关键。

在感知器和 logistic 回归的训练中,我们一般将参数全部初始化为 0。但是这在神 经网络的训练中会存在一些问题。因为如果参数都为 0,在第一遍前向计算时,所 有的隐层神经元的激活值都相同。这样会导致深层神经元没有区分性。这种现象 也称为对称权重现象。

为了打破这个平衡,比较好的方式是对每个参数都随机初始化,这样使得不 同神经元之间的区分性更好。

随机初始化参数的一个问题是如何选取随机初始化的区间。如果参数取的太小,一是会导致神经元的输入过小,经过多层之后信号就慢慢消失了;二是还 会使得 Sigmoid 型激活函数丢失非线性的能力。以 Logistic 函数为例,在 0 附近 基本上是近似线性的。这样多层神经网络的优势也就不存在了。如果参数取的太大,会导致输入状态过大。对于 Sigmoid 型激活函数来说,激活值变得饱和,从而导致梯度接近于 0。

因此,要高效地训练神经网络,给参数选取一个合适的随机初始化区间是非 常重要的。一般而言,参数初始化的区间应该根据神经元的性质进行差异化的 设置。如果一个神经元的输入连接很多,它的每个输入连接上的权重就应该小一 些,以避免神经元的输出过大(当激活函数为 ReLU 时)或过饱和(当激活函数为 Sigmoid 函数时)。

经常使用的初始化方法有以下两种:
Here Insert Picture Description

Xavier 初始化

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

He 初始化

Here Insert Picture Description

数据预处理

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

逐层归一化

在深度神经网络中,中间某一层的输入是其之前的神经层的输出。因此,其 之前的神经层的参数变化会导致其输入的分布发生较大的差异。在使用随机梯 度下降来训练网络时,每次参数更新都会导致网络中间每一层的输入的分布发 生改变。越深的层,其输入的分布会改变得越明显。就像一栋高楼,低楼层发生一 个较小的偏移,都会导致高楼层较大的偏移。

从机器学习角度来看,如果某个神经层的输入分布发生了改变,那么其参数 需要重新学习,这种现象叫做内部协变量偏移(Internal Covariate Shift)。

Here Insert Picture Description

批量归一化

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

层归一化

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

其它归一化方法

权重归一化

Here Insert Picture Description

局部响应归一化

Here Insert Picture Description
Here Insert Picture Description

超参数优化

在神经网络中,除了可学习的参数之外,还存在很多超参数。这些超参数对 网络性能的影响也很大。不同的机器学习任务往往需要不同的超参数。常见的超参数有以下三类:

• 网络结构,包括神经元之间的连接关系、层数、每层的神经元数量、激活函 数的类型等。

• 优化参数,包括优化方法、学习率、小批量的样本数量等。

• 正则化系数。

超参数优化(Hyperparameter Optimization)主要存在两方面的困难。
(1) 超参数优化是一个组合优化问题,无法像一般参数那样通过梯度下降方法来优化,也没有一种通用有效的优化方法。

(2)评估一组超参数配置(Configuration) 的时间代价非常高,从而导致一些优化方法(比如演化算法(Evolution Algo- rithm)在超参数优化中难以应用。

Here Insert Picture Description

网格搜索

Here Insert Picture Description

随机搜索

Here Insert Picture Description

贝叶斯优化

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

动态资源分配

在超参数优化中,每组超参数配置的评估代价比较高。如果我们可以在较早 的阶段就估计出一组配置的效果会比较差,那么我们就可以中止这组配置的评 估,将更多的资源留给其它配置。这个问题可以归结为多臂赌博机问题的一个泛 化问题:最优臂问题(Best-Arm Problem),即在给定有限的机会次数下,如何玩这些赌博机并找到收益最大的臂。和多臂赌博机问题类似,最优臂问题也是在利用和探索之间找到最佳的平衡。

由于目前神经网络的优化方法一般都采取随机梯度下降,因此我们可以通 过一组超参数的学习曲线来预估这组超参数配置是否有希望得到比较好的结 果。如果一组超参数配置的学习曲线不收敛或者收敛比较差,我们可以应用早期停止(Early-Stopping)策略来中止当前的训练。
Here Insert Picture Description

神经架构搜索

上面介绍的超参数优化方法都是在固定(或变化比较小)的超参数空间X 中进行最优配置搜索,而最重要的神经网络架构一般还是需要由有经验的专家 来进行设计。从某种角度来讲,深度学习使得机器学习中的“特征工程”问题转变为“网络架构工程”问题。

神经架构搜索(Neural Architecture Search,NAS)[Zoph等人,2017]是一个 新的比较有前景的研究方向,通过神经网络来自动实现网络架构的设计。一个神 经网络的架构可以用一个变长的字符串来描述。利用元学习的思想,神经架构搜 索利用一个控制器来生成另一个子网络的架构描述。控制器可以由一个循环神 经网络来实现。控制器的训练可以通过强化学习来完成,其奖励信号为生成的子网络在开发集上的准确率。

网络正则化

机器学习模型的关键是泛化问题,即在样本真实分布上的期望风险最小化。 而训练数据集上的经验风险最小化和期望风险并不一致。由于神经网络的拟合 能力非常强,其在训练数据上的错误率往往都可以降到非常低,甚至可以到 0,从 而导致过拟合。因此,如何提高神经网络的泛化能力反而成为影响模型能力的最关键因素。

正则化(Regularization)是一类通过限制模型复杂度,从而避免过拟合,提 高泛化能力的方法,比如引入约束、增加先验、提前停止等。

Here Insert Picture Description

L1和L2正则化

Here Insert Picture Description
Here Insert Picture Description

权重衰减

Here Insert Picture Description

提前停止

Here Insert Picture Description

丢弃法

Here Insert Picture Description
集成学习的解释 每做一次丢弃,相当于从原始的网络中采样得到一个子网络。 如果一个神经网络有 n 个神经元,那么总共可以采样出 2n 个子网络。每次迭代都相当于训练一个不同的子网络,这些子网络都共享原始网络的参数。那么,最终 的网络可以近似看作是集成了指数级个不同网络的组合模型。
Here Insert Picture Description
Here Insert Picture Description

循环神经网络上的丢弃法

当在循环神经网络上应用丢弃法时,不能直接对每个时刻的隐状态进行随 机丢弃,这样会损害循环网络在时间维度上的记忆能力。一种简单的方法是对 非时间维度的连接(即非循环连接)进行随机丢失 [Zaremba 等人,2014]。如 图7.13所示,虚线边表示进行随机丢弃,不同的颜色表示不同的丢弃掩码。
Here Insert Picture Description
然而根据贝叶斯学习的解释,丢弃法是一种对参数 θ 的采样。每次采样的参 数需要在每个时刻保持不变。因此,在对循环神经网络上使用丢弃法时,需要对 参数矩阵的每个元素进行随机丢弃,并在所有时刻都使用相同的丢弃掩码。这种 方法称为变分丢弃法(Variational Dropout)[Gal等人,2016b]。图7.14给出了变 分丢弃法的示例,相同颜色表示使用相同的丢弃掩码。
Here Insert Picture Description

数据增强

Here Insert Picture Description

标签平滑

Here Insert Picture Description

总结

深度神经网络的优化和正则化是即对立又统一的关系。一方面我们希望优 化算法能找到一个全局最优解(或较好的局部最优解),另一方面我们又不希望 模型优化到最优解,这可能陷入过拟合。优化和正则化的统一目标是期望风险最小化。

在传统的机器学习中,有一些很好的理论可以帮助我们在模型的表示能力、 复杂度和泛化能力之间找到比较好的平衡,比如 Vapnik-Chervonenkis(VC)维 [Vapnik,1998] 和 Rademacher 复杂度 [Bartlett 等人,2002]。但是这些理论无法解 释深层神经网络在实际应用中的泛化能力表现。目前,深度神经网络的泛化能力还没有很好的理论支持。在传统机器学习模型上比较有效的 l1 或 l2 正则化在深 度神经网络中作用也比较有限,而一些经验的做法,比如使用随机梯度下降和提 前停止,会更有效。

The universal approximation theorem, represents the ability of neural networks is very strong. Intuitively, the depth of the neural network is prone to overfitting, because of the increased level of abstraction such that the model can be modeled [Bengio et al., 2013] on the training data dependencies rare. Some experiments show that, although the capacity is deep enough to remember all the neural network training data, but still remember the training data priority general pattern (Pattern), that is, patterns of high generalization capability [Zhang et al., 2016].

In recent years, the rapid development of deep learning to some extent also be attributed to a lot of depth to optimize neural networks and emerging methods of regularization. Although these methods are often empirical, but in practice, we get good results, so that we can efficiently, end to end train the neural network model, layer by layer pre-training and training time is no longer dependent on an early train the neural network and other relatively inefficient method.

Published 64 original articles · won praise 9 · views 4315

Guess you like

Origin blog.csdn.net/Avery123123/article/details/104197910