Deep Learning Lecture 2
- 32Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Why do we process multiple training examples (a batch) at once during forward propagation in a neural network?
32 questions
- 1
Why do we process multiple training examples (a batch) at once during forward propagation in a neural network?
Model answer
To leverage vectorization and GPU parallelism for efficient computation.
Explanation
Processing a batch of m examples simultaneously allows matrix operations to be performed in parallel on hardware like GPUs, significantly speeding up training compared to processing one example at a time.
- 2
Define the cost function J in terms of the loss function L for a batch of m examples.
Model answer
J=m1∑i=1mL(i), where L(i) is the loss for the i-th example.
Explanation
The cost function is the average of the individual loss functions over the entire batch, allowing gradient descent to update parameters based on the overall error.
- 3
Write the binary cross-entropy loss function for a single training example.
Model answer
L(y,y^)=−[ylogy^+(1−y)log(1−y^)]
Explanation
This loss measures the difference between the true label y and predicted probability y^, penalizing confident wrong predictions heavily.
- 4
In backpropagation, why do we compute derivatives starting from the last layer (W3, b3) before earlier layers?
Model answer
Because the chain rule makes the derivative with respect to later layers easier to compute, and earlier layers depend on those results.
Explanation
The relationship between the cost and the weights in the final layer is more direct; computing those first allows reusing intermediate results for earlier layers via the chain rule.
- 5
Explain how the linearity of the derivative simplifies computing the derivative of the cost function J.
Model answer
The derivative of J is the average of the derivatives of the individual loss functions: ∂w∂J=m1∑i=1m∂w∂L(i).
Explanation
Since the derivative is a linear operation, the derivative of the average equals the average of the derivatives, allowing us to compute per-example gradients and then average them.
- 6
Write the forward propagation equation for the output layer (layer 3) in a neural network with sigmoid activation.
Model answer
z[3]=W[3]a[2]+b[3], a[3]=σ(z[3])=y^
Explanation
The linear combination of the previous layer's activations passes through a sigmoid to produce a probability output.
- 7
What is the derivative of the sigmoid activation function σ(z)?
Model answer
σ′(z)=σ(z)(1−σ(z))
Explanation
This derivative is used in backpropagation when computing gradients through a sigmoid layer; it is simple and efficient to compute from the activation value itself.
- 8
In backpropagation, what is the derivative of log(σ(z)) with respect to z?
Model answer
∂z∂log(σ(z))=σ(z)1⋅σ′(z)=1−σ(z)
Explanation
Using the chain rule, the derivative of log and sigmoid combine to a simple expression, 1−σ(z), which appears in the cross-entropy gradient.
- 9
When computing ∂W[3]∂L, why is the term ∂W[3]∂z[3] equal to a[2]⊤?
Model answer
Because z[3]=W[3]a[2]+b[3], the derivative of a scalar with respect to a matrix W[3] (1×2) yields a 1×2 matrix; shape analysis shows it must be a[2]⊤.
Explanation
The derivative of Wa with respect to W is a⊤ to match dimensions: W is (1×2), a is (2×1), so the gradient has shape (1×2).
- 10
Derive ∂W[3]∂L for a single training example using binary cross-entropy loss and sigmoid output.
Model answer
∂W[3]∂L=(y−a[3])a[2]⊤
Explanation
Starting from L=−[yloga[3]+(1−y)log(1−a[3])] with a[3]=σ(W[3]a[2]+b[3]), applying chain rule and simplifying yields this compact result.
- 11
How does the chain rule decompose ∂W[2]∂L in terms of intermediate derivatives?
Model answer
∂W[2]∂L=∂a[3]∂L⋅∂z[3]∂a[3]⋅∂a[2]∂z[3]⋅∂z[2]∂a[2]⋅∂W[2]∂z[2]
Explanation
This decomposition backpropagates the error from the output through the network to the weights of layer 2, reusing derivatives computed for later layers.
- 12
What is the derivative ∂z[3]∂L equal to, based on the derivation for W[3]?
Model answer
∂z[3]∂L=y−a[3]
Explanation
From ∂W[3]∂L=∂z[3]∂La[2]⊤ and the known result, we identify ∂z[3]∂L=y−a[3].
- 13
Why is caching (storing intermediate values) important during forward propagation?
Model answer
To avoid recomputing activations and linear outputs during backpropagation, improving computational efficiency at the cost of memory.
Explanation
Values like a[1],a[2],z[2],W[3] are needed in backprop; caching them saves forward passes during backward computation.
- 14
When computing ∂W[2]∂L via chain rule, which term involves an element-wise product?
Model answer
The derivative of the activation function ∂z[2]∂a[2] is an element-wise product (e.g., a[2](1−a[2]) for sigmoid).
Explanation
Since activation functions are applied element-wise, their derivatives also act element-wise when backpropagating through that layer.
- 15
In a neural network with no activation functions (identity activations), what does the entire network reduce to?
Model answer
A linear regression model, regardless of depth.
Explanation
Without nonlinear activations, successive linear transformations compose into a single linear transformation, making the network equivalent to a linear model.
- 16
List three common activation functions and their output ranges.
Model answer
Sigmoid: (0,1); Tanh: (-1,1); ReLU: [0, ∞)
Explanation
These ranges affect how gradients flow: sigmoid and tanh saturate at extremes, while ReLU does not for positive inputs.
- 17
What is the main disadvantage of the sigmoid activation function?
Model answer
It saturates (gradient near zero) for large positive or negative inputs, causing vanishing gradients.
Explanation
When |z| is large, the sigmoid derivative becomes very small, slowing or stopping learning in early layers.
- 18
Write the derivative of the ReLU activation function.
Model answer
ReLU′(z)={10if z>0if z≤0
Explanation
The derivative is 1 for positive z, allowing gradients to pass through unchanged, and 0 for non-positive z, creating sparsity.
- 19
When would you use a tanh activation in the output layer?
Model answer
When the desired output is between -1 and 1, such as reward values in reinforcement learning.
Explanation
Tanh maps inputs to (-1,1), making it suitable for outputs like normalized rewards or centered data.
- 20
What is a common practice for choosing activation functions across layers in a neural network?
Model answer
Use the same activation function for all hidden layers (e.g., ReLU), and a different one for the output layer based on the task.
Explanation
Empirically, using one activation per layer (e.g., ReLU hidden, sigmoid for binary classification) works well, and mixing within a layer is uncommon.
- 21
Why is random initialization of weights important?
Model answer
To break symmetry; without randomness, neurons in the same layer would learn identical features.
Explanation
If all weights start equally, gradients are the same for each neuron, preventing diversification.
- 22
Describe the vanishing gradient problem in deep neural networks.
Model answer
Gradients become extremely small as they are backpropagated through many layers, making early layers learn very slowly or not at all.
Explanation
When activation derivatives (e.g., sigmoid) are <1, repeated multiplication causes gradients to exponentially shrink with depth.
- 23
Explain the exploding gradient problem.
Model answer
Gradients become excessively large, causing unstable updates and divergence during training.
Explanation
When weight matrices have eigenvalues >1, repeated multiplication in backprop leads to exponentially growing gradients.
- 24
What is the purpose of input normalization?
Model answer
To center the data (subtract mean) and scale to unit variance, which speeds up optimization by making the loss landscape more spherical.
Explanation
Normalization prevents features with large ranges from dominating the gradients, allowing gradient descent to move more directly toward the minimum.
- 25
When normalizing inputs, should you use the mean and variance computed on the training set or the test set for test data?
Model answer
Use the mean and variance computed on the training set.
Explanation
The network was trained on normalized training data; applying the same transformation ensures consistent input distribution across training and test.
- 26
State a common weight initialization for layers with sigmoid activation.
Model answer
Initialize weights from a distribution with variance n[l−1]1, e.g., W[l]∼N(0,n[l−1]1).
Explanation
This keeps the linear outputs z from growing too large, reducing saturation and aiding gradient flow.
- 27
What modification to the initialization variance is often used for ReLU activations?
Model answer
Use variance n[l−1]2 instead of n[l−1]1.
Explanation
Empirically, this helps ReLU networks train better, possibly compensating for the zero gradient on negative side.
- 28
What is the Xavier (Glorot) initialization, and which activation is it typically used for?
Model answer
Initialize weights with variance n[l−1]+n[l]2, often used with tanh activation.
Explanation
It considers both forward and backward passes, balancing the variance of activations and gradients.
- 29
What is the advantage of mini-batch gradient descent over batch gradient descent?
Model answer
It provides a trade-off between vectorization efficiency (using batches) and faster updates (not needing full dataset per iteration).
Explanation
Mini-batch allows leveraging GPU parallelism with moderate batch sizes (e.g., 1000) while making more frequent parameter updates than full-batch.
- 30
How does the cost function graph differ between batch gradient descent and mini-batch gradient descent?
Model answer
Batch gradient descent shows a smooth decreasing curve; mini-batch decreases with noise due to gradient approximation.
Explanation
Mini-batch gradients are estimates based on the batch, so the cost may fluctuate but trends downward faster per computation.
- 31
Describe the intuition behind momentum in gradient descent.
Model answer
Momentum accumulates past gradient updates (velocity) to dampen oscillations in directions of high curvature and accelerate in consistent directions.
Explanation
By averaging gradients over time, momentum reduces zigzagging in steep ravines, leading to faster convergence.
- 32
Write the update equations for momentum gradient descent.
Model answer
v=βv+(1−β)∂w∂J; w=w−αv
Explanation
Velocity v is an exponentially weighted average of past gradients, smoothed by β (commonly 0.9). The weight is then updated by velocity times learning rate.

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