Question bank
Pick an answer to see if you're right — with an explanation.
All topicsPythonSQL / MySQLData ScienceNumPyPandasMatplotlibMachine LearningDeep LearningArtificial IntelligenceLarge Language ModelsDjangoAPIsGit & GitHubPower BIExcelStatistics
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
Explanation: `backward()` only fills each parameter's `.grad`; the optimizer's `step()` performs the actual update.
Deep LearningEasy
Which layer type is best suited to capturing local spatial patterns in images?
ann.LSTM
bnn.Embedding
cnn.Conv2d
dnn.LayerNorm
Explanation: Convolutions slide shared filters over the image, detecting local patterns like edges anywhere they occur.
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
Explanation: Without zeroing, gradients from previous batches are added to the current ones, giving wrong updates.
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
Explanation: `eval()` changes layer behaviour only; use `torch.no_grad()` separately to stop gradient tracking.
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
Explanation: dy/dx = 2x + 4, which equals 10 at x = 3.
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])
Explanation: Padding 1 with a 3x3 kernel and stride 1 keeps height and width; channels become 16.
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
Explanation: CrossEntropyLoss applies log-softmax internally, so pass raw logits and class indices.
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
Explanation: With little data, reusing pretrained features and training only the head gives strong accuracy and avoids overfitting.
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
Explanation: Dot products grow with dimension; scaling keeps their variance stable so softmax stays trainable. Softmax itself ensures weights sum to 1.
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)
Explanation: `out` holds the top layer's state at every step in batch-first layout, while `h` is always (num_layers, batch, hidden).