HOME

TheInfoList



OR:

Batch normalization (also known as batch norm) is a method used to make training of
artificial neural network Artificial neural networks (ANNs), usually simply called neural networks (NNs) or neural nets, are computing systems inspired by the biological neural networks that constitute animal brains. An ANN is based on a collection of connected unit ...
s faster and more stable through normalization of the layers' inputs by re-centering and re-scaling. It was proposed by Sergey Ioffe and Christian Szegedy in 2015. While the effect of batch normalization is evident, the reasons behind its effectiveness remain under discussion. It was believed that it can mitigate the problem of ''internal covariate shift'', where parameter initialization and changes in the distribution of the inputs of each layer affect the learning rate of the network. Recently, some scholars have argued that batch normalization does not reduce internal covariate shift, but rather smooths the
objective function In mathematical optimization and decision theory, a loss function or cost function (sometimes also called an error function) is a function that maps an event or values of one or more variables onto a real number intuitively representing some "cos ...
, which in turn improves the performance. However, at initialization, batch normalization in fact induces severe gradient explosion in deep networks, which is only alleviated by skip connections in residual networks. Others maintain that batch normalization achieves length-direction decoupling, and thereby accelerates
neural networks A neural network is a network or circuit of biological neurons, or, in a modern sense, an artificial neural network, composed of artificial neurons or nodes. Thus, a neural network is either a biological neural network, made up of biological ...
. More recently a normalize gradient clipping technique and smart hyperparameter tuning has been introduced in Normalizer-Free Nets, so called "NF-Nets" which mitigates the need for batch normalization.


Internal covariate shift

Each layer of a neural network has inputs with a corresponding distribution, which is affected during the training process by the randomness in the parameter initialization and the randomness in the input data. The effect of these sources of randomness on the distribution of the inputs to internal layers during training is described as internal covariate shift. Although a clear-cut precise definition seems to be missing, the phenomenon observed in experiments is the change on means and variances of the inputs to internal layers during training. Batch normalization was initially proposed to mitigate internal covariate shift. During the training stage of networks, as the parameters of the preceding layers change, the distribution of inputs to the current layer changes accordingly, such that the current layer needs to constantly readjust to new distributions. This problem is especially severe for deep networks, because small changes in shallower hidden layers will be amplified as they propagate within the network, resulting in significant shift in deeper hidden layers. Therefore, the method of batch normalization is proposed to reduce these unwanted shifts to speed up training and to produce more reliable models. Besides reducing internal covariate shift, batch normalization is believed to introduce many other benefits. With this additional operation, the network can use higher
learning rate In machine learning and statistics, the learning rate is a tuning parameter in an optimization algorithm that determines the step size at each iteration while moving toward a minimum of a loss function. Since it influences to what extent newly ac ...
without vanishing or exploding gradients. Furthermore, batch normalization seems to have a regularizing effect such that the network improves its generalization properties, and it is thus unnecessary to use dropout to mitigate
overfitting mathematical modeling, overfitting is "the production of an analysis that corresponds too closely or exactly to a particular set of data, and may therefore fail to fit to additional data or predict future observations reliably". An overfitt ...
. It has been observed also that with batch norm the network becomes more robust to different initialization schemes and learning rates.


Procedures


Transformation

In a neural network, batch normalization is achieved through a normalization step that fixes the means and variances of each layer's inputs. Ideally, the normalization would be conducted over the entire training set, but to use this step jointly with stochastic optimization methods, it is impractical to use the global information. Thus, normalization is restrained to each mini-batch in the training process. Let us use ''B'' to denote a mini-batch of size ''m'' of the entire training set. The empirical
mean There are several kinds of mean in mathematics, especially in statistics. Each mean serves to summarize a given group of data, often to better understand the overall value (magnitude and sign) of a given data set. For a data set, the ''arithme ...
and
variance In probability theory and statistics, variance is the expectation of the squared deviation of a random variable from its population mean or sample mean. Variance is a measure of dispersion, meaning it is a measure of how far a set of numbers ...
of ''B'' could thus be denoted as \mu_B = \frac 1 m \sum_^m x_i, and \sigma_B^2 = \frac 1 m \sum_^m (x_i-\mu_B)^2. For a layer of the network with ''d-''dimensional input, x = (x^,...,x^), each dimension of its input is then normalized (i.e. re-centered and re-scaled) separately, \hat_^ = \frac \sqrt, where k \in ,d/math> and i \in ,m/math>; \mu_B^ and \sigma_B^ are the per-dimension mean and standard deviation, respectively. \epsilon is added in the denominator for numerical stability and is an arbitrarily small constant. The resulting normalized activation \hat^have zero mean and unit variance, if \epsilon is not taken into account. To restore the representation power of the network, a transformation step then follows as y_i^ = \gamma^ \hat_^ +\beta^, where the parameters \gamma^ and \beta^ are subsequently learned in the optimization process. Formally, the operation that implements batch normalization is a transform BN_: x^_ \rightarrow y^_ called the Batch Normalizing transform. The output of the BN transform y^ = BN_(x^) is then passed to other network layers, while the normalized output \hat_^ remains internal to the current layer.


Backpropagation

The described BN transform is a
differentiable In mathematics, a differentiable function of one real variable is a function whose derivative exists at each point in its domain. In other words, the graph of a differentiable function has a non-vertical tangent line at each interior point in its ...
operation, and the gradient of the
loss Loss may refer to: Arts, entertainment, and media Music * ''Loss'' (Bass Communion album) (2006) * ''Loss'' (Mull Historical Society album) (2001) *"Loss", a song by God Is an Astronaut from their self-titled album (2008) * Losses "(Lil Tjay son ...
''l'' with respect to the different parameters can be computed directly with the
chain rule In calculus, the chain rule is a formula that expresses the derivative of the composition of two differentiable functions and in terms of the derivatives of and . More precisely, if h=f\circ g is the function such that h(x)=f(g(x)) for every , ...
. Specifically, \frac depends on the choice of
activation function In artificial neural networks, the activation function of a node defines the output of that node given an input or set of inputs. A standard integrated circuit can be seen as a digital network of activation functions that can be "ON" (1) or " ...
, and the
gradient In vector calculus, the gradient of a scalar-valued differentiable function of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p is the "direction and rate of fastest increase". If the gradi ...
against other parameters could be expressed as a function of \frac : \frac = \frac\gamma^ , \frac = \sum_^m \frac\hat_i^ , \frac = \sum_^m \frac ,
\frac = \sum_^m \frac (x_i^-\mu_B^)\left(-\frac 2 (\sigma_B^+\epsilon)^\right) , \frac = \sum_^m \frac\frac+\frac\frac\sum_^m (-2)\cdot (x_i^-\mu^_B) , and \frac = \frac\frac+\frac\frac+\frac\frac .


Inference

During the training stage, the normalization steps depend on the mini-batches to ensure efficient and reliable training. However, in the inference stage, this dependence is not useful any more. Instead, the normalization step in this stage is computed with the population statistics such that the output could depend on the input in a deterministic manner. The population mean, E ^/math>, and variance, \operatorname ^/math>, are computed as: E ^= E_ mu^_B , and \operatorname ^= \fracE_ left(\sigma^_B \right)^2 . The population statistics thus is a complete representation of the mini-batches. The BN transform in the inference step thus becomes y^ = BN^_(x^)=\gamma^\frac + \beta^, where y^ is passed on to future layers instead of x^. Since the parameters are fixed in this transformation, the batch normalization procedure is essentially applying a
linear transform In mathematics, and more specifically in linear algebra, a linear map (also called a linear mapping, linear transformation, vector space homomorphism, or in some contexts linear function) is a mapping V \to W between two vector spaces that pre ...
to the activation.


Theoretical Understanding

Although batch normalization has become popular due to its strong empirical performance, the working mechanism of the method is not yet well-understood. The explanation made in the original paper was that batch norm works by reducing internal covariate shift, but this has been challenged by more recent work. One experiment trained a VGG-16 network under 3 different training regimes: standard (no batch norm), batch norm, and batch norm with noise added to each layer during training. In the third model, the noise has non-zero mean and non-unit variance, i.e. it explicitly introduces covariate shift. Despite this, it showed similar accuracy to the second model, and both performed better than the first, suggesting that covariate shift is not the reason that batch norm improves performance.


Smoothness

One alternative explanation, is that the improvement with batch normalization is instead due to it producing a smoother parameter space and smoother gradients, as formalized by a smaller
Lipschitz constant In mathematical analysis, Lipschitz continuity, named after German mathematician Rudolf Lipschitz, is a strong form of uniform continuity for functions. Intuitively, a Lipschitz continuous function is limited in how fast it can change: there ex ...
. Consider two identical networks, one contains batch normalization layers and the other doesn't, the behaviors of these two networks are then compared. Denote the loss functions as L and \hat , respectively. Let the input to both networks be x , and the output be y , for which y = Wx , where W is the layer weights. For the second network, y additionally goes through a batch normalization layer. Denote the normalized activation as \hat , which has zero mean and unit variance. Let the transformed activation be z = \gamma\hat+\beta , and suppose \gamma and \beta are constants. Finally, denote the standard deviation over a mini-batch \hat \in \R^m as \sigma_j . First, it can be shown that the gradient magnitude of a batch normalized network, , , \triangledown_\hat, , , is bounded, with the bound expressed as , , \triangledown_\hat, , ^2 \le \frac\Bigg(, , \triangledown_L, , ^2-\frac\langle 1,\triangledown_L\rangle^2-\frac\langle\triangledown_L,\hat_j\rangle^2\bigg) . Since the gradient magnitude represents the Lipschitzness of the loss, this relationship indicates that a batch normalized network could achieve greater Lipschitzness comparatively. Notice that the bound gets tighter when the gradient \triangledown_\hat correlates with the activation \hat , which is a common phenomena. The scaling of \frac is also significant, since the variance is often large. Secondly, the quadratic form of the loss Hessian with respect to activation in the gradient direction can be bounded as (\triangledown_\hat)^T \frac(\triangledown_\hat) \le \frac \bigg(\frac\bigg)^T \bigg(\frac\bigg)\bigg(\frac\bigg) -\frac\langle\triangledown_L,\hat\rangle \bigg, \bigg, \frac\bigg, \bigg, ^2 . The scaling of \frac indicates that the loss Hessian is resilient to the mini-batch variance, whereas the second term on the right hand side suggests that it becomes smoother when the
Hessian A Hessian is an inhabitant of the German state of Hesse. Hessian may also refer to: Named from the toponym *Hessian (soldier), eighteenth-century German regiments in service with the British Empire **Hessian (boot), a style of boot **Hessian f ...
and the inner product are non-negative. If the loss is locally
convex Convex or convexity may refer to: Science and technology * Convex lens, in optics Mathematics * Convex set, containing the whole line segment that joins points ** Convex polygon, a polygon which encloses a convex set of points ** Convex polytope ...
, then the Hessian is positive semi-definite, while the inner product is positive if \hat is in the direction towards the minimum of the loss. It could thus be concluded from this inequality that the gradient generally becomes more predictive with the batch normalization layer. It then follows to translate the bounds related to the loss with respect to the normalized activation to a bound on the loss with respect to the network weights: \hat \le \frac(g^2_j-m\mu^2_-\lambda^2\langle \triangledown_L,\hat_j\rangle^2) , where g_j = max_ , , \triangledown_W L, , ^2 and \hat_j = max_ , , \triangledown_W \hat, , ^2 . In addition to the smoother landscape, it is further shown that batch normalization could result in a better initialization with the following inequality: , , W_0-\hat^*, , ^2 \le , , W_0-W^*, , ^2-\frac(, , W^*, , ^2-\langle W^*,W_0\rangle)^2 , where W^* and \hat^* are the local optimal weights for the two networks, respectively. Some scholars argue that the above analysis cannot fully capture the performance of batch normalization, because the proof only concerns the largest eigenvalue, or equivalently, one direction in the landscape at all points. It is suggested that the complete eigenspectrum needs to be taken into account to make a conclusive analysis.


Measure

Since it is hypothesized that batch normalization layers could reduce internal covariate shift, an experiment is set up to measure quantitatively how much covariate shift is reduced. First, the notion of internal covariate shift needs to be defined mathematically. Specifically, to quantify the adjustment that a layer's parameters make in response to updates in previous layers, the correlation between the gradients of the loss before and after all previous layers are updated is measured, since gradients could capture the shifts from the first-order training method. If the shift introduced by the changes in previous layers is small, then the correlation between the gradients would be close to 1. The correlation between the gradients are computed for four models: a standard VGG network, a VGG network with batch normalization layers, a 25-layer deep linear network (DLN) trained with full-batch gradient descent, and a DLN network with batch normalization layers. Interestingly, it is shown that the standard VGG and DLN models both have higher correlations of gradients compared with their counterparts, indicating that the additional batch normalization layers are not reducing internal covariate shift.


Vanishing/exploding gradients

Even though batchnorm was originally introduced to alleviate gradient vanishing or explosion problems, a deep batchnorm network in fact ''suffers from gradient explosion'' at initialization time, no matter what it uses for nonlinearity. Thus the optimization landscape is very far from smooth for a randomly initialized, deep batchnorm network. More precisely, if the network has L layers, then the gradient of the first layer weights has norm > c\lambda^L for some \lambda>1, c>0 depending only on the nonlinearity. For any fixed nonlinearity, \lambda decreases as the batch size increases. For example, for ReLU, \lambda decreases to \pi/(\pi-1)\approx 1.467 as the batch size tends to infinity. Practically, this means deep batchnorm networks are untrainable. This is only relieved by skip connections in the fashion of residual networks. This gradient explosion on the surface contradicts the ''smoothness'' property explained in the previous section, but in fact they are consistent. The previous section studies the effect of inserting a single batchnorm in a network, while the gradient explosion depends on stacking batchnorms typical of modern deep neural networks.


Decoupling

Another possible reason for the success of batch normalization is that it decouples the length and direction of the weight vectors and thus facilitates better training. By interpreting batch norm as a reparametrization of weight space, it can be shown that the length and the direction of the weights are separated and can thus be trained separately. For a particular neural network unit with input x and weight vector w , denote its output as f(w) = E_x
phi(x^Tw) Phi (; uppercase Φ, lowercase φ or ϕ; grc, ϕεῖ ''pheî'' ; Modern Greek: ''fi'' ) is the 21st letter of the Greek alphabet. In Archaic and Classical Greek (c. 9th century BC to 4th century BC), it represented an aspirated voicele ...
, where \phi is the activation function, and denote S = E x^T . Assume that E 0 , and that the spectrum of the matrix S is bounded as 0<\mu = \lambda_(S) , L=\lambda_(S)<\infty , such that S is symmetric positive definite. Adding batch normalization to this unit thus results in f_(w,\gamma,\beta) = E_x phi(BN(x^Tw))= E_x\bigg phi\bigg(\gamma(\frac)+\beta\bigg)\bigg , by definition. The variance term can be simplified such that var_x ^Tww^TSw . Assume that x has zero mean and \beta can be omitted, then it follows that f_(w,\gamma) = E_x\bigg phi\bigg(\gamma\frac\bigg)\bigg , where (w^TSw)^ is the induced norm of S , , , w, , _s . Hence, it could be concluded that f_(w,\gamma) = E_x phi(x^T\tilde) , where \tilde=\gamma \frac , and \gamma and w accounts for its length and direction separately. This property could then be used to prove the faster convergence of problems with batch normalization.


Linear convergence


Least-square problem

With the reparametrization interpretation, it could then be proved that applying batch normalization to the ordinary least squares problem achieves a linear convergence rate in gradient descent, which is faster than the regular gradient descent with only sub-linear convergence. Denote the objective of minimizing an ordinary least squares problem as min_f_(\tilde)=min_(E_ y-x^T\tilde)^2=min_(2u^T\tilde+\tilde^TS\tilde) , where u=E yx . Since \tilde=\gamma\frac , the objective thus becomes min_f_(w,\gamma)=min_\bigg(2\gamma\frac\bigg) , where 0 is excluded to avoid 0 in the denominator. Since the objective is convex with respect to \gamma , its optimal value could be calculated by setting the partial derivative of the objective against \gamma to 0. The objective could be further simplified to be min_\rho(w)=min_\bigg(-\frac\bigg) . Note that this objective is a form of the generalized Rayleigh quotient \tilde(w)=\frac , where B\in R^ is a symmetric matrix and A\in R^ is a symmetric
positive definite In mathematics, positive definiteness is a property of any object to which a bilinear form or a sesquilinear form may be naturally associated, which is positive-definite. See, in particular: * Positive-definite bilinear form * Positive-definite f ...
matrix. It is proven that the gradient descent convergence rate of the generalized
Rayleigh quotient In mathematics, the Rayleigh quotient () for a given complex Hermitian matrix ''M'' and nonzero vector ''x'' is defined as: R(M,x) = . For real matrices and vectors, the condition of being Hermitian reduces to that of being symmetric, and the co ...
is \frac\le \bigg(1-\frac\bigg)^\frac , where \lambda_1 is the largest
eigenvalue In linear algebra, an eigenvector () or characteristic vector of a linear transformation is a nonzero vector that changes at most by a scalar factor when that linear transformation is applied to it. The corresponding eigenvalue, often denoted b ...
of B , \lambda_2 is the second largest eigenvalue of B , and \lambda_ is the smallest eigenvalue of B . In our case, B=uu^T is a rank one matrix, and the convergence result can be simplified accordingly. Specifically, consider gradient descent steps of the form w_=w_t-\eta_t\triangledown\rho(w_t) with step size \eta_t=\frac , and starting from \rho(w_0)\ne 0 , then \rho(w_t)-\rho(w^*)\le \bigg(1-\frac\bigg)^(\rho(w_0)-\rho(w^*)) .


Learning halfspace problem

The problem of learning halfspaces refers to the training of the
Perceptron In machine learning, the perceptron (or McCulloch-Pitts neuron) is an algorithm for supervised learning of binary classifiers. A binary classifier is a function which can decide whether or not an input, represented by a vector of numbers, belon ...
, which is the simplest form of neural network. The optimization problem in this case is min_f_(\tilde)=E_ phi(z^T\tilde) , where z=-yx and \phi is an arbitrary loss function. Suppose that \phi is infinitely differentiable and has a bounded derivative. Assume that the objective function f_ is \zeta -
smooth Smooth may refer to: Mathematics * Smooth function, a function that is infinitely differentiable; used in calculus and topology * Smooth manifold, a differentiable manifold for which all the transition maps are smooth functions * Smooth algebrai ...
, and that a solution \alpha^* = argmin_, , \triangledown f(\alpha w), , ^2 exists and is bounded such that -\infty < \alpha^* < \infty . Also assume z is a multivariate normal random variable. With the Gaussian assumption, it can be shown that all critical points lie on the same line, for any choice of loss function \phi . Specifically, the gradient of f_ could be represented as \triangledown_f_(\tilde)=c_1(\tilde)u+c_2(\tilde)S\tilde , where c_1(\tilde)=E_z phi^(z^T\tilde)E_z phi^(z^T\tilde)u^T\tilde) , c_2(\tilde)=E_z phi^(z^T\tilde) , and \phi^ is the i -th derivative of \phi . By setting the gradient to 0, it thus follows that the bounded critical points \tilde_* can be expressed as \tilde_* = g_*S^u , where g_* depends on \tilde_* and \phi . Combining this global property with length-direction decoupling, it could thus be proved that this optimization problem converges linearly. First, a variation of
gradient descent In mathematics, gradient descent (also often called steepest descent) is a first-order iterative optimization algorithm for finding a local minimum of a differentiable function. The idea is to take repeated steps in the opposite direction of the ...
with batch normalization, Gradient Descent in Normalized Parameterization (GDNP), is designed for the objective function min_f_(w,\gamma) , such that the direction and length of the weights are updated separately. Denote the stopping criterion of GDNP as h(w_t,\gamma_t)=E_z phi'(z^T\tilde_t)u^Tw_t)-E_z phi''(z^T\tilde_t)u^Tw_t)^2 . Let the step size be s_t=s(w_t,\gamma_t)=-\frac . For each step, if h(w_t,\gamma_t)\ne 0 , then update the direction as w_=w_t-s_t\triangledown_w f(w_t,\gamma_t) . Then update the length according to \gamma_t = Bisection(T_s,f,w_t) , where Bisection() is the classical bisection algorithm, and T_s is the total iterations ran in the bisection step. Denote the total number of iterations as T_d , then the final output of GDNP is \tilde_ = \gamma_\frac . The GDNP algorithm thus slightly modifies the batch normalization step for the ease of mathematical analysis. It can be shown that in GDNP, the partial derivative of f_ against the length component converges to zero at a linear rate, such that (\partial_\gamma f_(w_t,a_t^)^2\le \frac , where a_t^ and b_t^ are the two starting points of the bisection algorithm on the left and on the right, correspondingly. Further, for each iteration, the norm of the gradient of f_ with respect to w converges linearly, such that , , w_t, , _S^2, , \triangledown f_(w_t,g_t), , _^2\le \bigg(1-\frac\bigg)^\Phi^2\gamma_t^2(\rho(w_0)-\rho^*) . Combining these two inequalities, a bound could thus be obtained for the gradient with respect to \tilde_ : , , \triangledown_\tildef(\tilde_), , ^2\le \bigg(1-\frac\bigg)^\Phi^2(\rho(w_0)-\rho^*)+\frac , such that the algorithm is guaranteed to converge linearly. Although the proof stands on the assumption of Gaussian input, it is also shown in experiments that GDNP could accelerate optimization without this constraint.


Neural networks

Consider a
multilayer perceptron A multilayer perceptron (MLP) is a fully connected class of feedforward artificial neural network (ANN). The term MLP is used ambiguously, sometimes loosely to mean ''any'' feedforward ANN, sometimes strictly to refer to networks composed of mul ...
(MLP) with one hidden layer and m hidden units with mapping from input x\in R^d to a scalar output described as F_x(\tilde,\Theta)=\sum_^\theta_i\phi(x^T\tilde^) , where \tilde^ and \theta_i are the input and output weights of unit i correspondingly, and \phi is the activation function and is assumed to be a tanh function. The input and output weights could then be optimized with min_(f_(\tilde,\Theta)=E_ (-yF_x(\tilde,\Theta)) , where l is a loss function, \tilde=\ , and \Theta=\ . Consider fixed \Theta and optimizing only \tilde , it can be shown that the critical points of f_(\tilde) of a particular hidden unit i , \hat^ , all align along one line depending on incoming information into the hidden layer, such that \hat^ = \hat^S^u , where \hat^\in R is a scalar, i =1,...,m . This result could be proved by setting the gradient of f_ to zero and solving the system of equations. Apply the GDNP algorithm to this optimization problem by alternating optimization over the different hidden units. Specifically, for each hidden unit, run GDNP to find the optimal W and \gamma . With the same choice of stopping criterion and stepsize, it follows that , , \triangledown_f(\tilde_t^), , ^2_\le\bigg(1-\frac\bigg)^C(\rho(w_0)-\rho^*)+\frac . Since the parameters of each hidden unit converge linearly, the whole optimization problem has a linear rate of convergence.


References

* Ioffe, Sergey; Szegedy, Christian (2015). "Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift", ICML'15: Proceedings of the 32nd International Conference on International Conference on Machine Learning - Volume 37, July 2015 Pages 448–456 * {{Differentiable computing Artificial intelligence