Inverse transmission: from local lead count to parameter update

Use a hidden neuron with ReLU to progressively calculate forward values, reverse gradients and update them simultaneously.

System Chapter . StepCollate in 2 Graphics6 self-measurement3 First-hand sources
Start Body Change the variable
Learning objectives and first steps4 objectives • 3 first fixes

Try to do it after reading

  • Organization of forward and inverse calculations with calculation diagrams
  • Disaggregate local guides, accumulated gradients and parameter updates
  • Explains the gradient on the branch
  • Check the gradient using the numeric difference and identify the impregnable boundary

Suggested first

  • vector point
  • Counts and chain rules
  • ReLU Peaceful Path Error

Why don't you try every parameter again and again

A model is assumed to have many parameters. If the entire loss is recalculated for each parameter change and the gradient is estimated by differential, a large number of identical calculations are repeated. Reverse communication divides a calculation into nodes: saves the median amount required for the forward and then combines the local guides along the map in reverse. The automatic differential framework manages the map for us, but the gradient still means “the proximity of the current parameters, how sensitive the loss is to minor changes”.

Reverse dissemination is responsible for calculating the gradient, and the optimizer is responsible for updating the parameters using the gradient. Combine the two into a “model learning automatically”, and it is easy to find out what the problem is when you are wrong.

Start with a hidden neuron

This example is entered in two numbers, and the hidden layer has only one ReLU unit, which is exported as a mark. No regular item, no average number of instalments, loss-specific retention factor 1/2

z=w1x1+w2x2+b,h=max(0,z),y^=vh+c L=12(y^−y)2

Parameter w=(0.1,0.2)、b=0.1、v=0.5、c=0.1I don't know. Give given synthetic input x=(1,2) and objectives y=1, and then move forward:

Nodes Operation Result
z 0.1×1+0.2×2+0.1 0.6
h max(0,0.6) 0.6
Forecast value 0.5×0.6+0.1 0.4
L 0.5×(0.4−1)² 0.18
Mono-hidden neuron forward value and reverse local lead numberTwo input weights sought and obtained z 0:06, ReLU for h 0:06, output 0:4 and loss of 0:18; Reverses the local lead number.x₁=1x₂=2z=0.6ReLUŷ=0.4h=0.6v=0.5Reverse: Error − 0.6 * Hide gradient − 0.3 * Two weights
Original calculation map, only the artist input side. The deviations b and c are clearly retained in the formula and the gradient cannot be omitted from the drawing.

Go back from loss

First request ∂L/∂ŷ=ŷ−y=−0.6I don't know. Output Node is ŷ=vh+c♪ So, so ♪ ∂ŷ/∂v=h=0.6、∂ŷ/∂h=v=0.5、∂ŷ/∂c=1I don't know. Multiply along path:

  • ∂L/∂v=(−0.6)×0.6=−0.36。
  • ∂L/∂c=(−0.6)×1=−0.6。
  • ∂L/∂h=(−0.6)×0.5=−0.3。

Current z>0, ReLU with a local guide of 1, so ∂L/∂z=−0.3I don't know. Then go through the input layer:∂L/∂w₁=−0.3×1=−0.3,∂L/∂w₂=−0.3×2=−0.6,∂L/∂b=−0.3。

The negative sign here describes the direction of local change and does not mean that the parameters themselves must be negative. If the loss falls in the direction of an increase in a parameter, the gradient of that parameter is negative and the gradient drops less that negative number.

Updates the gradient of the same moment

Learning rate 0.1. Update all parameters at the same time. Get w=(0.13,0.26)、b=0.13、v=0.536、c=0.16I don't know. After recalculating,z=0.78、ŷ=0.57808, the loss is approximately 0.08900824。

Can not open message vGet the new one v Returns the hidden gradient of the wheel. That has changed a set of conditions for calculation and is not a decline in the normal gradient as defined in this chapter.

If a parameter is used for two paths, its total gradient is to add to the two paths. The simplest example is f(w)=w·w: Consider both multiply inputs as coming from the same wAnd every contribution is w♪ And the sum is 2wI don't know. Just one side will be half less.

Multiple targets share one layer. How the gradient is combined

Industrial models may allow one to indicate multiple outputs of services, such as forecasts of different time windows. Do not introduce real business labels first, take a shared mark h =0.5, output a =2 h 、 b =− h Targets 1 and 3 respectively. The total loss is the sum of two square errors multiplied by one/two. a just happened to be 1, so the first error was zero; b is -0.5, the second error is 1.5 and the total loss is 1.125.

Sharing the gradient of h is the sum of the two paths contributing: Article 12×(a−1)=0Article II−1×(b+2)=−1.5So the sum is -1.5. If h = wx and x = 2, w = 0.25, then the gradient for w is -3. The entire gradient of the shared expression cannot be kept to zero because one of the objectives has already been formulated; Another goal will still change it.

∂L∂h=2(a−1)−(b+2)=−1.5

Sharing indicates the number of guides to be added to the two targetsThe h output is split by five points above a equal to one and lower output b equal to negative 05, and the two reverse contributions are zero and negative 05 respectively, and are sought at h.h=.5a = 1, Target 1, Contribution 0b = 10.5, Target -2, Contribution -1.5Convergence with a number of guides, which are multiplied by a path
Two target weights are set at 1. If the second rim is given, the gradient along the shared path is also multiplied.

Target weights change the course of actual learning. The loss units, sample numbers and gradient scales of the two missions are different and simplicity does not mean equal impact; The weight of the weight is discussed after the standardization of each of them. What is said here is how the gradient is calculated without giving generic weights that do not need to be verified. Different mission gradients may also offset each other, and the overall small gradient does not mean that each has been learned.

# 标准Python:共享路径数值差分,已执行复算。
def shared_loss(w):
h = 2*w
return .5*(2*h-1)**2 + .5*(-h+2)**2
w, eps = .25, 1e-5
numeric = (shared_loss(w+eps)-shared_loss(w-eps))/(2*eps)
assert abs(shared_loss(w)-1.125)<1e-12
assert abs(numeric+3)<1e-8

What to keep when scaling up from the mark to the volume

If a layer of output is multiple, local guides are described in a comparative description, but training is often less explicit in the construction of complete and comparable volumes, and the calculated vector of the loss to output is multiplied by a local aerometric. (b) The shape is a reliable line of error: the weight gradient should be the same as the weight of the weight shape; The gradient must be accumulated along the respective axes by the number of times used, after the parameters are sought or broadcast.

For example, each sample for a batch was added to the same bias, and the gradient bias was the sum of the corresponding errors in all samples, which were treated on average according to the definition of loss; We can't just take the first one, we can't lose it. mean I'll take it off again. batch size 。 The correct calculation of the maps does not guarantee that labels, time frames and loss definitions are correct, and the mathematical and data protocols are still two checks.

Cross-check with numerical differences

No training framework is used below to directly compare the changes in the loss on both sides of the parameter. The central difference is only a gradient inspection tool and not the training method recommended here.

def loss(theta):
w1, w2, b, v, c = theta
h = max(0.0, w1 + 2.0 * w2 + b)
prediction = v * h + c
return 0.5 * (prediction - 1.0) ** 2
theta = [0.1, 0.2, 0.1, 0.5, 0.1]
epsilon = 1e-5
numerical = []
for index in range(len(theta)):
plus, minus = theta.copy(), theta.copy()
plus[index] += epsilon
minus[index] -= epsilon
numerical.append((loss(plus) - loss(minus)) / (2 * epsilon))
print(numerical) # 约 [-0.3, -0.6, -0.3, -0.36, -0.6]

The length of the steps over the General Assembly allows the approximation to deviate from the local area and is too small to be affected by floating points. And to avoid ReLU z=0 The point is not insignificant, and the central difference cannot be required to be exactly the same as the zero point gradient agreed upon in the frame selection.

If you put it b To turn z into negative, these gradients to hide the feed will become zero, but the output will be biased c It is still possible to update. A zero gradient does not mean that the entire model has reached its best overall level.

Gradient check how to select the error scale

When the limited differential is approximated, both absolute and relative errors can be reported. A gradient close to zero is not suitable for a relative margin only, as the denominator is small; A large gradient is also not appropriate to provide for only one absolute threshold of any kind. The use of a small input with double accuracy and distance from the indispensible point, and repeated examination at several different locations, reduces incidental passage.

Disparities inspections should also be carried out on the basis of mutual independence. If both the solver gradient and the differential loss were to be preprocessed by the same error, they might together provide a consistent result, but they were still not intended to be optimized. Manual benchmarking such as this chapter is desirable before procedures are checked. Multi-output models select clearly guided target metrics, or clearly pass into vectors - the upstream weights in the accompaniment volume; The only answer cannot be "backward for a vector".

How two samples form a batch gradient

Take a separate linear case and keep only the weight of the mark w without bias. The two entries are 1 and 2, the targets are 1 and 0, and the initial w = 0.5. The projections are 0.5 and 1, respectively; Each loss remained at half the error square, so it was 0.125 and 0.5, with an average instalment of 0.3125.

The gradient of the first for w is 0.5-1 x 1 = ~ 0.5, and the second for 1-0 = 2 = 2, with an average gradient of 0.75. The learning rate of 0.1 was updated by w = 0.425 and the average loss for the new batch was 0.26328125. Note that errors in the first sample have increased and that the overall average target has fallen; The reduction in the gradient was optimized by the agreed overall objective, which did not guarantee that each sample would be better at every step.

This also explains why best updates of samples cannot be done separately, and that the parameters are simply averaged as equivalent forms of the general training cycle. The updated position changes and the subsequent gradient changes. The question of whether such an alternative might appear to be viable could only be discussed under clear assumptions and algorithmic definitions. All updates in this chapter are then calculated on the old parameter and the parameters are updated simultaneously.

# 标准Python,已执行;两条样本、无bias。
loss = lambda w: sum(.5*(w*x-y)**2 for x,y in [(1.,1.),(2.,0.)])/2
old, gradient = .5, .75
new = old-.1*gradient
assert abs(loss(old)-.3125)<1e-12
assert abs(loss(new)-.26328125)<1e-12

Check understanding

If v = 0, why hide the gradient may be zero, while v itself can still be updated?

The path to hide the layer to the loss contains a multiplier v and may therefore be cut off; v gradient is the output error multiplied h Just... h And the error is not zero, and it may still receive a non-zero gradient.

Why does the default MSELoss result probably double the result of this chapter?

This chapter defines a single metric error squared by 1/2. The default mean error does not have this factor, and it is possible to average multiple elements. The definition of loss and reduction must be aligned first.

Could the numerical gradient test prove that the training data and assessment protocols are correct?

Can't. It examines the realization of local guides in the given calculation; Label leaks, errors in scoring and inappropriate indicators may still exist.

Sharing h connects two targets, with a single target error of 0, and a total gradient of h of 0?

Not necessarily. The path of another objective in this chapter contributes -1.5 and the overall gradient after convergence remains -1.5.

The same bias is used in four samples, which error to choose for guidance?

All access paths are accumulated, and then the total lost sum or mean is standardized and cannot be selected at random.

By multiplying the second task loss by 0.1, does it affect only the displayed values?

It is also transmitted to the shared layer with a gradient of 0.1, changing the actual update direction and relative impact.

The next step is to read " Finish a training loop " and see when these gradients are saved, when they are cleared and when they are given to the optimist. Further Delineate Readable D2L Calculating Chart Section、Anti-referral instructions for CS231n and Deep Learning Chapter VI I don't know. Source core for 2026-10-29; The number of cases and text is originally created at the site and has been restated without any claim of GPU or framework training.

Change a variable

Update parameters step by step

Synthetic teaching algorithms

1D: L(w) = (w − 2)2, initial w = 0.

Step 0Step 0
Current parameter w
0.0000
Current loss
4.0000

The vertical axis is adjusted to the loss shown. Large steps may exceed the minimum, and the decline in loss is not guaranteed for every learning rate.

Displays the calculation of the default parameters at the moment. The parameters can be changed when JavaScript is turned on.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. Dive into Deep Learning — Forward Propagation, Backward Propagation, and Computational Graphs
  2. CS231n — Backpropagation, Intuitions
  3. Deep Learning — Deep Feedforward Networks

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.