Question bank

Pick an answer to see if you're right — with an explanation.

Deep LearningEasy
What does calling `loss.backward()` do in PyTorch?
aUpdates the model weights
bComputes gradients of the loss with respect to parameters that require grad
cResets all gradients to zero
dRuns the forward pass again
Deep LearningEasy
Which layer type is best suited to capturing local spatial patterns in images?
ann.LSTM
bnn.Embedding
cnn.Conv2d
dnn.LayerNorm
Deep LearningEasy
Why is `optimizer.zero_grad()` called at the start of each training step?
aBecause PyTorch accumulates gradients across backward calls by default
bTo reset the learning rate
cTo re-initialise the weights randomly
dTo free the model from GPU memory
Deep LearningEasy
What does `model.eval()` change?
aIt disables gradient computation entirely
bIt freezes all parameters so they cannot be trained
cIt moves the model to the CPU
dIt switches layers like dropout and batch norm to inference behaviour
Deep LearningMedium
What does this code print?
import torch
x = torch.tensor(3.0, requires_grad=True)
y = x ** 2 + 4 * x
y.backward()
print(x.grad)
atensor(21.)
btensor(10.)
ctensor(6.)
dNone
Deep LearningMedium
What is the output shape?
import torch, torch.nn as nn
conv = nn.Conv2d(3, 16, kernel_size=3, padding=1)
x = torch.randn(8, 3, 64, 64)
print(conv(x).shape)
atorch.Size([8, 16, 64, 64])
btorch.Size([8, 16, 62, 62])
ctorch.Size([8, 3, 64, 64])
dtorch.Size([16, 8, 64, 64])
Deep LearningMedium
What inputs does `nn.CrossEntropyLoss` expect for multi-class classification?
aSoftmax probabilities and one-hot float labels
bSigmoid outputs and float labels
cRaw logits and integer class indices
dLog-probabilities and string labels
Deep LearningMedium
You have 400 labelled images across 4 classes. What is the best first approach?
aTrain a deep CNN from scratch for 200 epochs
bUse an RNN over the pixel rows
cTrain a transformer from scratch
dUse a pretrained backbone, freeze it, and train a new classification head
Deep LearningHard
Why are attention scores divided by the square root of the key dimension?
aTo stop large dot products from pushing softmax into saturated regions with tiny gradients
bTo make attention weights sum to 1
cTo reduce memory usage from quadratic to linear
dTo add positional information to the tokens
Deep LearningHard
What shapes are printed?
import torch, torch.nn as nn
lstm = nn.LSTM(input_size=10, hidden_size=32, num_layers=2, batch_first=True)
x = torch.randn(4, 15, 10)
out, (h, c) = lstm(x)
print(out.shape, h.shape)
a(4, 15, 32) and (4, 2, 32)
b(15, 4, 32) and (2, 4, 32)
c(4, 15, 32) and (2, 4, 32)
d(4, 32) and (2, 32)