Introduction to Deep Learning and Generative AI · Quiz 1 · Jan 2026
Introduction to Deep Learning and Generative AI · Quiz 1 · Jan 2026
← Course papers · Start practice / exam
Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.
22 / 22 published solutions
What will be the output of the following PyTorch code?
29
43
48
53
**1. Count tensor elements:** x has \(4\times3\times2=24\) elements, y has \(6\times4=24\), and z has 5.
**2. Evaluate the expression:** numel counts entries, independently of their random values. Thus \(24+24-5=43\).
**Answer: B — 43.**
A: **Incorrect:** It does not equal the element-count expression.
B: **Correct:** 24+24−5 equals 43.
C: **Incorrect:** 48 omits the subtraction of z.numel().
D: **Incorrect:** 53 adds the final 5 instead of subtracting it.
Question 3 MCQ · 2.0 marks
Consider the following code snippet:
What will be printed?
torch.Size([5, 1, 3, 1]), torch.Size([5, 3,1])
torch.Size([1, 5, 1, 3, 1]), torch.Size([5, 3,1])
torch.Size([5, 1, 3, 1]), torch.Size([5, 3])
torch.Size([5, 3]), torch.Size([5, 3])
Published solution
**1. Apply squeeze(0):** x has shape (1,5,1,3,1). Removing only the leading size-one axis gives y shape (5,1,3,1).
**2. Apply squeeze():** With no dimension specified, every size-one axis is removed, giving z shape (5,3).
**Answer: C — torch.Size([5,1,3,1]), torch.Size([5,3]).**
A: **Incorrect:** The first shape is right, but the trailing singleton in z is also removed.
B: **Incorrect:** squeeze(0) removes the leading singleton rather than keeping it.
C: **Correct:** Both the targeted and all-singleton removals are correct.
D: **Incorrect:** squeeze(0) does not remove the other singleton axes.
Question 4 MCQ · 2.0 marks
You want to train a linear model using stochastic gradient descent (SGD).
Assume that the loss function and training loop are implemented correctly.
Which of the following model definitions will result in the weights being updated during training?
Published solution
**1. Identify optimizer registration:** In the standard SGD(model.parameters(), …) setup, assigning nn.Parameter objects to a module registers them as trainable parameters.
**2. Compare the definitions:** Model B wraps both W and b in nn.Parameter. Model A creates ordinary tensors with gradient tracking but does not register them; Model C neither registers parameters nor enables their gradients.
**Answer: B — Model B.**
**Convention note:** This assumes the standard optimizer over model.parameters(). Explicitly passing Model A’s tensors to an optimizer would also permit updates.
A: **Incorrect:** requires_grad=True alone does not register an ordinary tensor in model.parameters().
B: **Correct:** nn.Parameter registers both tensors and enables gradients by default.
C: **Incorrect:** The ordinary tensors are unregistered and do not require gradients.
Question 5 MCQ · 2.0 marks
Consider the following training loop:
Which statement best describes the problem in this training loop?
The forward pass is missing
Gradients accumulate across epochs, leading to incorrect updates
The optimizer cannot update parameters without model.eval()
The loss function cannot compute gradients
Published solution
**1. Locate the missing reset:** The loop calls backward() and optimizer.step(), but never clears previous gradients.
**2. Explain the consequence and fix:** PyTorch accumulates into parameter .grad, so successive updates include earlier gradients. Call optimizer.zero_grad() before each new backward pass when accumulation is not intended.
**Answer: B — Gradients accumulate across epochs, leading to incorrect updates.**
A: **Incorrect:** y_pred=model_0(X_train) is the forward pass.
B: **Correct:** Missing zero_grad causes unintended accumulation across epochs.
C: **Incorrect:** eval changes layer behavior and is not required for optimizer updates.
D: **Incorrect:** The shown differentiable loss can produce gradients.
Question 6 MCQ · 2.0 marks
You are given a dataset of 10 × 10 grayscale images. Your goal is to build a 5-class classifier.
You have to adopt one of the following two
p_A > p_B
p_A = p_B
p_A < p_B
Published solution
**1. Count Model A weights:** Flattening gives 100 inputs connected to 5 outputs, with no bias: \(p_A=100(5)=500\).
**2. Count Model B weights:** Each of five 10×10 filters spans the single grayscale channel: \(p_B=5(10)(10)(1)=500\). Therefore the counts are equal.
**Answer: B — \(p_A=p_B=500\).**
A: **Incorrect:** Both counts are 500, so A is not larger.
B: **Correct:** Both architectures use 500 weights without biases.
C: **Incorrect:** Both counts are 500, so A is not smaller.
Question 7 MCQ · 2.0 marks
An image contains 16 channels.
Which of the following code snippets correctly creates a convolution layer for this image?
Published solution
**1. Read the positional arguments:** Conv2d takes in_channels, out_channels and kernel_size in that order. The required first argument is 16.
**2. Select the matching layer:** Conv2d(16,8,3,stride=1,padding=0) accepts 16 input channels and produces 8 output channels.
**Answer: A — nn.Conv2d(16,8,3,stride=1,padding=0).**
A: **Correct:** Its first argument correctly specifies 16 input channels.
B: **Incorrect:** It expects 8 input channels; 16 is its output channel count.
C: **Incorrect:** It expects 8 input channels; 16 is the kernel size.
D: **Incorrect:** It expects 8 input channels; 16 is the stride.
Question 8 MCQ · 2.0 marks
Consider the following pytorch code to preprocess the FashionMNIST dataset.
Which of the following hold true?
The images in train_dataset will be converted to tensors and normalized
before being returned.
The dataset will return normalized images in the range [−1,1] because
FashionMNIST is grayscale.
The transforms are automatically applied to the test split while they are not
applied to train split.
The dataset will return PIL images and not tensors.
Published solution
**1. Inspect the dataset constructor:** Although a transform pipeline is defined, the FashionMNIST call does not pass transform=transform.
**2. Follow dataset access:** With its default transform=None, the dataset returns PIL images and integer labels; the unused pipeline does not automatically run.
**Answer: D — The dataset will return PIL images and not tensors..**
A: **Incorrect:** The defined transformation is never supplied to the dataset.
B: **Incorrect:** No normalization runs, and grayscale alone does not imply a [−1,1] range.
C: **Incorrect:** Transforms are not automatically attached to either split.
D: **Correct:** The image component remains a PIL image when transform is omitted.
Question 9 MCQ · 2.0 marks
An input volume has shape 6x6x2 (height=6, width=6, depth=2 channels). Perform the following
two steps on it.
● Step 1: Apply 2x2 Max Pooling with stride=2
● Step 2: Then, apply 1x1 Convolution with 4 filters.
What is the shape of the final output volume?
3x3x2
3x3x4
6x6x4
3x3x8
Published solution
**1. Pool spatially:** A 2×2 pool with stride 2 maps 6×6×2 to 3×3×2, preserving channel count.
**2. Apply the pointwise convolution:** With stride 1, four 1×1 filters preserve 3×3 and create four output channels, giving 3×3×4.
**Answer: B — 3×3×4.**
A: **Incorrect:** This is the intermediate pooled shape before convolution.
B: **Correct:** Pooling gives 3×3 and the convolution gives 4 output channels.
C: **Incorrect:** Pooling halves both spatial dimensions.
D: **Incorrect:** The four filters produce four channels, not 2×4 channels.
Question 10 MCQ · 2.0 marks
In an Inception module, four parallel paths produce outputs of shapes:
28x28x64, 28x28x128, 28x28x32, and 28x28x32.
After concatenation, what is the output shape?
112×28×128
28×112×256
28×28×256
112×112×256
Published solution
**1. Preserve spatial positions:** All four paths have matching 28×28 grids, so concatenation can occur along the channel axis.
**2. Add channels:** \(64+128+32+32=256\), giving 28×28×256.
**Answer: C — 28×28×256.**
A: **Incorrect:** Depth concatenation does not add heights.
B: **Incorrect:** It does not add widths.
C: **Correct:** The channel counts sum to 256 and the spatial grid is unchanged.
D: **Incorrect:** Neither spatial dimension is multiplied by the branch count.
Question 11 MCQ · 2.0 marks
A CNN produces an output feature map of size 7x7x512, which is followed by Global Average
Pooling (GAP) and then a fully connected layer with 10 output classes.
Which of the following statements is correct?
GAP converts the feature map into a 49 × 512 vector before classification
GAP produces a 512-dimensional vector, resulting in 5120 trainable
parameters in the final layer
GAP produces a 7 × 7 × 1 feature map, followed by a 10-unit fully connected
layer
GAP increases the number of parameters compared to flattening
Published solution
**1. Apply GAP:** Averaging the 49 spatial values separately in each channel gives a 512-dimensional vector.
**2. Count classifier weights:** Ten outputs need \(512\times10=5120\) weights. Flattening would instead feed 49×512 inputs and require 250880 weights.
**Answer: B — B — 512 GAP features and 5,120 classifier weights.**
**Convention note:** B calls 5120 the total trainable parameters, which excludes biases. With the usual ten output biases, the layer has 5130 parameters. The question does not specify bias=False; B is its intended weights-only answer.
A: **Incorrect:** 49×512 describes flattening rather than global averaging.
B: **Correct:** It correctly gives 512 GAP features and 5120 classifier weights, under the intended no-bias count.
C: **Incorrect:** GAP preserves channels and collapses spatial axes, giving 1×1×512.
D: **Incorrect:** GAP greatly reduces the final layer’s input dimension.
Question 12 MCQ · 3.0 marks
Consider the following code snippet:
What will be printed?
torch.Size([3, 3, 4]), torch.Size([3, 3, 4]), 72
torch.Size([3, 3, 4]), torch.Size([3, 4]), 72
torch.Size([9, 4]), torch.Size([9, 4]), 72
torch.Size([3, 3, 4]), torch.Size([3, 3, 4]), 36
Published solution
**1. Stack on a new axis:** Stacking three (3,4) tensors along dim=1 inserts an axis of length 3, giving (3,3,4).
**2. Squeeze:** No axis has length 1, so the shape remains (3,3,4).
**3. Count storage:** There are \(3\times3\times4=36\) float16 elements at 2 bytes each, giving 72 bytes.
**Answer: A — torch.Size([3,3,4]), torch.Size([3,3,4]), 72.**
A: **Correct:** Both shapes and the 72-byte tensor-data count match.
B: **Incorrect:** No dimension of length 1 exists to squeeze away.
C: **Incorrect:** stack inserts an axis; it does not concatenate into a (9,4) tensor.
D: **Incorrect:** 36 is the element count, while float16 requires 72 bytes.
Question 13 MCQ · 3.0 marks
A CNN uses three consecutive 3x3 convolution layers with stride 1 and no pooling.
What is the receptive field of a neuron in the third layer?
3x3
5x5
7x7
9x9
Published solution
**1. Use the receptive-field recurrence:** A stride-one 3×3 convolution adds two positions to each side length: \(r_{l}=r_{l-1}+2\), starting at r0=1.
**2. Apply three layers:** The lengths are 3,5,7, so the final receptive field is 7×7.
**Answer: C — 7×7.**
A: **Incorrect:** This is the receptive field after one layer.
B: **Incorrect:** This is the receptive field after two layers.
C: **Correct:** After three layers the side length is 1+3×2=7.
D: **Incorrect:** 9×9 would require four such layers.
Question 14 MCQ · 3.0 marks
An input feature map of size 32x32 is convolved using SAME padding in the following two
independent cases:
Case I:
● Filter size: 5x5
● Stride: 1
Case II:
● Filter size: 3x3
● Stride: 1
What amount of padding is applied on each side (top, bottom, left, right) in Case I and Case II,
respectively?
Case I: 2 pixels, Case II: 1 pixel
Case I: 1 pixel, Case II: 2 pixels
Case I: 2 pixels, Case II: 0 pixels
Case I: 4 pixels, Case II: 2 pixels
Published solution
**1. Impose equal input and output sizes:** At stride 1, \(n_{out}=n+2p-k+1\). Setting nout=n gives \(p=(k-1)/2\).
**2. Substitute each kernel:** For 5×5, p=2 per side; for 3×3, p=1 per side.
**Answer: A — Case I: 2 pixels per side; Case II: 1 pixel per side.**
A: **Correct:** These per-side paddings preserve 32×32 in the respective cases.
B: **Incorrect:** It reverses the required paddings.
C: **Incorrect:** Zero padding would shrink the 3×3 case to 30×30.
D: **Incorrect:** These are the total paddings across two sides, not the padding on each side.
Question 15 NAT · 2.0 marks
Consider an input image of size 12x12x4. In the convolution layer a single filter of size 12 x 12 is
passed to the image.
Now consider the image is resized to 14x14x4.
How many additional parameters will be added to the convolution layer?
Published solution
**1. Count fixed filter parameters:** One 12×12 filter over four channels has \(12\times12\times4=576\) weights, plus one bias if enabled.
**2. Resize only the input:** Increasing spatial size from 12×12 to 14×14 changes the number of filter placements, not the filter coefficients. Additional parameters: 0.
**Answer: 0.**
Question 16 MSQ · 3.0 marks
A hidden layer in the feed_forward network of a CNN contains 5 neurons labelled A,B,C,D,E.
We apply dropout to this hidden layer to prevent overfitting.
During training the following observations occured -
Epoch 1 - B and E were dropped out
Epoch 2 - A and D were dropped out
Select the false statements :
During epoch 3 of training C will be dropped out
During epoch 4 of training none of the neurons will be dropped out for sure
since all of them have been dropped in one of the previous epochs.
During inference all of A,B,C,D and E have equal chances of being dropped out
During inference none of the neurons will be dropped out.
Published solution
**1. Apply random masking during training:** Standard dropout samples new masks independently of which units were dropped in earlier epochs; it does not schedule every neuron to be dropped in turn.
**2. Apply evaluation behavior:** Standard dropout is disabled during inference, so all neurons are retained. Select the statements that contradict these rules.
**Answer: A, B, C — A, B and C — the intended false statements.**
**Convention note:** C literally says all neurons have “equal chances,” which is also true if all chances are zero. Its intended false claim is that random dropping continues during inference.
A: **Correct:** False, so select it: earlier masks do not force C to be dropped next.
B: **Correct:** False, so select it: earlier masks do not guarantee a later all-retained mask; C has not even been dropped in the observations.
C: **Correct:** False in the intended sense, so select it: dropout does not randomly drop neurons in standard inference.
D: **Incorrect:** True, so do not select it: evaluation disables standard dropout.
Question 17 NAT · 3.0 marks
Consider the following CNN :
Calculate the total number of parameters in the CNN.
Published solution
**1. Count convolution parameters:** Conv1 has \(16(3\times3\times3+1)=448\). Conv2 has \(32(16\times3\times3+1)=4640\). The +1 includes a bias for each output channel.
**2. Count dense parameters:** fc1 has \((32\times8\times8+1)128=262272\). fc2 has \((128+1)10=1290\).
**3. Sum:** \(448+4640+262272+1290=268650\). Max pooling contributes no parameters.
**Answer: 268650.**
Question 18 MCQ · 2.0 marks
Consider the below neural network with **fixed weights** and answer the given subquestions:
Given the input
, what is the output
of the network?
0
1
2
2.5
Published solution
**1. Compute hidden linear scores:** For x=(1,−1), the scores are \(1-(-1)=2\) and \(-0.5(1)+(-1)-0.5=-2\).
**2. Apply ReLU and the output layer:** Hidden activations become (2,0), so \(y=1(2)+0.5(0)+0=2\).
**Answer: C — 2.**
A: **Incorrect:** The first hidden neuron is active.
B: **Incorrect:** The first hidden activation is 2, not 1.
C: **Correct:** The linear output is 2+0=2.
D: **Incorrect:** The second hidden neuron is inactive and contributes zero.
Question 19 NAT · 2.0 marks
Consider the below neural network with **fixed weights** and answer the given subquestions:
Assume the **target value** is
. Using **Mean Squared Error (MSE)** as the loss function,
compute the numerical value of the loss assuming the input
.
Published solution
**1. Forward through the fixed network:** For x=(1,−1), hidden scores (2,−2) become (2,0) after ReLU; the output is \(y_{pred}=2\).
**2. Compute single-sample MSE:** With target 1.5, \(L=(2-1.5)^2=0.25\). No 1/2 factor is specified.
**Answer: 0.25.**
Question 20 MCQ · 3.0 marks
Consider the below neural network with **fixed weights** and answer the given subquestions:
For which of the following conditions on
will the first neuron of the hidden layer
not be activated (
)?
Published solution
**1. Write the first hidden activation:** Its weights are (1,−1) and its bias is zero, hence \(h_0=\max(0,x[0]-x[1])\).
**2. Solve for inactivity:** \(h_0=0\) exactly when \(x[0]-x[1]\le0\), i.e. \(x[0]\le x[1]\).
**Answer: D — \(x[0]\le x[1]\).**
**Convention note:** B and C each describe a sufficient subset; D is the complete necessary-and-sufficient condition intended by this single-choice question.
A: **Incorrect:** A strictly greater first input activates the neuron.
B: **Incorrect:** Equality is sufficient but misses all strictly smaller first inputs.
C: **Incorrect:** Strict inequality misses the zero output at equality.
D: **Correct:** This includes every input at which the ReLU output is zero.
Question 21 MCQ · 2.0 marks
Consider the following fixed neural network implemented in PyTorch.
Loss function used:
Based on the above data, answer the given subquestions.
Given the input:
What is the output
produced by the network?
0.500
0.612
0.648
0.731
Published solution
**1. Compute hidden scores:** For x=(1,0), the hidden linear layer gives (2,−1), so \(h=(\sigma(2),\sigma(-1))\approx(0.880797,0.268941)\).
**2. Compute output:** \[z=h_0-h_1\approx0.611856,\qquad\hat y=\sigma(z)\approx0.648364.\] Rounded to three decimals: 0.648.
**Answer: C — 0.648.**
A: **Incorrect:** Zero output score would be needed for a prediction of 0.5.
B: **Incorrect:** 0.612 is approximately the pre-activation, before the final sigmoid.
C: **Correct:** The final sigmoid gives approximately 0.648.
D: **Incorrect:** This would be sigmoid(1), but the actual output score is about 0.612.
Question 22 MCQ · 2.0 marks
Consider the following fixed neural network implemented in PyTorch.
Loss function used:
Based on the above data, answer the given subquestions.
For the input:
The network output is:
Recall:
What is the gradient of the loss with respect to the **hidden layer activations**
(i.e.
)?
[ 0.334, 0.334]
[ 0.334, -0.334]
[-0.334, 0.334]
[ 0.111, -0.111]
Published solution
**1. Use the supplied output value:** The question explicitly gives prediction 0.334 and target 0. For sigmoid with BCE, \(\partial L/\partial z=\hat y-y=0.334\).
**2. Differentiate with respect to hidden activations:** Since \(z=h_0-h_1\), \[\nabla_hL=0.334(1,-1)=(0.334,-0.334).\] No hidden sigmoid derivative is needed when differentiating with respect to h itself.
**Answer: B — [0.334, −0.334].**
**Convention note:** Recomputing the earlier printed network at x=(0,1) gives 0.351636, rather than the 0.334 stipulated here. Using the stipulated value gives B; using the exact forward pass gives [0.351636,−0.351636], which is not listed.
A: **Incorrect:** The second output weight is negative, so the second gradient is negative.
B: **Correct:** It multiplies the given output error by the output weights (1,−1).
C: **Incorrect:** Both signs are reversed.
D: **Incorrect:** It introduces an extra shrinking factor not needed for a gradient with respect to h.
Question 23 MSQ · 2.0 marks
Consider the following fixed neural network implemented in PyTorch.
Loss function used:
Based on the above data, answer the given subquestions.
Based on the **hidden-layer weights** and the **output-layer weights**, which of the following
statements are **correct**?
Hidden neuron 0 produces larger activations when
.
Hidden neuron 0 produces larger activations when
.
Hidden neuron 1 produces larger activations when
.
If the predicted class is 1, then the hidden neuron 0 is highly activated.
If the predicted class is 0, then the hidden neuron 0 is highly activated.
If the predicted class is 0, then the hidden neuron 1 is highly activated.
Published solution
**1. Compare hidden neurons:** Their pre-activations are \(a_0=2x_1-x_2\) and \(a_1=-x_1+2x_2\). Their difference is \(3(x_1-x_2)\), so sigmoid monotonicity gives \(h_0>h_1\) exactly when x1>x2.
**2. Relate the output to hidden preference:** \(\hat y=\sigma(h_0-h_1)\). With the usual 0.5 decision threshold, class 1 corresponds to h0 being at least as large as h1; class 0 corresponds to h1>h0.
**Answer: A, C, D, F — A, C, D and F.**
**Convention note:** “Larger/highly activated” is interpreted relative to the other hidden neuron. It need not mean an activation close to 1: both can be very small while one is larger. At equal activations the output is exactly 0.5, so its class depends on the tie convention.
A: **Correct:** x1>x2 makes neuron 0 more active than neuron 1.
B: **Incorrect:** It reverses the hidden-neuron comparison.
C: **Correct:** x2>x1 makes neuron 1 more active than neuron 0.
D: **Correct:** Correct in the intended relative sense: class 1 is supported by neuron 0 rather than neuron 1.
E: **Incorrect:** Class 0 corresponds to the other hidden neuron being more active.
F: **Correct:** Correct in the intended relative sense: class 0 is supported by neuron 1.