Backpropagation network: Difference between revisions

From testwiki
Jump to navigation Jump to search
imported>Bert Niehaus
 
(No difference)

Latest revision as of 13:16, 4 October 2023

Introduction

Backpropagation can also refer to the way the result of a playout is propagated up the search tree in Monte Carlo tree search.

As a machine-learning algorithm, backpropagation performs a backward pass to adjust a neural network model's parameters, aiming to minimize the mean squared error (MSE).[1][2] In a multi-layered network, backpropagation uses the following steps:

Propagate training data

Propagate training data through the model from input to predicted output by computing the successive hidden layers' outputs and finally the final layer's output (the feedforward step).

Adjust the model weights

Adjust the model weights to reduce the error relative to the weights.

  • The error is typically the squared difference between prediction and target.
  • For each weight, the slope or derivative of the error is found, and the weight adjusted by a negative multiple of this derivative, so as to go downslope toward the minimum-error configuration.
  • This derivative is easy to calculate for final layer weights, and possible to calculate for one layer given the next layer's derivatives. Starting at the end, then, the derivatives are calculated layer by layer toward the beginning -- thus "backpropagation".

Update Weights

Repeatedly update the weights until they converge or the model has undergone enough iterations.

Origine of basic Idea

It is an efficient application of the Leibniz chain rule (1673)[3] to such networks.[4] It is also known as the reverse mode of automatic differentiation or reverse accumulation, due to Seppo Linnainmaa (1970).[5][6][7][8][9][10][11] The term "back-propagating error correction" was introduced in 1962 by Frank Rosenblatt,[12][4] but he did not know how to implement this, even though Henry J. Kelley had a continuous precursor of backpropagation[13] already in 1960 in the context of control theory.[4]

Gradient Descent

Backpropagation computes the gradient of a loss function with respect to the weights of the network for a single input–output example, and does so efficiently, computing the gradient one layer at a time, iterating backward from the last layer to avoid redundant calculations of intermediate terms in the chain rule; this can be derived through dynamic programming.[13][14]Template:Sfn Gradient descent, or variants such as stochastic gradient descent,[15] are commonly used.

Strictly the term backpropagation refers only to the algorithm for computing the gradient, not how the gradient is used; but the term is often used loosely to refer to the entire learning algorithm – including how the gradient is used, such as by stochastic gradient descent.[16] In 1986 David E. Rumelhart et al. published an experimental analysis of the technique.[17] This contributed to the popularization of backpropagation and helped to initiate an active period of research in multilayer perceptrons.

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"Template:Efn
    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 l1 and l, where wjkl is the weight between the k-th node in layer l1 and the j-th node in layer lTemplate:Efn
  • 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, and ReLU. swish[18] mish,[19] and other activation functions have since been proposed as well.

The overall network is a combination of function composition and matrix multiplication:

g(x):=fL(WLfL1(WL1f1(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 previous layer can be computed δl1 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 ajl/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.Template:Efn 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(WLfL1(WL1f2(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:

dCdaLdaLdzLdzLdaL1daL1dzL1dzL1daL2da1dz1z1x,

where daLdzL is a diagonal matrix.

These terms are: the derivative of the loss function;Template:Efn the derivatives of the activation functions;Template:Efn and the matrices of weights:Template:Efn

dCdaL(fL)WL(fL1)WL1(f1)W1.

The gradient is the transpose of the derivative of the output in terms of the input, so the matrices are transposed and the order of multiplication is reversed, but the entries are the same:

xC=(W1)T(f1)(WL1)T(fL1)(WL)T(fL)aLC.

Backpropagation then consists essentially of evaluating this expression from right to left (equivalently, multiplying the previous expression for the derivative from left to right), computing the gradient at each layer on the way; there is an added step, because the gradient of the weights is not just a subexpression: there's an extra multiplication.

Introducing the auxiliary quantity δl for the partial products (multiplying from right to left), interpreted as the "error at level l" and defined as the gradient of the input values at level l:

δl:=(fl)(Wl+1)T(fl+1)(WL1)T(fL1)(WL)T(fL)aLC.

Note that δl is a vector, of length equal to the number of nodes in level l; each component is interpreted as the "cost attributable to (the value of) that node".

The gradient of the weights in layer l is then:

WlC=δl(al1)T.

The factor of al1 is because the weights Wl between level l1 and l affect level l proportionally to the inputs (activations): the inputs are fixed, the weights vary.

The δl can easily be computed recursively, going from right to left, as:

δl1:=(fl1)(Wl)Tδl.

The gradients of the weights can thus be computed using a few matrix multiplications for each level; this is backpropagation.

Compared with naively computing forwards (using the δl for illustration):

δ1=(f1)(W2)T(f2)(WL1)T(fL1)(WL)T(fL)aLCδ2=(f2)(WL1)T(fL1)(WL)T(fL)aLCδL1=(fL1)(WL)T(fL)aLCδL=(fL)aLC,

there are two key differences with backpropagation:

  1. Computing δl1 in terms of δl avoids the obvious duplicate multiplication of layers l and beyond.
  2. Multiplying starting from aLC – propagating the error backwards – means that each step simply multiplies a vector (δl) by the matrices of weights (Wl)T and derivatives of activations (fl1). By contrast, multiplying forwards, starting from the changes at an earlier layer, means that each multiplication multiplies a matrix by a matrix. This is much more expensive, and corresponds to tracking every possible path of a change in one layer l forward to changes in the layer l+2 (for multiplying Wl+1 by Wl+2, with additional multiplications for the derivatives of the activations), which unnecessarily computes the intermediate quantities of how weight changes affect the values of hidden nodes.

Adjoint graph

Template:Expand section For more general graphs, and other advanced variations, backpropagation can be understood in terms of automatic differentiation, where backpropagation is a special case of reverse accumulation (or "reverse mode").[11]

Intuition

Motivation

The goal of any supervised learning algorithm is to find a function that best maps a set of inputs to their correct output. The motivation for backpropagation is to train a multi-layered neural network such that it can learn the appropriate internal representations to allow it to learn any arbitrary mapping of input to output.[20]

Learning as an optimization problem

To understand the mathematical derivation of the backpropagation algorithm, it helps to first develop some intuition about the relationship between the actual output of a neuron and the correct output for a particular training example. Consider a simple neural network with two input units, one output unit and no hidden units, and in which each neuron uses a linear output (unlike most work on neural networks, in which mapping from inputs to outputs is non-linear)Template:Efn that is the weighted sum of its input.

Error creating thumbnail:
A simple neural network with two input units (each with a single input) and one output unit (with two inputs)

Initially, before training, the weights will be set randomly. Then the neuron learns from training examples, which in this case consist of a set of tuples (x1,x2,t) where x1 and x2 are the inputs to the network and Template:Mvar is the correct output (the output the network should produce given those inputs, when it has been trained). The initial network, given x1 and x2, will compute an output Template:Mvar that likely differs from Template:Mvar (given random weights). A loss function L(t,y) is used for measuring the discrepancy between the target output Template:Mvar and the computed output Template:Mvar. For regression analysis problems the squared error can be used as a loss function, for classification the categorical cross-entropy can be used.

As an example consider a regression problem using the square error as a loss:

L(t,y)=(ty)2=E,

where Template:Mvar is the discrepancy or error.

Consider the network on a single training case:

(1,1,0)

. Thus, the input

x1

and

x2

are 1 and 1 respectively and the correct output, Template:Mvar is 0. Now if the relation is plotted between the network's output Template:Mvar on the horizontal axis and the error Template:Mvar on the vertical axis, the result is a parabola. The minimum of the parabola corresponds to the output Template:Mvar which minimizes the error Template:Mvar. For a single training case, the minimum also touches the horizontal axis, which means the error will be zero and the network can produce an output Template:Mvar that exactly matches the target output Template:Mvar. Therefore, the problem of mapping inputs to outputs can be reduced to an optimization problem of finding a function that will produce the minimal error.

File:Error surface of a linear neuron for a single training case.png
Error surface of a linear neuron for a single training case

However, the output of a neuron depends on the weighted sum of all its inputs:

y=x1w1+x2w2,

where w1 and w2 are the weights on the connection from the input units to the output unit. Therefore, the error also depends on the incoming weights to the neuron, which is ultimately what needs to be changed in the network to enable learning.

In this example, upon injecting the training data (1,1,0), the loss function becomes

E=(ty)2=y2=(x1w1+x2w2)2=(w1+w2)2.

Then, the loss function E takes the form of a parabolic cylinder with its base directed along w1=w2. Since all sets of weights that satisfy w1=w2 minimize the loss function, in this case additional constraints are required to converge to a unique solution. Additional constraints could either be generated by setting specific conditions to the weights, or by injecting additional training data.

One commonly used algorithm to find the set of weights that minimizes the error is gradient descent. By backpropagation, the steepest descent direction is calculated of the loss function versus the present synaptic weights. Then, the weights can be modified along the steepest descent direction, and the error is minimized in an efficient way.

Derivation

The gradient descent method involves calculating the derivative of the loss function with respect to the weights of the network. This is normally done using backpropagation. Assuming one output neuron,Template:Efn the squared error function is

E=L(t,y)

where

L is the loss for the output y and target value t,
t is the target output for a training sample, and
y is the actual output of the output neuron.

For each neuron j, its output oj is defined as

oj=φ(netj)=φ(k=1nwkjxk),

where the activation function φ is non-linear and differentiable over the activation region (the ReLU is not differentiable at one point). A historically used activation function is the logistic function:

φ(z)=11+ez

which has a convenient derivative of:

dφdz=φ(z)(1φ(z))

The input netj to a neuron is the weighted sum of outputs ok of previous neurons. If the neuron is in the first layer after the input layer, the ok of the input layer are simply the inputs xk to the network. The number of input units to the neuron is n. The variable wkj denotes the weight between neuron k of the previous layer and neuron j of the current layer.

Finding the derivative of the error

File:ArtificialNeuronModel english.png
Diagram of an artificial neural network to illustrate the notation used here

Calculating the partial derivative of the error with respect to a weight wij is done using the chain rule twice: Template:NumBlk

In the last factor of the right-hand side of the above, only one term in the sum netj depends on wij, so that Template:NumBlk

If the neuron is in the first layer after the input layer, oi is just xi.

The derivative of the output of neuron j with respect to its input is simply the partial derivative of the activation function:

Template:NumBlk

which for the logistic activation function

ojnetj=netjφ(netj)=φ(netj)(1φ(netj))=oj(1oj)

This is the reason why backpropagation requires that the activation function be differentiable. (Nevertheless, the ReLU activation function, which is non-differentiable at 0, has become quite popular, e.g. in AlexNet)

The first factor is straightforward to evaluate if the neuron is in the output layer, because then oj=y and Template:NumBlk

If half of the square error is used as loss function we can rewrite it as

Eoj=Ey=y12(ty)2=yt

However, if j is in an arbitrary inner layer of the network, finding the derivative E with respect to oj is less obvious.

Considering E as a function with the inputs being all neurons L={u,v,,w} receiving input from neuron j,

E(oj)oj=E(netu,netv,,netw)oj

and taking the total derivative with respect to oj, a recursive expression for the derivative is obtained:

Template:NumBlk

Therefore, the derivative with respect to oj can be calculated if all the derivatives with respect to the outputs o of the next layer – the ones closer to the output neuron – are known. [Note, if any of the neurons in set L were not connected to neuron j, they would be independent of wij and the corresponding partial derivative under the summation would vanish to 0.]

Substituting Template:EquationNote, Template:EquationNote Template:EquationNote and Template:EquationNote in Template:EquationNote we obtain:

Ewij=Eojojnetjnetjwij=Eojojnetjoi
Ewij=oiδj

with

δj=Eojojnetj={L(t,oj)ojdφ(netj)dnetjif j is an output neuron,(Lwjδ)dφ(netj)dnetjif j is an inner neuron.

if φ is the logistic function, and the error is the square error:

δj=Eojojnetj={(ojtj)oj(1oj)if j is an output neuron,(Lwjδ)oj(1oj)if j is an inner neuron.

To update the weight wij using gradient descent, one must choose a learning rate, η>0. The change in weight needs to reflect the impact on E of an increase or decrease in wij. If Ewij>0, an increase in wij increases E; conversely, if Ewij<0, an increase in wij decreases E. The new Δwij is added to the old weight, and the product of the learning rate and the gradient, multiplied by 1 guarantees that wij changes in a way that always decreases E. In other words, in the equation immediately below, ηEwij always changes wij in such a way that E is decreased:

Δwij=ηEwij=ηoiδj

Second-order gradient descent

Using a Hessian matrix of second-order derivatives of the error function, the Levenberg–Marquardt algorithm often converges faster than first-order gradient descent, especially when the topology of the error function is complicated.[21][22] It may also find solutions in smaller node counts for which other methods might not converge.[22] The Hessian can be approximated by the Fisher information matrix.[23]

Loss function

Template:Further The loss function is a function that maps values of one or more variables onto a real number intuitively representing some "cost" associated with those values. For backpropagation, the loss function calculates the difference between the network output and its expected output, after a training example has propagated through the network.

Assumptions

The mathematical expression of the loss function must fulfill two conditions in order for it to be possibly used in backpropagation.[24] The first is that it can be written as an average E=1nxEx over error functions Ex, for n individual training examples, x. The reason for this assumption is that the backpropagation algorithm calculates the gradient of the error function for a single training example, which needs to be generalized to the overall error function. The second assumption is that it can be written as a function of the outputs from the neural network.

Example loss function

Let y,y be vectors in n.

Select an error function E(y,y) measuring the difference between two outputs. The standard choice is the square of the Euclidean distance between the vectors y and y:E(y,y)=12yy2The error function over n training examples can then be written as an average of losses over individual examples:E=12nx(y(x)y(x))2

Limitations

Gradient descent may find a local minimum instead of the global minimum.
  • Gradient descent with backpropagation is not guaranteed to find the global minimum of the error function, but only a local minimum; also, it has trouble crossing plateaus in the error function landscape. This issue, caused by the non-convexity of error functions in neural networks, was long thought to be a major drawback, but Yann LeCun et al. argue that in many practical problems, it is not.[25]
  • Backpropagation learning does not require normalization of input vectors; however, normalization could improve performance.[26]
  • Backpropagation requires the derivatives of activation functions to be known at network design time.

History

Template:See also

Modern backpropagation is Seppo Linnainmaa's reverse mode of automatic differentiation (1970) for discrete connected networks of nested differentiable functions.[5][6][9][10][7][8] It is an efficient application of the chain rule (derived by Gottfried Wilhelm Leibniz in 1673[3][27]) to such networks.[4] The terminology "back-propagating error correction" was introduced in 1962 by Frank Rosenblatt,[28][4] but he did not know how to implement this, although Henry J. Kelley had a continuous precursor of backpropagation[13] already in 1960 in the context of control theory.[4] The first deep learning multilayer perceptron (MLP) trained by stochastic gradient descent[15] was published in 1967 by Shun'ichi Amari.[29][4] In computer experiments, his five layer MLP with two modifiable layers learned internal representations required to classify non-linearily separable pattern classes.[4] In 1982, Paul Werbos applied backpropagation to MLPs in the way that has become standard.[30][31][4] In 1985, David E. Rumelhart et al. published an experimental analysis of the technique.[17] This contributed to the popularization of backpropagation and helped to initiate an active period of research in multilayer perceptrons.[20][32][33]

Kelley (1960)[13] and Arthur E. Bryson (1961)[14] used principles of dynamic programming to derive the above-mentioned continuous precursor of the method. In 1962, Stuart Dreyfus published a simpler derivation based only on the chain rule.[34][35][36][9][10] In 1973, he adapted parameters of controllers in proportion to error gradients.[37] Unlike Linnainmaa's 1970 method,[5][7] these precursors used "standard Jacobian matrix calculations from one stage to the previous one, neither addressing direct links across several stages nor potential additional efficiency gains due to network sparsity."[4]

In 1985, the method was also described by Parker.[38][39] Yann LeCun proposed an alternative form of backpropagation for neural networks in his PhD thesis in 1987. In 1993, Eric Wan won an international pattern recognition contest through backpropagation.[9][40]

During the 2000s it fell out of favourTemplate:Citation needed, but returned in the 2010s, benefitting from cheap, powerful GPU-based computing systems. This has been especially so in speech recognition, machine vision, natural language processing, and language structure learning research (in which it has been used to explain a variety of phenomena related to first[41] and second language learning.[42]).

Error backpropagation has been suggested to explain human brain ERP components like the N400 and P600.[43]

In 2023, a backpropagation algorithm was implemented on a photonic processor by a team at Stanford University.[44]

See also

Notes

Template:Notelist

References

Template:Reflist

Further reading


Page Information

You can display this page as Wiki2Reveal slides

Wiki2Reveal

The Wiki2Reveal slides were created for the Wikipedia Authors' and the Link for the Wiki2Reveal Slides was created with the link generator.

Wikipedia2Wikiversity

This page was based on the following wikipedia-source page:

  1. Template:Harvnb, "Furthermore, back-propagation is often misunderstood as being specific to multi-layer neural networks, but in principle it can compute derivatives of any function"
  2. Template:Cite arXiv
  3. 3.0 3.1 Template:Cite book
  4. 4.00 4.01 4.02 4.03 4.04 4.05 4.06 4.07 4.08 4.09 Template:Cite arXiv
  5. 5.0 5.1 5.2 Template:Cite thesis
  6. 6.0 6.1 Template:Cite journal
  7. 7.0 7.1 7.2 Template:Cite book
  8. 8.0 8.1 Template:Cite book
  9. 9.0 9.1 9.2 9.3 Template:Cite journal
  10. 10.0 10.1 10.2 Template:Cite journal
  11. 11.0 11.1 Template:Harvtxt, "The back-propagation algorithm described here is only one approach to automatic differentiation. It is a special case of a broader class of techniques called reverse mode accumulation."
  12. Template:Cite book
  13. 13.0 13.1 13.2 13.3 Template:Cite journal
  14. 14.0 14.1 Template:Cite book
  15. 15.0 15.1 Template:Cite journal
  16. Template:Harvnb, "The term back-propagation is often misunderstood as meaning the whole learning algorithm for multilayer neural networks. Backpropagation refers only to the method for computing the gradient, while other algorithms, such as stochastic gradient descent, is used to perform learning using this gradient."
  17. 17.0 17.1 Template:Cite journal
  18. Template:Cite arXiv
  19. Template:Cite arXiv
  20. 20.0 20.1 Template:Cite journal
  21. Template:Cite journal
  22. 22.0 22.1 Template:Cite journal
  23. Template:Cite journal
  24. Template:Harvtxt, "[W]hat assumptions do we need to make about our cost function ... in order that backpropagation can be applied? The first assumption we need is that the cost function can be written as an average ... over cost functions ... for individual training examples ... The second assumption we make about the cost is that it can be written as a function of the outputs from the neural network ..."
  25. Template:Cite journal
  26. Template:Cite book
  27. Template:Cite journal
  28. Template:Cite book
  29. Template:Cite journal
  30. Template:Cite book
  31. Template:Cite book
  32. Template:Cite book
  33. Template:Cite book
  34. Template:Cite journal
  35. Template:Cite journal
  36. Template:Cite web
  37. Template:Cite journal
  38. Template:Cite journal
  39. Template:Cite book
  40. Template:Cite book
  41. Template:Cite journal
  42. Template:Cite journal
  43. Template:Cite journal
  44. Template:Cite web