ArticleslgStudy

computer science

Backpropagation

Backpropagation 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 Backpropagation rather than just read about it. In short: In machine learning, backpropagation is a gradient computation method commonly used for training a neural network in computing parameter updates. It is an efficient application of the chain rule to neural networks.

Backpropagation — main illustration
Backpropagation — illustration

Key takeaways

  • Backpropagation 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 Backpropagation to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Backpropagation from memory before moving on to harder problems.

Reference excerpt

In machine learning, backpropagation is a gradient computation method commonly used for training a neural network in computing parameter updates. It is an efficient application of the chain rule to neural networks. Backpropagation efficiently computes the gradient of the loss with respect to the network weights for a single input–output example. It does this by propagating derivatives backward, one layer at a time, from the output layer to the input layer, thereby avoiding redundant chain-rule calculations. Strictly speaking, the term backpropagation refers only to an algorithm for efficiently computing the gradient, not how the gradient is used, but the term is often used loosely to refer to the entire learning algorithm. This includes changing model parameters in the negative direction of the gradient, such as by stochastic gradient descent, or as an intermediate step in a more complicated optimizer, such as Adaptive Moment Estimation. Backpropagation had multiple discoveries and partial discoveries, with a tangled history and terminology (see § History). Some other names for the technique include "reverse mode of automatic differentiation" or "reverse accumulation".

Overview Backpropagation computes the gradient in weight space of a feedforward neural network, with respect to a loss function. Denote:

x: input (vector of features) y: target output For classification, output will be a vector of class probabilities (e.g., (0.1,0.7,0.2), and target output is a specific class, encoded by the one-hot/dummy variable (e.g., (0,1,0)). C: loss function or "cost function" For classification, this is usually cross-entropy (XC, log loss), while for regression it is usually squared error loss (SEL). L: the number of layers Wl=(wjkl): the weights between layer l−1 and l, where wjkl is the weight between the k-th node in layer l−1 and the j-th node in layer l fl: activation functions at layer l For classification the last layer is usually the logistic function for binary classification, and softmax (softargmax) for multi-class classification, while for the hidden layers this was traditionally a sigmoid function (logistic function or others) on each node (coordinate), but today is more varied, with rectifier (ramp, ReLU) being common. ajl: activation of the j-th node in layer l. In the derivation of backpropagation, other intermediate quantities are used by introducing them as needed below. Bias terms are not treated specially since they correspond to a weight with a fixed input of 1. For backpropagation the specific loss function and activation functions do not matter as long as they and their derivatives can be evaluated efficiently. Traditional activation functions include sigmoid, tanh, ReLU, Swish, Mish, and many others. The overall network is a combination of function composition and matrix multiplication:

g(x):=fL(WLfL−1(WL−1⋯f1(W1x)⋯)) For a training set there will be a set of input–output pairs, {(xi,yi)}. For each input–output pair (xi,yi) in the training set, the loss of the model on that pair is the cost of the difference between the predicted output g(xi) and the target output yi:

C(yi,g(xi)) Note the distinction: during model evaluation the weights are fixed while the inputs vary (and the target output may be unknown), and the network ends with the output layer (it does not include the loss function). During model training the input–output pair is fixed while the weights vary, and the network ends with the loss function. Backpropagation computes the gradient for a fixed input–output pair (xi,yi), where the weights wjkl can vary. Each individual component of the gradient, ∂C/∂wjkl, can be computed by the chain rule; but doing this separately for each weight is inefficient. Backpropagation efficiently computes the gradient by avoiding duplicate calculations and not computing unnecessary intermediate values, by computing the gradient of each layer – specifically the gradient of the weighted input of each layer, denoted by δl – from back to front. Informally, the key point is that since the only way a weight in Wl affects the loss is through its effect on the next layer, and it does so linearly, δl are the only data you need to compute the gradients of the weights at layer l, and then the gradients of weights of previous layer can be computed by δl−1 and repeated recursively. This avoids inefficiency in two ways. First, it avoids duplication because when computing the gradient at layer l, it is unnecessary to recompute all derivatives on later layers l+1,l+2,… each time. Second, it avoids unnecessary intermediate calculations, because at each stage it directly computes the gradient of the weights with respect to the ultimate output (the loss), rather than unnecessarily computing the derivatives of the values of hidden layers with respect to changes in weights ∂aj′l′/∂wjkl. Backpropagation can be expressed for simple feedforward networks in terms of matrix multiplication, or more generally in terms of the adjoint graph.

Matrix multiplication For the basic case of a feedforward network, where nodes in each layer are connected only to nodes in the immediate next layer (without skipping any layers), and there is a loss function that computes a scalar loss for the final output, backpropagation can be understood simply by matrix multiplication. Essentially, backpropagation evaluates the expression for the derivative of the cost function as a product of derivatives between each layer from right to left – "backwards" – with the gradient of the weights between each layer being a simple modification of the partial products (the "backwards propagated error"). Given an input–output pair (x,y), the loss is:

C(y,fL(WLfL−1(WL−1⋯f2(W2f1(W1x))⋯))) To compute this, one starts with the input x and works forward; denote the weighted input of each hidden layer as zl and the output of hidden layer l as the activation al. For backpropagation, the activation al as well as the derivatives (fl)′ (evaluated at zl) must be cached for use during the backwards pass. The derivative of the loss in terms of the inputs is given by the chain rule; note that each term is a total derivative, evaluated at the value of the network (at each node) on the input x:

dCdaL⋅daLdzL⋅dzLdaL−1⋅daL−1dzL−1⋅dzL−1daL−2⋅…⋅da1dz1⋅∂z1∂x, where daLdzL is a diagonal matrix. These terms are: the derivative of the loss function; the derivatives of the activation functions; and the matrices of weights:

… excerpt ends here. Continue reading the full article.

Illustrations

Backpropagation: Error surface of a linear neuron for a single training case
Error surface of a linear neuron for a single training case
Backpropagation: Diagram of an artificial neural network to illustrate the notation used here
Diagram of an artificial neural network to illustrate the notation used here
Backpropagation: Gradient descent may find a local minimum instead of the global minimum.
Gradient descent may find a local minimum instead of the global minimum.

Worked examples

Example 1 — a first encounter with Backpropagation

Start with the simplest possible case. Write down what Backpropagation 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 Backpropagation 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 Backpropagation 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 Backpropagation

In research
Backpropagation 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 Backpropagation 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
Backpropagation is common in secondary-school and first-year university syllabi. It links to neighbouring topics Artificial neural networks, Machine learning algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Backpropagation 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 “Backpropagation” →

How to study Backpropagation in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Backpropagation 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 Backpropagation out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Backpropagation in simple terms?

In machine learning, backpropagation is a gradient computation method commonly used for training a neural network in computing parameter updates. It is an efficient application of the chain rule to neural networks.

Why does Backpropagation 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 Backpropagation?

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 Backpropagation.

Tags

  • Artificial neural networks
  • Machine learning algorithms

Keep exploring