Suppose during Inception modules (GoogLeNet), you apply multiple parallel convolutions (1x1, 3x3, 5x5, max pooling) and concatenate outputs. If input is (H, W, 64) and each path outputs (H, W, 32), what is the output shape?
Output is (H, W, 32) because all paths must converge to a single scale via averaging or selection
Output is (H, W, 64) because the module processes input channels and outputs the same number (conservation of information)
Output is (4*H*W*32) = (H, W) × 4096 in flattened form, as Inception modules require spatial flattening
Output is (H, W, 128) because 4 paths (1x1, 3x3, 5x5, max pool) each produce (H, W, 32), concatenated: 4*32=128 channels.
Answer: D. Output is (H, W, 128) because 4 paths (1x1, 3x3, 5x5, max pool) each produce (H, W, 32), concatenated: 4*32=128 channels.
ExplanationIn an Inception module, the four parallel branches (1x1 convolution, 3x3 convolution, 5x5 convolution, and 3x3 max pooling, each using padding to preserve spatial size) all output feature maps with the same height and width as the input, H and W. The branches are combined not by summing or averaging but by concatenating along the channel axis. Since each of the four branches produces 32 channels, concatenation gives 32 + 32 + 32 + 32 = 128 channels, while the spatial dimensions stay unchanged at H and W. This produces a final output shape of (H, W, 128), reflecting how Inception modules grow channel depth by stacking multi-scale feature maps side by side rather than by altering the spatial resolution.
Question 22 · Loss Functions · hard
Suppose during Cross-Entropy loss for multi-class classification: L = -sum_i y_i * log(p_i), where y is one-hot and p is softmax output. If p = [0.7, 0.2, 0.1] and y = [1, 0, 0] (correct class is 0), what is the loss?
Loss = -log(0.7) ≈ 0.357. Only the term for the true class (i=0) contributes: y_0*log(p_0) = 1*log(0.7). Other terms: y_1*log(p_1) + y_2*log(p_2) = 0 + 0 = 0 (one-hot zeros them). The loss penalizes low confidence: lower p_0 (e.g., 0.5) gives higher loss (~0.693). This aligns with the goal: maximize correct-class probability during training
Loss = log(0.7) ≈ -0.357, omitting the negation from the formula. Since cross-entropy loss must be non-negative for any probability p ∈ (0,1) (because log(p) < 0 there), a negative result here signals that the required negative sign was dropped
Loss = -(log(0.7) + log(0.2) + log(0.1)) ≈ 4.269, incorrectly summing the log-probabilities over all three classes instead of using only the single true-class term that the one-hot label selects
Loss = 0 because the predicted class (0, with probability 0.7) matches the true label (class 0) — this confuses cross-entropy with an accuracy check; the loss depends on the actual predicted probability, not merely on whether the argmax prediction is correct
Answer: A. Loss = -log(0.7) ≈ 0.357. Only the term for the true class (i=0) contributes: y_0*log(p_0) = 1*log(0.7). Other terms: y_1*log(p_1) + y_2*log(p_2) = 0 + 0 = 0 (one-hot zeros them). The loss penalizes low confidence: lower p_0 (e.g., 0.5) gives higher loss (~0.693). This aligns with the goal: maximize correct-class probability during training
ExplanationFirst, cross-entropy loss L = -sum_i (y_i * log(p_i)). For one-hot label y = [1, 0, 0] and prediction p = [0.7, 0.2, 0.1]: L = -(1*log(0.7) + 0*log(0.2) + 0*log(0.1)) = -log(0.7). Then, common misconceptions: that cross-entropy sums over all classes (one-hot zeros eliminate non-true classes), that negative loss is possible (it's not; log(p) < 0 for p ∈ (0,1), so -log(p) > 0), or that cross-entropy is symmetric (it's not; it penalizes false negatives more than false positives if label quality differs).
Question 23 · Attention Mechanisms · hard
Suppose during Vision Transformers (ViT), the input image is divided into patches (e.g., 16x16 patches). For a 224x224x3 image with patch_size=16, how many patch embeddings are created, and what is their dimension?
Dividing 224² by 16 (not 16²) gives 3136 — this incorrectly uses the patch side length as the divisor instead of the patch area (256).
Treating each of the 224 × 224 = 50,176 pixels as its own patch, ignoring the 16×16 grouping into patches.
14×14 = 196 patches, but each patch is mistakenly compressed into a single-value embedding instead of a 768-dimensional vector.
(224/16)² = 14² = 196 patches, each embedded into a 768-dimensional vector (from a flattened 16×16×3 patch).
Answer: D. (224/16)² = 14² = 196 patches, each embedded into a 768-dimensional vector (from a flattened 16×16×3 patch).
ExplanationA Vision Transformer (Dosovitskiy et al., 2021) divides the image into non-overlapping patches. For a 224x224x3 image with patch_size=16: patches per dimension = 224/16 = 14, so total patches = 14x14 = 196. Each patch is 16x16x3 = 768 pixels, which is flattened and linearly projected into a 768-dimensional embedding vector (matching ViT-Base's hidden size). Common misconceptions: treating ViT as operating on individual pixels (it groups them into patches, which reduces the sequence length from 50,176 pixels to just 196 tokens), or assuming positional embeddings encode raw coordinates (they are learnable vectors added to each patch embedding, similar to BERT's position embeddings).
Question 24 · Optimization Algorithms · hard
In the Adam optimizer, the first-moment estimate is updated as m_t = β1 · m_(t-1) + (1 − β1) · g_t, starting from m_0 = 0. Suppose β1 = 0.9 and the gradient observed at the very first training step is g_1 = 8. What is the bias-corrected estimate m̂_1, and why does Adam bother applying this correction?
No further adjustment is needed beyond m̂_1 = 0.8, because after only one update the moving average already reflects the gradient directly, independent of how m_0 was initialized.
Applying the two-step decay formula gives m̂_1 ≈ 4.21, since the denominator should use 1 − 0.9² = 0.19, so 0.8 divided by 0.19 comes to about 4.21.
The corrected estimate m̂_1 works out to 8: dividing the raw value 0.8 by (1 − 0.9¹) = 0.1 exactly cancels the 90% shrinkage that the zero-initialized m_0 causes at this very first step.
Bias correction shrinks rather than grows the estimate, giving m̂_1 = 0.08 by multiplying the raw value 0.8 by (1 − β1) = 0.1 to offset the moving average overshooting the true gradient.
Answer: C. The corrected estimate m̂_1 works out to 8: dividing the raw value 0.8 by (1 − 0.9¹) = 0.1 exactly cancels the 90% shrinkage that the zero-initialized m_0 causes at this very first step.
ExplanationWith m_0 fixed at zero, the raw exponential moving average m_t starts out biased toward zero, because only the (1 − β1) fraction of the update comes from the new gradient while the rest is inherited from a zero-valued history. At t = 1 this is easy to compute directly: m_1 = 0.9(0) + 0.1(8) = 0.8, even though the only information available is a single gradient of magnitude 8 — so the raw estimate understates the true signal by a factor of 10. Adam's correction divides by (1 − β1^t), which at t = 1 equals 1 − 0.9 = 0.1, exactly undoing that tenfold shrinkage: m̂_1 = 0.8 / 0.1 = 8, matching the single observed gradient exactly. As training proceeds, β1^t decays toward zero so 1 − β1^t approaches 1 and the correction factor fades to essentially no effect — which is why the bias is largest, and the correction most necessary, in the first few steps right after initialization.
Question 25 · Generative Models · hard
In a Variational Autoencoder, the encoder outputs μ and log σ² describing the approximate posterior q(z|x) = N(μ, σ²). To sample the latent variable, VAEs use the reparameterization trick z = μ + σ⊙ε, where ε ~ N(0, I) is drawn independently of the network's parameters, instead of sampling z directly from N(μ, σ²). Why is this reparameterization necessary for training the encoder with backpropagation?
The reparameterization trick moves the randomness into an independent noise term ε ~ N(0,I) so that z = μ + σ⊙ε becomes a deterministic, differentiable function of μ and σ; sampling z directly from N(μ, σ²) instead would make the sampling operation itself non-differentiable, blocking gradient flow back into the encoder.
The trick discretizes the latent space into one-hot categories so that discrete gradients, which are always well-defined, can replace the ill-defined gradients of continuous sampling.
The trick eliminates the KL-divergence term from the ELBO entirely, since σ already accounts for the regularization needed to keep q(z|x) close to the prior.
The trick removes the need to backpropagate through the decoder network, since z = μ + σ⊙ε lets the loss be computed directly from μ and σ without ever evaluating p(x|z).
Answer: A. The reparameterization trick moves the randomness into an independent noise term ε ~ N(0,I) so that z = μ + σ⊙ε becomes a deterministic, differentiable function of μ and σ; sampling z directly from N(μ, σ²) instead would make the sampling operation itself non-differentiable, blocking gradient flow back into the encoder.
ExplanationSampling z ~ N(μ, σ²) directly makes z a random variable whose stochasticity is entangled with the trainable parameters μ and σ, so there is no well-defined ∂z/∂μ or ∂z/∂σ — the sampling step has no gradient a network can backpropagate through. Reparameterizing as z = μ + σ⊙ε, where ε is drawn from a fixed N(0,I) carrying no trainable parameters, isolates all the randomness in ε alone. Given a sampled ε, z becomes a deterministic, differentiable function of μ and σ: ∂z/∂μ = 1 and ∂z/∂σ = ε, so the chain rule applies cleanly and gradients from the reconstruction loss flow back through the encoder exactly as in a standard feedforward layer. The claim about discretizing into one-hot categories confuses this with a different relaxation technique (such as Gumbel-Softmax) that solves a different problem — enabling gradients through categorical sampling, not Gaussian sampling. The claim about eliminating the KL term is false: reparameterization only changes how z is sampled, not the structure of the ELBO, and the KL(q(z|x) || p(z)) term still appears in the loss and still depends on σ staying well-behaved (not collapsing to zero) for its gradient to be meaningful. The claim about bypassing the decoder is also false: the reconstruction term of the ELBO still requires passing the sampled z through the decoder to evaluate p(x|z); reparameterization makes that sampled z differentiable, it does not remove the decoder from the computation graph.
Question 26 · Regularization · hard
A neural network with dense layers of sizes [1024, 512, 256, 128] applies dropout with rate p=0.5 during training. Calculate the expected number of active neurons in the second dense layer during the backward pass?
All 512 neurons will be active during backpropagation because dropout is only applied in the forward pass
Approximately 341 neurons will be active because dropout's effect is assumed to compound across the three hidden layers, so the second layer keeps two-thirds of its neurons rather than half
Only 128 neurons will be active since the size of the final hidden layer caps how many gradients can flow backward through any earlier layer in the network
With dropout rate 0.5, we expect 50% of 512 neurons to be active, so approximately 256 neurons will pass gradients during backpropagation because dropout randomly deactivates half the neurons in expectation, and this holds equally for forward and backward passes
Answer: D. With dropout rate 0.5, we expect 50% of 512 neurons to be active, so approximately 256 neurons will pass gradients during backpropagation because dropout randomly deactivates half the neurons in expectation, and this holds equally for forward and backward passes
ExplanationFirst, dropout with rate p=0.5 randomly sets 50% of activations to zero, both forward and backward. Expected number of active neurons = 512 × (1 - 0.5) = 512 × 0.5 = 256. Then, during backpropagation, the same binary mask from forward pass is applied, so gradients flow through these same 256 connections. The dropout mask is sampled once per training example and reused consistently, therefore gradients only pass through the non-dropped neurons.
Question 27 · Optimization · hard
An Adam optimizer maintains exponential moving averages of gradients (m) and squared gradients (v) with decay rates β₁=0.9 and β₂=0.999. After 1,000 training steps, evaluate the bias-corrected moving average for squared gradients?
There is no bias correction needed after 1000 steps since the moving average has already fully converged to the true second moment by that point
Bias correction applies only to the first-moment estimate m, so v_hat equals v directly without ever being divided by (1 - β₂^t)
The bias correction factor is (1 - β₁^t) = (1 - 0.9^1000) ≈ 1.0, since v_hat is mistakenly corrected using β₁ instead of β₂
The bias-corrected moving average is divided by (1 - β₂^t) = (1 - 0.999^1000) ≈ 0.632, meaning the effective learning rate correction accounts for the first 1000 steps where β₂^t decays from 0.999 to approximately 0.368, leaving 0.632 of the correction factor applied
Answer: D. The bias-corrected moving average is divided by (1 - β₂^t) = (1 - 0.999^1000) ≈ 0.632, meaning the effective learning rate correction accounts for the first 1000 steps where β₂^t decays from 0.999 to approximately 0.368, leaving 0.632 of the correction factor applied
ExplanationAdam maintains bias-corrected estimates m_hat = m / (1 - β₁^t) and v_hat = v / (1 - β₂^t). At t=1000, β₂^1000 = 0.999^1000 = e^(1000×ln(0.999)) ≈ e^(-1.0005) ≈ 0.3677, so 1 - β₂^1000 ≈ 0.6323. This correction matters because early in training v is severely underestimated — at t=1 the divisor is only about 0.001, inflating v_hat nearly a thousandfold — and even by t=1000 the correction factor of roughly 0.632 still meaningfully rescales the adaptive learning rate.
Question 28 · Semantic Segmentation · hard
Analyze semantic segmentation with a U-Net encoder-decoder architecture. If the input image is 256×256 and the encoder downsamples by factor 16, what upsampling strategy minimizes checkerboard artifacts?
Transposed convolution with kernel size 2 and stride 2 applied 4 times sequentially minimizes artifacts because learnable upsampling (transposed conv) is superior to fixed interpolation, and four applications of 2× upsampling equals 16× total (2^4 = 16), allowing the network to learn anti-aliasing patterns since kernel_size=2 with stride=2 avoids the uneven kernel overlap that produces checkerboard patterns
Nearest neighbor upsampling repeated 4 times because it avoids learnable parameters and is computationally efficient, but its fixed pixel-replication pattern lacks any learned smoothing to blend decoder features, so it produces blocky boundaries instead of the refined output transposed convolution learns during training
Bilinear interpolation applied once with factor 16 because one-shot upsampling avoids the compounding cost of four separate layers, but forcing the interpolation kernel to span the entire 16× jump in a single step amplifies blur and aliasing at segment boundaries rather than letting the decoder refine features gradually
Simple cropping and padding operations since U-Net uses skip connections that eliminate upsampling needs, but skip connections only concatenate encoder feature maps at matching spatial resolutions — the decoder must still upsample the bottleneck back to 256×256 before that concatenation can happen
Answer: A. Transposed convolution with kernel size 2 and stride 2 applied 4 times sequentially minimizes artifacts because learnable upsampling (transposed conv) is superior to fixed interpolation, and four applications of 2× upsampling equals 16× total (2^4 = 16), allowing the network to learn anti-aliasing patterns since kernel_size=2 with stride=2 avoids the uneven kernel overlap that produces checkerboard patterns
ExplanationThe encoder downsamples the 256×256 input by a factor of 16, producing a 16×16 bottleneck feature map (256 ÷ 16 = 16). To restore the original resolution, the decoder must upsample by that same factor of 16. Four successive transposed convolutions with kernel size 2 and stride 2 each double the spatial resolution, taking the feature map from 16×16 to 32×32 to 64×64 to 128×128 to 256×256, since 2^4 = 16 matches the required total upsampling factor exactly. Because each transposed convolution layer carries learnable weights, the network adapts its upsampling kernels during training to smooth out the periodic kernel-overlap patterns that cause checkerboard artifacts, unlike fixed interpolation methods whose repetitive, untrained weighting leaves visible periodic artifacts in the output.
Question 29 · Training Dynamics · hard
During training of a deep neural network, the learning rate schedule uses exponential decay: lr_t = lr_0 × decay_rate^(t / decay_steps) where lr_0=0.1, decay_rate=0.96, t=1000 steps, decay_steps=100. Calculate the learning rate at step 1000?
The learning rate at step 1000 is lr_1000 = 0.1 × 0.96^(1000/100) = 0.1 × 0.96^10 ≈ 0.1 × 0.6648 ≈ 0.06648 because the exponent 10 means we apply the decay factor 10 times, and 0.96^10 represents the cumulative decay of the learning rate over 10 decay periods
The learning rate remains 0.1 at step 1000 because decay_rate^(t/decay_steps) is mistaken for a value close to 1, on the assumption that a decay_rate of 0.96 changes the learning rate by only a negligible amount no matter how many decay periods have elapsed
At step 1000, the learning rate is 0.96, because decay_rate is mistaken for the updated learning rate itself, skipping both the exponentiation by t/decay_steps and the multiplication by lr_0 in the schedule formula
The learning rate at step 1000 is 0.1 - 1000/100 = -9.9, which is invalid and requires learning rate reinitialization
Answer: A. The learning rate at step 1000 is lr_1000 = 0.1 × 0.96^(1000/100) = 0.1 × 0.96^10 ≈ 0.1 × 0.6648 ≈ 0.06648 because the exponent 10 means we apply the decay factor 10 times, and 0.96^10 represents the cumulative decay of the learning rate over 10 decay periods
ExplanationLearning rate decay formula: lr_t = lr_0 × decay_rate^(t / decay_steps). At t=1000: lr = 0.1 × 0.96^(1000/100) = 0.1 × 0.96^10. Calculate 0.96^10: ln(0.96^10) = 10 × ln(0.96) = 10 × (-0.04082) = -0.4082, so 0.96^10 = e^(-0.4082) ≈ 0.6648. Therefore lr_1000 ≈ 0.1 × 0.6648 ≈ 0.06648. This exponential decay gradually reduces the learning rate, allowing the model to converge smoothly by taking smaller steps as it approaches optimal weights.
Question 30 · Attention Mechanisms · hard
In a transformer encoder, the embedding dimension d_model = 512 is split across 8 attention heads, so each head computes scaled dot-product attention independently within its own d_k = 64-dimensional subspace. Which statement correctly describes how the eight individual head outputs are combined to form the final multi-head attention output?
The eight 64-dimensional head outputs are concatenated into a single 512-dimensional vector, which is then multiplied by a learned output projection matrix W^O of shape 512×512 to produce the final output.
Each head's 64-dimensional output is zero-padded to 512 dimensions, and the eight padded vectors are then averaged element-wise to produce the final 512-dimensional output.
Summing the eight 64-dimensional head outputs element-wise yields a single 64-dimensional vector, which is then broadcast to fill all 512 output dimensions.
Each attention head already computes its output directly in the full 512-dimensional space, so the eight outputs are simply averaged together without needing any projection matrix.
Answer: A. The eight 64-dimensional head outputs are concatenated into a single 512-dimensional vector, which is then multiplied by a learned output projection matrix W^O of shape 512×512 to produce the final output.
ExplanationWith d_model = 512 and h = 8 heads, each head operates in a d_k = 512 / 8 = 64 dimensional subspace, computing scaled dot-product attention independently using its own 64-dimensional query, key, and value projections. The architecture requires the eight resulting 64-dimensional outputs to be concatenated back into a single 512-dimensional vector (8 x 64 = 512), and this concatenated vector is then passed through a learned output projection matrix W^O of shape 512x512. That projection step matters because concatenation alone only places the heads' outputs side by side in separate blocks — it does not let information learned in one head's subspace interact with another's; multiplying by W^O is what mixes and recombines the independently-learned per-head representations into a single joint 512-dimensional representation. Padding each head's output to 512 dimensions and averaging would throw away the benefit of using separate low-dimensional subspaces in the first place, since averaging blends mostly zeros with each head's signal. Summing the outputs into one 64-dimensional vector and broadcasting it would collapse eight distinct learned representations into one and cannot recover the 512 dimensions needed downstream. The claim that each head already outputs in the full 512-dimensional space confuses the per-head dimension d_k with the model dimension d_model, when by construction d_k = d_model / h, which is exactly 64 here, not 512.
Question 31 · Object Detection · hard
A ground-truth bounding box for an object is (x1, y1, x2, y2) = (50, 50, 150, 150), a 100×100 pixel square. A detector's predicted box for the same object is (60, 60, 160, 160), also 100×100 pixels, shifted diagonally by 10 pixels. Across the full test set, this model scores mAP@IoU=0.5 = 78% but mAP@IoU=0.75 = 30%. After computing this box's IoU with the ground truth, what does it correctly demonstrate about how the two mAP scores are computed?
Computing IoU as intersection-over-union gives 8100⁄11900 ≈ 0.68 for this box: since 0.68 exceeds 0.5, the detection counts as correct for mAP@0.5, but since 0.68 falls short of 0.75, the same detection counts as a miss for mAP@0.75 — showing the 48-point gap comes from imprecise localization, not failure to find the object.
Treating the union as the sum of both box areas (20,000 px²) without removing the overlap gives IoU = 8100⁄20000 ≈ 0.41, which is below 0.5, so this detection would be scored as missed at both thresholds, meaning the low mAP@0.75 reflects the model failing to detect objects at all rather than a localization problem.
Raising the IoU threshold from 0.5 to 0.75 also raises the bar for correct classification, since a detector shown less object context in a tightly cropped region is more likely to confuse the object with visually similar classes, so the 48-point drop mainly reflects misclassification rather than box placement.
Because IoU thresholds are arbitrary cutoffs chosen by evaluation convention, whether this particular box counts as a hit or a miss changes with the threshold in a way that carries no real diagnostic signal, so the gap between mAP@0.5 and mAP@0.75 cannot be attributed to any specific weakness in the model.
Answer: A. Computing IoU as intersection-over-union gives 8100⁄11900 ≈ 0.68 for this box: since 0.68 exceeds 0.5, the detection counts as correct for mAP@0.5, but since 0.68 falls short of 0.75, the same detection counts as a miss for mAP@0.75 — showing the 48-point gap comes from imprecise localization, not failure to find the object.
ExplanationThe ground-truth box (50,50,150,150) and predicted box (60,60,160,160) are both 100×100 squares offset diagonally by 10 pixels, so they overlap in a 90×90 region: overlap in x runs from 60 to 150 (90 px) and overlap in y runs from 60 to 150 (90 px), giving an intersection area of 90×90 = 8100 px². The union is area(GT) + area(pred) − intersection = 10,000 + 10,000 − 8,100 = 11,900 px². Dividing gives IoU = 8100⁄11900 ≈ 0.68. Compared against the two thresholds used in the reported scores, 0.68 clears the 0.5 cutoff (counted as a true positive for mAP@0.5) but falls short of the 0.75 cutoff (counted as a false negative for mAP@0.75). Averaged over many predictions with this kind of moderate positional error, exactly this pattern — objects found but not boxed tightly enough — produces a large drop between mAP@0.5 and mAP@0.75 (78% to 30%, a 48-point gap) without any change in the model's ability to recognize what the object is. A common arithmetic slip is to compute the union by simply adding the two box areas without subtracting the overlap (10,000 + 10,000 = 20,000), which understates IoU (8100⁄20000 ≈ 0.41) and would incorrectly suggest the detection fails even the loose threshold. The IoU metric also has no bearing on class prediction — tightening the localization threshold changes only how precisely a box must match, not how the classifier scores object categories — so a widening mAP gap as the threshold tightens is diagnostic of localization precision, not classification confusion or measurement noise.
Question 32 · Generative Models · hard
A VAE encoder processes an input x and outputs mean μ = 2.0 and log-variance log(σ²) = 0 for the approximate posterior q(z|x). Using the reparameterization trick z = μ + σ·ε, where ε is a value sampled from a standard normal distribution N(0,1), a specific sample gives ε = 1.5. What is the resulting value of z, and why does this reparameterization allow the VAE to be trained by backpropagation?
Since log(σ²) = 0 gives σ² = 1 and thus σ = 1, z = 2.0 + (1)(1.5) = 3.5; the reparameterization is essential because directly sampling z from N(μ, σ²) makes z a stochastic node with no gradient defined with respect to μ and σ, so backpropagation cannot flow through the sampling step, whereas expressing z as a deterministic function of μ, σ, and an externally-sampled noise term ε isolates the randomness in ε and lets gradients flow through μ and σ during training.
Because log(σ²) = 0 directly gives σ = 0, z equals μ alone at 2.0 regardless of ε; reparameterization matters only because it reduces the variance of the gradient estimator during Monte Carlo sampling, not because the original sampling step blocks backpropagation.
Treating log(σ²) = 0 as σ² = 0 gives z = 2.0 + (0)(1.5) = 2.0; reparameterization is required because it is the only way to obtain a closed-form expression for the KL divergence term between q(z|x) and the prior p(z), which would otherwise be intractable to compute.
Substituting the given values as z = μ·ε + σ produces z = (2.0)(1.5) + 1 = 4.0; reparameterization is necessary so that the decoder can be trained without ever needing to sample from the prior distribution p(z) at any stage, including during generation.
Answer: A. Since log(σ²) = 0 gives σ² = 1 and thus σ = 1, z = 2.0 + (1)(1.5) = 3.5; the reparameterization is essential because directly sampling z from N(μ, σ²) makes z a stochastic node with no gradient defined with respect to μ and σ, so backpropagation cannot flow through the sampling step, whereas expressing z as a deterministic function of μ, σ, and an externally-sampled noise term ε isolates the randomness in ε and lets gradients flow through μ and σ during training.
Explanationlog(σ²) = 0 means σ² = e^0 = 1, so σ = 1. Applying the reparameterization formula z = μ + σ·ε with μ = 2.0, σ = 1, and ε = 1.5 gives z = 2.0 + (1)(1.5) = 3.5. Sampling z directly from N(μ, σ²) treats the sampling operation as a stochastic node in the computation graph; standard backpropagation cannot compute ∂z/∂μ or ∂z/∂σ through a random sampling step, since gradients are not defined through the act of drawing a random sample. The reparameterization trick rewrites z as a deterministic, differentiable function of μ and σ, with all randomness pushed into an independently sampled ε ~ N(0,1) that does not depend on the network's parameters. This lets gradients of the loss flow through μ and σ via ordinary chain-rule backpropagation, which is what makes end-to-end training of the VAE's encoder possible. Note that the closed-form KL divergence between two Gaussians is a separate mathematical fact unrelated to reparameterization, and sampling from the prior p(z) is still required at generation time even though reparameterization is not used there.
Question 33 · Efficient Neural Networks · hard
A CNN layer applies a standard 3×3 convolution to an input with 16 channels, producing an output with 32 channels. An engineer replaces it with a depthwise separable convolution: a 3×3 depthwise stage (one filter per input channel, no cross-channel mixing) followed by a 1×1 pointwise stage that maps the 16 channels to 32 output channels. What is the total parameter count of the depthwise separable version, and by what factor does it reduce the standard convolution's parameter count?
Computing each stage separately: the depthwise step uses 16×1×3×3 = 144 parameters and the pointwise step uses 16×32×1×1 = 512 parameters, giving a total of 656 parameters versus 16×32×3×3 = 4,608 for the standard convolution — a reduction of about 7.0×.
Only the depthwise step matters here: it uses 16×3×3 = 144 parameters, and since the pointwise step is treated as contributing no additional weights, this represents a reduction of about 32× from the standard convolution's 4,608 parameters.
The channel-mixing step alone sets the parameter count: 16×32×1×1 = 512 parameters, treating the spatial filtering step as contributing no learnable weights, for a reduction of about 9.0× from the standard convolution's 4,608 parameters.
Adding rather than multiplying within each stage gives 16×32 + 3×3 = 521 total parameters, which would be a reduction of about 8.8× from the standard convolution's 4,608 parameters.
Answer: A. Computing each stage separately: the depthwise step uses 16×1×3×3 = 144 parameters and the pointwise step uses 16×32×1×1 = 512 parameters, giving a total of 656 parameters versus 16×32×3×3 = 4,608 for the standard convolution — a reduction of about 7.0×.
ExplanationA standard 3×3 convolution over 16 input channels producing 32 output channels needs one filter per output channel, each spanning all 16 input channels: 16×32×3×3 = 4,608 parameters. Depthwise separable convolution factors this into two independent stages. The depthwise stage applies a single 3×3 filter to each input channel independently, with no mixing across channels, costing 16×1×3×3 = 144 parameters. The pointwise stage then mixes those 16 channels into 32 output channels using a 1×1 convolution, costing 16×32×1×1 = 512 parameters. Together the two stages total 144 + 512 = 656 parameters. Dividing the standard convolution's cost by this total, 4,608 / 656 ≈ 7.0, shows the depthwise separable version needs about seven times fewer parameters. The savings come from decoupling spatial filtering, handled cheaply by the depthwise stage since each channel gets only 9 weights, from channel mixing, handled cheaply by the pointwise stage since it has no spatial extent — a standard convolution instead pays the full 3×3 spatial cost for every one of the 32×16 output-input channel pairs at once. This factorization is the core idea behind MobileNet-style architectures, which keep accuracy nearly unchanged while cutting compute and parameters for deployment on resource-constrained devices.
Question 34 · Attention Mechanisms · hard
A transformer's attention layer uses query and key vectors of dimension d_k = 64, where every component of q and k is drawn independently from a standard normal distribution (mean 0, variance 1). The unscaled dot product q·k is therefore a sum of 64 independent products q_i·k_i, each with mean 0 and variance 1. Given this, what is the standard deviation of the unscaled q·k, and why does dividing every attention score by √d_k before the softmax matter for training stability?
The dot product's standard deviation equals √64 = 8, so unscaled logits routinely swing across a wide range (roughly ±24 at three standard deviations); fed into softmax, this saturates the output into a near one-hot distribution, and since the softmax gradient scales as p_i(1−p_i), gradients collapse toward zero for the dominant and suppressed logits alike — dividing by √64 = 8 restores a standard deviation of 1, keeping softmax in its high-gradient regime.
Summing 64 independent zero-mean, unit-variance products drives the total toward zero by the law of large numbers, giving q·k a standard deviation of roughly 1/8; dividing by √d_k therefore amplifies this near-vanishing signal back up to a range softmax can meaningfully discriminate between keys.
Because variance adds directly across independent terms without a square root, q·k itself has a standard deviation of 64; the √d_k divisor exists to prevent the softmax denominator from overflowing standard floating-point range, not to influence how gradients propagate.
The standard deviation of q·k is √64 = 8, but the √d_k divisor is required only so the resulting attention-weighted output matches the dimensionality of the value vectors V for the following matmul; without it the Q@K^T @ V multiplication would be shape-incompatible.
Answer: A. The dot product's standard deviation equals √64 = 8, so unscaled logits routinely swing across a wide range (roughly ±24 at three standard deviations); fed into softmax, this saturates the output into a near one-hot distribution, and since the softmax gradient scales as p_i(1−p_i), gradients collapse toward zero for the dominant and suppressed logits alike — dividing by √64 = 8 restores a standard deviation of 1, keeping softmax in its high-gradient regime.
ExplanationEach term q_i·k_i is an independent product of two zero-mean, unit-variance variables, so Var(q_i·k_i) = E[q_i²]E[k_i²] − (E[q_i]E[k_i])² = 1×1 − 0 = 1. Summing d_k = 64 independent such terms gives Var(q·k) = 64, so the standard deviation of the unscaled dot product is √64 = 8 — not 1/8 (that would require the sum to behave like an average, which the law of large numbers does not apply to here since nothing is being divided by 64) and not 64 itself (that confuses variance with standard deviation). A standard deviation of 8 means logits typically differ by tens of units across keys, and because softmax is exponential in its input, even a moderate logit gap gets exponentiated into an almost one-hot distribution. Once softmax saturates this way, its gradient p_i(1−p_i) shrinks toward zero for both the dominant key (p_i≈1) and the suppressed ones (p_i≈0), so almost no gradient reaches Q or K through that attention head. Dividing every logit by √d_k = √64 = 8 rescales the dot product back to unit standard deviation, keeping softmax's input in a range where its output stays soft and its gradient stays informative. This is a numerical-stability fix for the softmax's gradient behavior, not a floating-point overflow safeguard and not a tensor-shape requirement — scaling by a scalar never changes the [b,n,n] shape of Q@K^T, so it cannot be what makes the later multiplication with V shape-compatible.
In a PPO update with clip range ε = 0.2 (so the probability ratio is clipped to [0.8, 1.2]), a timestep has advantage estimate Â_t = 2.0 and probability ratio r_t(θ) = π_θ(a_t|s_t)/π_θ_old(a_t|s_t) = 1.5 — meaning the updated policy has raised this action's probability 50% above what the old policy assigned it. Using L^CLIP_t = min(r_t(θ)·Â_t, clip(r_t(θ), 1-ε, 1+ε)·Â_t), what is the value of the clipped surrogate objective at this timestep, and how does that value restrain the update?
Because clip only engages when the ratio drops below 1−ε, not when it rises above 1+ε, the value stays at 3.0 here since a positive advantage means the unclipped term is always used.
Since clipping is applied to the advantage estimate rather than the ratio, multiplying the unclipped ratio 1.5 by the clipped advantage clip(2.0, 0.8, 1.2) = 1.2 gives 1.8.
The ratio is clipped to 1.2 once it exceeds 1+ε, so the min operator picks the smaller clipped term 1.2×2.0 = 2.4 over the unbounded 1.5×2.0 = 3.0, removing the gradient's incentive to push the ratio further past the trust region.
Capping the ratio at clip(r_t, 1−ε, 1+ε) = 1.2 and reporting that clipped ratio alone, without multiplying by Â_t, yields 1.2 as the surrogate objective's value.
Answer: C. The ratio is clipped to 1.2 once it exceeds 1+ε, so the min operator picks the smaller clipped term 1.2×2.0 = 2.4 over the unbounded 1.5×2.0 = 3.0, removing the gradient's incentive to push the ratio further past the trust region.
ExplanationWith Â_t = 2.0 and r_t(θ) = 1.5, the unclipped term r_t·Â_t = 1.5 × 2.0 = 3.0. But r_t = 1.5 exceeds 1+ε = 1.2, so the clip function bounds it to clip(r_t, 0.8, 1.2) = 1.2, giving a clipped term of 1.2 × 2.0 = 2.4. PPO's min operator selects the smaller of the two candidate values, so L^CLIP_t = min(3.0, 2.4) = 2.4. Because the clipped branch is the active one here, and clip(r_t, 0.8, 1.2) is constant (equal to 1.2) for any r_t beyond 1.2, the objective's gradient with respect to θ is zero in this region — the policy earns no further increase in the objective for continuing to raise this action's probability. That is the mechanism by which PPO caps how far a single update can push the policy away from π_θ_old, even when the advantage strongly favors the action. This is distinct from clipping the advantage itself, which PPO never does, and from stopping at the clipped ratio without folding in the advantage's value, which discards the sign and magnitude information the objective needs.
Question 36 · CNN architecture · hard
Consider a convolutional layer applied to a 32×32×3 RGB input, using Conv2D(filters=32, kernel_size=5×5, stride=2, padding='valid'). What are the output feature map dimensions and the total number of trainable parameters in this Conv2D layer?
This Conv2D layer produces a 14×14×32 output with 2,432 trainable parameters: floor((32-5)/2)+1 = 14 per spatial dimension, and each filter contributes (5×5×3)+1 = 76 weights, so 32×76 = 2,432 total.
Applying same-padding-style rounding to the stride gives a 15×15×32 output with 2,432 parameters, since 13.5 is rounded up instead of using the floor function required for valid padding.
Omitting the bias term per filter yields a 14×14×32 output but only 2,400 parameters, since 5×5×3 = 75 weights per filter times 32 filters excludes the bias contribution.
Treating each input channel as producing its own output map yields a 14×14×96 output with 2,432 parameters, incorrectly multiplying the filter count by the 3 input channels.
Answer: A. This Conv2D layer produces a 14×14×32 output with 2,432 trainable parameters: floor((32-5)/2)+1 = 14 per spatial dimension, and each filter contributes (5×5×3)+1 = 76 weights, so 32×76 = 2,432 total.
ExplanationFor a convolutional layer with padding='valid', the output spatial dimension follows out = floor((input - kernel)/stride) + 1. Here, floor((32-5)/2) + 1 = floor(13.5) + 1 = 13 + 1 = 14, giving a 14×14 spatial output. The channel dimension equals the number of filters, 32, so the output volume is 14×14×32. Each filter's parameter count is (kernel_height × kernel_width × input_channels) + 1 bias = (5×5×3) + 1 = 76. With 32 filters, total trainable parameters = 32 × 76 = 2,432. Rounding the stride division upward instead of taking the floor would incorrectly produce a 15×15 output; dropping the bias term would undercount parameters at 2,400; and multiplying the filter count by the number of input channels conflates how channels are absorbed into each filter's depth with how many output maps are actually produced.
Question 37 · CNN architecture · hard
For Conv2D(filters=128, kernel_size=3, stride=2, padding=1) applied to input (batch=16, 224, 224, 3), use output_size = floor((input_size + 2*padding - kernel_size) / stride + 1) to calculate output shape and total parameters?
Output is (16, 112, 112, 128) with 3,584 parameters: output_size = floor((224 + 2 - 3)/2 + 1) = 112. Each filter: 3*3*3+1=28. Total: 128*28=3,584.
Output is (16, 112, 112, 128) with 4,608 parameters including bias corrections.
Output is (16, 224, 224, 128) with 1,152 parameters, since stride affects only filter count.
Output is (16, 56, 56, 128) with 9,216 parameters, because stride and kernel combine to 4x reduction.
Answer: A. Output is (16, 112, 112, 128) with 3,584 parameters: output_size = floor((224 + 2 - 3)/2 + 1) = 112. Each filter: 3*3*3+1=28. Total: 128*28=3,584.
ExplanationFirst, dimension calculation: output_size = floor((224 + 2*1 - 3)/2 + 1) = floor(223/2 + 1) = floor(112.5) = 112. Parameter count: each of 128 filters has 3*3*3=27 weights + 1 bias = 28 parameters. Then, total = 128*28 = 3,584 parameters. No shared parameters between filters. The full output tensor (16, 112, 112, 128) holds 16*112*112*128 = 25,690,112 activation values per batch, confirming the output shape (16, 112, 112, 128) with 3,584 total parameters.
Question 38 · RNN/LSTM/GRU · hard
Analyze the computational behavior: in an RNN, hidden state h_t = tanh(W_hh*h_t-1 + W_xh*x_t + b_h) processes sequence [x1, x2, ..., xT]. If gradients satisfy |dL/dh_t| = 0.5*|dL/dh_t+1|, what problem emerges after 10 timesteps and why?
Exploding gradient problem: gradient magnitude grows to 1,024 times larger, causing numerical overflow.
No problem occurs because tanh activation bounds gradients to [-1,1].
Mode collapse occurs because recurrent kernel becomes singular.
Answer: A. Vanishing gradient problem: |dL/dh_1| = (0.5)^10 * |dL/dh_11| ~ 0.001 * initial gradient. Early timesteps receive negligible gradient signal, preventing learning of long-term dependencies.
ExplanationGradient propagation: each timestep multiplies gradient by 0.5. After T=10 timesteps: |dL/dh_1| = (0.5)^10 = 1/1024 ~ 0.001. If initial gradient is 1.0, early timesteps get 0.001 gradient. Weight updates W = W - eta*dL/dW become negligible (~eta*0.001 ~ 0). Weights controlling early timesteps receive almost no learning signal. This is the vanishing gradient problem endemic to RNNs with sequences longer than 7-10 timesteps. LSTMs solve this with additive state c_t = f_t * c_t-1 + i_t * tanh(...), enabling gradient flow through forget gate f_t ~ 1.0.
Question 39 · Transfer learning & fine-tuning · hard
A convolutional network pretrained on a source domain (photographs) is being adapted to a target domain (line-art sketches) using Maximum Mean Discrepancy (MMD) feature alignment on a 2-D embedding phi(x). The mean embedding over source images is mu_s = [1, 2] and the mean embedding over target images is mu_t = [4, 6]. Using the squared MMD, MMD^2 = ||mu_s - mu_t||^2 (the sum of squared component-wise differences), what is the value of MMD^2, and why does adding lambda*MMD^2 to the fine-tuning loss improve the source-trained classifier's accuracy on the sketch domain?
Computing directly, MMD^2 = (1-4)^2 + (2-6)^2 = 9 + 16 = 25. Adding lambda*MMD^2 to the fine-tuning loss pulls the target feature mean toward the source feature mean, so sketch images land inside the region of feature space where the classifier head -- trained only on source features -- already produces confident, correct predictions; this reduces the covariate shift between phi(x_s) and phi(x_t) without requiring any labeled target examples.
Summing component differences without squaring gives (1-4) + (2-6) = -7, and since this value is negative it means the source and target feature means are already well aligned, so the MMD penalty term contributes nothing useful to the fine-tuning loss.
Taking the square root first, MMD = sqrt((1-4)^2 + (2-6)^2) = sqrt(25) = 5, and minimizing this quantity works by using the unlabeled target sketches to directly retrain the classifier's decision boundaries from scratch, discarding what was learned from the source photographs.
The squared distance between the means is indeed (1-4)^2 + (2-6)^2 = 25, but minimizing this term operates by repainting the target sketches into photorealistic images at the pixel level before classification, rather than by adjusting the learned feature representation phi.
Answer: A. Computing directly, MMD^2 = (1-4)^2 + (2-6)^2 = 9 + 16 = 25. Adding lambda*MMD^2 to the fine-tuning loss pulls the target feature mean toward the source feature mean, so sketch images land inside the region of feature space where the classifier head -- trained only on source features -- already produces confident, correct predictions; this reduces the covariate shift between phi(x_s) and phi(x_t) without requiring any labeled target examples.
ExplanationSquared MMD with a linear kernel on the mean embeddings is just the squared Euclidean distance between the two mean vectors: MMD^2 = ||mu_s - mu_t||^2 = sum of squared component-wise differences. Here mu_s = [1, 2] and mu_t = [4, 6], so the component differences are (1-4) = -3 and (2-6) = -4. Squaring each and summing: (-3)^2 + (-4)^2 = 9 + 16 = 25, so MMD^2 = 25. Why minimizing this helps: a classifier trained only on source features has decision boundaries that are only reliable in the region of feature space where source features live (centered near mu_s). If target features cluster far away (near mu_t), most target inputs fall outside that reliable region and get misclassified -- this is covariate shift, formally P_s(phi(x)) != P_t(phi(x)). Adding lambda*MMD^2 to the training loss penalizes the encoder phi whenever the source and target mean embeddings drift apart, so gradient descent adjusts phi to pull phi(x_t) back toward phi(x_s). Once the means (and, with a richer kernel, the higher-order moments) are aligned, target sketches are mapped into the same feature neighborhood the classifier was trained on, so the existing decision boundaries now apply correctly to them -- and critically, this alignment uses only unlabeled target data, which is what makes MMD-based domain adaptation useful when target labels are unavailable. The rejected options each break one part of this: one drops the squaring and misreads a negative sum as "already aligned," one reports the unsquared distance (5) and confuses feature alignment with discarding the source classifier and retraining from labels that don't exist in this unsupervised setting, and one gets the arithmetic right but describes pixel-level image repainting (a GAN-style approach) instead of the feature-space alignment that MMD actually performs.
Question 40 · CNN architectures · hard
A toy CNN stack has 3 blocks, and at the current input each block's convolutional sub-network F has local derivative dF/dx = 0.5. For a plain block, y = F(x), and for a residual block, y = F(x) + x. Applying the chain rule across all 3 stacked blocks to compute the total gradient dy₃/dx₀ from the output back to the input, what are the total gradients for the plain stack and the residual stack respectively?
With each residual block contributing a local multiplier of (dF/dx + 1) = 1.5 and each plain block contributing dF/dx = 0.5, chain-rule multiplication across the 3 stacked blocks gives a plain-stack total gradient of 0.125 and a residual-stack total gradient of 3.375
Applying the +1 identity term only once to the product of the three dF/dx factors — rather than once per block — gives a plain-stack total gradient of 0.125 and a residual-stack total gradient of 0.375
Skip connections pin the gradient at exactly 1.0 regardless of network depth, so the residual stack's total gradient is 1.0 while the plain stack's total gradient is 0.125 from multiplying the three dF/dx terms
Combining local derivatives across stacked blocks by addition rather than multiplication gives a plain-stack total gradient of 1.5 (0.5+0.5+0.5) and a residual-stack total gradient of 4.5 (1.5+1.5+1.5)
Answer: A. With each residual block contributing a local multiplier of (dF/dx + 1) = 1.5 and each plain block contributing dF/dx = 0.5, chain-rule multiplication across the 3 stacked blocks gives a plain-stack total gradient of 0.125 and a residual-stack total gradient of 3.375
ExplanationEach residual block computes dy/dx = dF/dx + 1 = 0.5 + 1 = 1.5, while each plain block computes dy/dx = dF/dx = 0.5. The chain rule across 3 stacked blocks multiplies these per-block derivatives together: the plain stack's total gradient is 0.5 × 0.5 × 0.5 = 0.125, and the residual stack's total gradient is 1.5 × 1.5 × 1.5 = 3.375. The key insight is that the skip connection's +1 identity term does not just add a flat offset to the final answer — it raises the per-layer multiplier above 1, so it compounds multiplicatively across depth exactly like the dF/dx term does. This is why deeper residual networks maintain (and here, even amplify) gradient signal at early layers, while a plain stack's gradient shrinks toward zero as depth grows, since it is repeatedly multiplied by a factor below 1.