ArticleslgStudy

computer science

Normalization (machine learning)

Normalization (machine learning) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Normalization (machine learning) rather than just read about it. In short: In machine learning, normalization is a statistical technique with various applications. There are two main forms of normalization, namely data normalization and activation normalization.

Key takeaways

  • Normalization (machine learning) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Normalization (machine learning) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Normalization (machine learning) from memory before moving on to harder problems.

Reference excerpt

In machine learning, normalization is a statistical technique with various applications. There are two main forms of normalization, namely data normalization and activation normalization. Data normalization (or feature scaling) includes methods that rescale input data so that the features have the same range, mean, variance, or other statistical properties. For instance, a popular choice of feature scaling method is min-max normalization, where each feature is transformed to have the same range (typically [0,1] or [−1,1]). This solves the problem of different features having vastly different scales, for example if one feature is measured in kilometers and another in nanometers. Activation normalization, on the other hand, is specific to deep learning, and includes methods that rescale the activation of hidden neurons inside neural networks. Normalization is often used to:

increase the speed of training convergence, reduce sensitivity to variations and feature scales in input data, reduce overfitting, and produce better model generalization to unseen data. Normalization techniques are often theoretically justified as reducing covariance shift, smoothing optimization landscapes, and increasing regularization, though they are mainly justified by empirical success.

Batch normalization

Batch normalization (BatchNorm) operates on the activations of a layer for each mini-batch. Consider a simple feedforward network, defined by chaining together modules: x(0)↦x(1)↦x(2)↦⋯ where each network module can be a affine transform, a nonlinear activation function, a convolution, etc. x(0) is the input vector, x(1) is the output vector from the first module, etc. BatchNorm is a module that can be inserted at any point in the feedforward network. For example, suppose it is inserted just after x(l), then the network would operate accordingly: ⋯↦x(l)↦BN(x(l))↦x(l+1)↦⋯The BatchNorm module does not operate over individual inputs. Instead, it must operate over one batch of inputs at a time. Concretely, suppose we have a batch of inputs x(1)(0),x(2)(0),…,x(B)(0), fed all at once into the network. We would obtain in the middle of the network some vectors:xvector coordinate(layer):x(1)(l),x(2)(l),…,x(B)(l)The BatchNorm module computes the coordinate-wise mean and variance of these vectors:μi(l)=1B∑b=1Bx(b),i(l)(σi(l))2=1B∑b=1B(x(b),i(l)−μi(l))2where i indexes the coordinates of the vectors, and b indexes the elements of the batch. In other words, we are considering the i-th coordinate of each vector in the batch, and computing the mean and variance of these numbers. More transparently, we may writeμvector coordinate i(layer ℓ)=Avg⁡(b,x(batch b),i(l))(σi(l))2=Avg⁡(b,(x(b),i(l)−μi(l))2)It then normalizes each coordinate to have zero mean and unit variance:x̂(b),i(l)=x(b),i(l)−μi(l)(σi(l))2+ϵThe ϵ is a small positive constant such as 10−9 added to the variance for numerical stability, to avoid division by zero. The entire operation is a data whitening transformation of the x(batch b),vector coordinate i(layer ℓ) tensor over the b-index, with the small positive constant ϵ added for numerical stability. We notate it as:x̂(batch b),vector coordinate i(layer ℓ)=Whitenϵ(x(b),i(l)|b)Finally, it applies a affine transformation:y(b),i(l)=γi(ℓ)x̂(b),i(ℓ)+βi(ℓ)Here, γ and β are parameters inside the BatchNorm module. They are learnable parameters, typically trained by gradient descent, while ϵ is a hyperparameter (i.e. not trained) of the BatchNorm module. More succinctly,y(batch b),vector coordinate i(layer ℓ)=γi(ℓ)Whitenϵ(x(b),i(l)|b)+βi(ℓ)More succinctly,

Interpretation γ and β allow the network to learn to undo the normalization, if this is beneficial. BatchNorm can be interpreted as removing the purely affine transformations, so that its layers focus solely on modelling the nonlinear aspects of data, which may be beneficial, as a neural network can always be augmented with a affine transformation layer on top. It is claimed in the original publication that BatchNorm works by reducing internal covariance shift, though the claim has both supporters and detractors.

Special cases The original paper recommended to only use BatchNorms after a affine transform, not after a nonlinear activation. That is, ϕ(BN(Wx+b)), not BN(ϕ(Wx+b)). Also, the bias b does not matter, since it would be canceled by the subsequent mean subtraction, so it is of the form BN(Wx). That is, if a BatchNorm is preceded by a affine transform, then that affine transform's bias term is set to zero.

CNN For convolutional neural networks (CNNs), BatchNorm must preserve the translation-invariance of these models, meaning that it must treat all outputs of the same kernel as if they are different data points within a batch. This is sometimes called Spatial BatchNorm, or BatchNorm2D, or per-channel BatchNorm. Concretely, suppose we have a 2-dimensional convolutional layer defined by:xh,w,c(l)=∑h′,w′,c′Kh′−h,w′−w,c,c′(l)xh′,w′,c′(l−1)+bc(l)where:

xh,w,c(l) is the activation of the neuron at position (h,w) in the c-th channel of the l-th layer. KΔh,Δw,c,c′(l) is a kernel tensor. Each channel c corresponds to a kernel Kh′−h,w′−w,c,c′(l), with indices Δh,Δw,c′. bc(l) is the bias term for the c-th channel of the l-th layer. In order to preserve the translational invariance, BatchNorm treats all outputs from the same kernel in the same batch as more data in a batch. That is, it is applied once per kernel c (equivalently, once per channel c), not per activation xh,w,c(l+1):μc(l)=1BHW∑b=1B∑h=1H∑w=1Wx(b),h,w,c(l)(σc(l))2=1BHW∑b=1B∑h=1H∑w=1W(x(b),h,w,c(l)−μc(l))2where B is the batch size, H is the height of the feature map, and W is the width of the feature map. That is, even though there are only B data points in a batch, all BHW outputs from the kernel in this batch are treated equally. Subsequently, normalization and the affine transform is also done per kernel:x̂(b),h,w,c(l)=x(b),h,w,c(l)−μc(l)(σc(l))2+ϵy(b),h,w,c(l)=γc(ℓ)x̂(b),h,w,c(l)+βc(ℓ)This generalizes to n-dimensional CNN.

The original BatchNorm is a special case of BatchNorm for 0-dimensional CNN.

RNN A multilayered recurrent neural networks (RNN) is similar to a 1-dimensional RNN. Consequently, BatchNorm for 1D CNN applies.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Normalization (machine learning)

Start with the simplest possible case. Write down what Normalization (machine learning) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Normalization (machine learning) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Normalization (machine learning) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Normalization (machine learning)

In research
Normalization (machine learning) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Normalization (machine learning) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Normalization (machine learning) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Deep learning, Machine learning, Neural networks, so understanding it makes those chapters shorter.
In everyday life
Look for Normalization (machine learning) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Normalization (machine learning)” →

How to study Normalization (machine learning) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Normalization (machine learning) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Normalization (machine learning) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Normalization (machine learning) in simple terms?

In machine learning, normalization is a statistical technique with various applications. There are two main forms of normalization, namely data normalization and activation normalization.

Why does Normalization (machine learning) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Normalization (machine learning)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Normalization (machine learning).

Tags

  • Deep learning
  • Machine learning
  • Neural networks
  • Statistical data transformation

Keep exploring