Neural Network Gradients
- 47Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Why is calculating gradients more challenging for a neural network with hidden layers than for models such as logistic regression or a linear SVM?
47 questions
- 1
Why is calculating gradients more challenging for a neural network with hidden layers than for models such as logistic regression or a linear SVM?
Model answer
A neural network is a compound function with many weights and nonlinear operations, so it can be difficult to determine how an individual weight affects the final loss. Its gradient expressions are also much more complicated to derive directly.
Explanation
The challenge is tracing the effect of a weight through the network’s intermediate operations to the loss.
- 2
How does a numerical gradient approximate a derivative?
Model answer
It evaluates the change in a function’s output over a small increment, dividing that change by the increment’s size. This approximates the derivative that would be obtained as the increment approaches zero.
Explanation
It uses a finite difference instead of calculating the limiting value in the derivative definition.
- 3
What conditions does the described numerical-gradient approach require of a function?
Model answer
The function must be defined at both the original input and the input after a small increment. The behavior between those points should also be close enough to the line joining their function values for the approximation to be useful.
Explanation
The method does not require a simple analytic expression, but it does rely on the function behaving coherently over the small interval.
- 4
Why is calculating numerical gradients impractical for a large neural network?
Model answer
The method changes each weight individually and runs the entire network to measure the effect. Repeating a full evaluation for every weight becomes extremely slow when a network has many weights.
Explanation
The cost grows with the number of weights because each one requires a separate network evaluation.
- 5
When is deriving gradients analytically a good choice, and what makes it difficult for complex networks?
Model answer
When feasible, an analytic gradient is an efficient, direct expression that can be evaluated readily. For large compound functions, deriving it by hand becomes difficult and error-prone because the algebra is extensive.
Explanation
A small algebraic mistake can affect the gradient calculations throughout the model.
- 6
What common mathematical rule makes it possible to automate analytic gradient calculation through a neural network?
Model answer
The chain rule makes it possible: derivatives of composed functions can be calculated by multiplying the derivatives of their component functions. Because this process is mechanical, it can be carried out systematically rather than by expanding all the algebra by hand.
Explanation
Backpropagation applies the chain rule repeatedly to compute gradients through a network.
- 7
State the chain rule for y=f(u) and u=g(x), and identify where the derivatives are evaluated.
Model answer
The chain rule is dy/dx=(dy/du)(du/dx), or (f(g(x)))′=f′(g(x))g′(x). The derivative of f is evaluated at g(x), while the derivative of g is evaluated at x.
Explanation
The output of the inner function becomes the input at which the outer function’s derivative is evaluated.
- 8
How does the chain rule extend to a composition of three functions, such as f(g(h(x)))?
Model answer
Its derivative is f′(g(h(x)))g′(h(x))h′(x). Each local derivative is evaluated at the input received by its function.
Explanation
The chain rule multiplies the derivatives along the entire sequence of function applications.
- 9
How can a sequence of function applications be represented as a directed computational graph?
Model answer
Nodes represent operations, and directed edges represent the flow of data between them. For example, data x can flow through f and then g, producing g(f(x)).
Explanation
The graph makes the order of operations and the connections between their inputs and outputs explicit.
- 10
How are gradients propagated through a simple graph in which x passes through f and then g?
Model answer
The local gradient at f is f′(x), and at g it is g′(f(x)). Multiplying them gives the overall gradient f′(x)g′(f(x)), with gradients conventionally propagated backward from the output.
Explanation
This graph calculation gives the same result as applying the chain rule symbolically.
- 11
Why does representing gradient propagation as moving backward through a graph not change the derivative product?
Model answer
The local derivatives are multiplied together, and multiplication is commutative, so the product does not depend on the order in which its factors are written. The backward direction is nevertheless useful for organizing the calculation.
Explanation
The direction is a convenient computational convention, not a change to the chain rule.
- 12
What derivative results when x passes through a sine operation followed by an exponential operation?
Model answer
The output is esinx, and its derivative is cos(x)esinx. The sine operation contributes cos(x), and the exponential contributes its output.
Explanation
The local derivative of sine is cosine, and the derivative of the exponential is the exponential evaluated at its input.
- 13
Describe the four operations that form the sigmoid function in the example, and give their successive values for input x.
Model answer
The operations negate the input, exponentiate it, add one, and take the reciprocal: x→−x→e−x→1+e−x→1/(1+e−x). The final value is the sigmoid function.
Explanation
Breaking the function into these operations gives a sequence of local derivatives that can be multiplied by the chain rule.
- 14
What are the local derivatives of the four operations used to construct the sigmoid function?
Model answer
Negation has derivative −1, exponentiation has derivative equal to its output, adding one has derivative 1, and taking the reciprocal of an input u has derivative −1/u2.
Explanation
Each derivative is calculated locally at the input to its corresponding operation.
- 15
Why might one leave the derivative of the constructed sigmoid function as a product of local derivatives rather than simplify it algebraically?
Model answer
For gradient computation, the goal is to obtain the needed gradient, not necessarily a neat symbolic expression. The local derivatives can be multiplied in pairs, which also yields gradients at intermediate stages.
Explanation
Associativity allows the derivative product to be grouped into pairwise calculations without changing its value.
- 16
For a graph that first multiplies inputs x and w and then applies a sigmoid, what are the local gradients of the multiplication output with respect to its two inputs?
Model answer
For the product xw, the gradient with respect to x is w, and the gradient with respect to w is x.
Explanation
Each input’s local derivative is the other input to the multiplication.
- 17
For the output σ(xw), how are the gradients with respect to x and w obtained?
Model answer
They are wσ′(xw) with respect to x and xσ′(xw) with respect to w. Each result multiplies the multiplication node’s local gradient by the sigmoid node’s gradient.
Explanation
The sigmoid gradient is evaluated at the product xw and propagated through the two-input multiplication node.
- 18
Why is it sufficient in a particular forward-and-backward calculation to store numeric gradient values rather than full symbolic gradient expressions?
Model answer
The parameter update needs the gradient’s value for the specific inputs being processed, not its full algebraic expression. Storing numeric values makes propagation simpler while preserving the information needed for the update.
Explanation
Local derivatives can be evaluated at the current inputs and then multiplied as numbers.
- 19
For input x=2, what are the approximate output and gradient of the function that applies sine and then exponential?
Model answer
The output is approximately 2.48, and the gradient is approximately −1.04. This follows from sin(2)≈0.91, esin(2)≈2.48, and cos(2)esin(2).
Explanation
The local derivatives are approximately −0.42 for sine at 2 and 2.48 for the exponential at its input.
- 20
For input x=1.5, what output and overall gradient are obtained from the four-operation sigmoid calculation?
Model answer
The output is approximately 0.82, and the overall gradient is approximately 0.15.
Explanation
The intermediate values are about −1.5, 0.22, and 1.22 before taking the reciprocal; multiplying the local derivatives gives the stated gradient.
- 21
For the sigmoid graph with x=−1.2 and w=0.3, what are the intermediate product and final output?
Model answer
The product is xw=−0.36, and the sigmoid output is approximately 0.41.
Explanation
The two inputs first enter the multiplication node, and its output is the input to the sigmoid node.
- 22
For the same graph with x=−1.2 and w=0.3, what are the approximate gradients with respect to x and w?
Model answer
The gradient with respect to x is approximately 0.07, and the gradient with respect to w is approximately −0.29.
Explanation
Using a sigmoid gradient of about 0.24 at −0.36, the gradients are w(0.24) and x(0.24), respectively.
- 23
In a sequence of operations stored as intermediate outputs, how is the gradient with respect to the input computed?
Model answer
Start from the output and work backward, multiplying the gradient already received from downstream by each operation’s local derivative. Continue until the gradient with respect to the input is reached.
Explanation
Each step needs only the local derivative and the gradient passed back from the next operation.
- 24
What gradients can be obtained while propagating backward through a sequence, in addition to the gradient with respect to the original input?
Model answer
The calculation also provides the gradients of the final output with respect to the intermediate values at each operation along the sequence.
Explanation
Each backward step produces the gradient with respect to the preceding operation’s output.
- 25
What information does an individual computational node need in order to calculate and propagate its gradients?
Model answer
It needs its own inputs and outputs, its local derivative rule, and the downstream gradient it receives. It can use these to calculate gradients with respect to its inputs without knowing the rest of the network.
Explanation
This local information is sufficient because the chain rule combines the node’s derivative with the gradient passed back to it.
- 26
How does a node’s forward communication differ from its backward communication?
Model answer
Forward, it sends its output to downstream nodes without needing to know what those nodes do. Backward, it receives a gradient from downstream and uses it to calculate gradients for its own inputs.
Explanation
A node communicates through its connections while remaining independent of the larger network’s internal details.
- 27
Does a computational graph require a fixed boundary between simple operations and compound functions? Explain.
Model answer
No. Node boundaries can be chosen wherever useful: a compound function can be broken into simple arithmetic operations or treated as one node if its derivative is known.
Explanation
The sigmoid, for example, can be represented either as a sequence of elementary operations or as a single operation with a known derivative.
- 28
How are gradient representations adapted when a node operates on vectors or matrices rather than scalars?
Model answer
Gradients are passed as vectors or matrices of partial derivatives, with the same shape as the data or weights to which they refer. Each partial derivative occupies the position corresponding to its associated element.
Explanation
The same chain-rule approach applies, but the calculation must preserve the elements’ locations and shapes.
- 29
What are the two important kinds of vector operations described for neural-network layers?
Model answer
One is an inner product, used in a fully connected or linear layer; the other is an elementwise operation, often used for an activation function.
Explanation
These cases have different patterns of dependence between input and output elements.
- 30
For a scalar output z equal to the dot product of vectors x and w, what are the gradients with respect to the two vectors?
Model answer
The gradient of z with respect to x is w, and the gradient with respect to w is x.
Explanation
Both gradients are needed: the one with respect to the input propagates upstream, while the one with respect to the weights supports their update.
- 31
In an elementwise vector activation, how is the gradient vector formed?
Model answer
It is formed by applying the scalar derivative at each corresponding input element, producing a vector of the individual derivatives.
Explanation
Each output element depends on its corresponding input element independently in an elementwise operation.
- 32
Why can taking the gradient of a softmax function alone require an entire Jacobian?
Model answer
Softmax is a vector-valued function of vector inputs, and each output element depends on all the input elements. Therefore, the derivatives must account for those cross-element dependencies.
Explanation
The Jacobian records the partial derivatives of every output element with respect to every input element.
- 33
Why can it be useful to bundle softmax with cross-entropy loss as a single layer?
Model answer
Combining them makes many of the otherwise extraneous Jacobian terms disappear, leaving a simpler gradient vector. Bundling them avoids passing the full Jacobian through separate layers.
Explanation
Choosing layer boundaries can reduce unnecessary complexity in gradient calculations.
- 34
What shape should the gradient have when a layer has multiple outputs and its weights form a matrix?
Model answer
The gradient with respect to the weights should be a matrix with the same shape as the weight matrix, so that it provides a derivative for every weight element.
Explanation
Each matrix element has a corresponding partial derivative.
- 35
In batch or mini-batch processing, what are two ways to handle a matrix of data gradients?
Model answer
One can pass the full data-matrix gradient, or take the sum or mean of its gradients and pass a gradient vector instead.
Explanation
The appropriate representation depends on how the layer or computation is organized.
- 36
Why is the mean of batch gradients often preferred to their sum?
Model answer
The mean is described as more stable and makes gradients more comparable across different batch sizes.
Explanation
A sum can vary with the number of examples in a batch, whereas taking the mean reduces that dependence.
- 37
What manages the overall network structure when individual layers are designed to be self-contained?
Model answer
A data structure or class keeps track of the network and manages communication between layers. A function can traverse that structure, or the class can provide methods that do so internally.
Explanation
This manager organizes the network-wide computation while individual layers handle their local operations.
- 38
What are the two passes used to populate intermediate data and gradients throughout a network?
Model answer
They are the forward pass, which propagates data from inputs to output, and the backward pass, which propagates loss gradients from output toward the inputs.
Explanation
Together, the passes calculate the intermediate values and gradients needed for learning.
- 39
In what order must nodes be processed during the forward pass?
Model answer
Nodes are processed in input-dependency order: a node can be called only after all of its inputs have been calculated.
Explanation
This ensures that each operation receives the values it needs from its upstream nodes.
- 40
What happens at the end of the forward pass, and where does the backward pass begin?
Model answer
The final stage of the forward pass calculates the loss. The backward pass begins at that loss and propagates its gradients through the network.
Explanation
The loss provides the starting point for calculating how network values and parameters affect the final objective.
- 41
What does each layer do when it receives a downstream gradient during the backward pass?
Model answer
It combines the received gradient with its own local derivatives to calculate gradients for earlier elements, then propagates those gradients to upstream nodes.
Explanation
This process continues until gradients have been propagated back to the graph’s inputs.
- 42
What is the distinction between backpropagation and optimization?
Model answer
Backpropagation calculates gradients; it is not itself the optimization process. An optimizer uses those gradients to update the network’s weights.
Explanation
The optimizer may use gradient descent or one of its variants to decide how to update parameters.
- 43
How does the training process use gradients to continue learning after a backward pass?
Model answer
An optimization policy updates the weights in all layers according to their individual gradients. The network then repeats a forward pass and a backward pass until a stopping criterion is reached.
Explanation
Gradient calculation and parameter updating are repeated as an iterative training process.
- 44
How do the loss landscapes of simple neural networks without hidden layers compare with those of networks that have hidden layers?
Model answer
A network without hidden layers can represent logistic regression or softmax regression, which have convex losses. Networks with hidden layers are almost always non-convex.
Explanation
The presence of hidden layers generally makes the optimization landscape more complex.
- 45
What optimization risk can arise when training a neural network with a non-convex loss?
Model answer
Optimization may get stuck in a local minimum rather than reaching a global minimum. How serious this risk is depends on the data, network structure, and task.
Explanation
Non-convexity allows local minima, but their practical significance varies across problems.
- 46
What evidence is described about local minima in some deep-learning problems?
Model answer
For some network types and problems commonly addressed by deep learning, there is evidence that local minima do not pose a significant practical problem.
Explanation
The material presents this as evidence for some cases, not as a guarantee for every neural network problem.
- 47
What is meant by a “bad” local minimum in the discussion of neural-network optimization?
Model answer
A bad local minimum is one that is a poor approximation of the true global minimum. In the cited computer-vision case, local minima appear to exist but not to be bad in this sense.
Explanation
The described finding is that those minima are, in some way, not far from the global optimum in quality.

Ask anything
We've read this whole study set, so questions about it get the best answers.