MauryaHub PYQ Practice

Introduction to Deep Learning and Generative AI · Quiz 2 · Sep 2025

Introduction to Deep Learning and Generative AI · Quiz 2 · Sep 2025

← 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.

24 / 25 published solutions

Question 131 MCQ · 2.0 marks

Source diagram or notation
6406535937458.
stacked_x_dim0: [3, 3], stacked_x_dim1: [4, 4]
6406535937459.
stacked_x_dim0: [4, 3], stacked_x_dim1: [3, 4]
6406535937460.
stacked_x_dim0: [3, 4], stacked_x_dim1: [4, 3]
6406535937461.
stacked_x_dim0: [4, 4], stacked_x_dim1: [3, 3]

Published solution

**1. Understand `torch.stack(tensors, dim)` in PyTorch:** - Given `x = torch.tensor([1, 2, 3, 4])`, the shape of `x` is `(4,)` (a 1D tensor of length 4). - We are stacking a list of **3** such tensors `[x, x, x]`: - **`dim=0` (`stacked_x_dim0 = torch.stack([x, x, x], dim=0)`):** Inserts the new stacking dimension of size 3 at index `0`, resulting in shape **`[3, 4]`**. - **`dim=1` (`stacked_x_dim1 = torch.stack([x, x, x], dim=1)`):** Inserts the new stacking dimension of size 3 at index `1`, resulting in shape **`[4, 3]`**. **Answer: stacked_x_dim0: [3, 4], stacked_x_dim1: [4, 3] (Option C).** A: **Incorrect:** Since `x` has 4 elements, one of the dimensions in both stacked tensors must be 4. B: **Incorrect:** This swaps the shapes for `dim=0` and `dim=1`. C: **Correct:** Stacking three 1D tensors of length 4 along `dim=0` produces shape `[3, 4]`, and along `dim=1` produces shape `[4, 3]`. D: **Incorrect:** Stacking 3 tensors of length 4 never produces `[4, 4]` or `[3, 3]`.

Report a correction for Q131

Question 132 MCQ · 1.0 marks

Source diagram or notation
6406535937462.
It will successfully convert gpu_tensor to a NumPy array on the CPU.
6406535937463.
It will successfully convert gpu_tensor to a NumPy array that also resides on the GPU.
6406535937464.
It will raise a RuntimeError because NumPy arrays cannot directly operate on GPU memory.
6406535937465.
It will create a view of the gpu_tensor on the CPU without copying data.
6406535937466.
The numpy() method is not available for GPU tensors.

Published solution

**1. Behavior of `.numpy()` on a CUDA (GPU) Tensor in PyTorch:** - NumPy arrays are strictly CPU-based data structures and cannot reference or operate on GPU memory directly. - In PyTorch, calling `gpu_tensor.numpy()` directly on a tensor residing on `'cuda'` raises a **`RuntimeError`** (`Can't call numpy() on Tensor that requires grad` or `can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.`). **Answer: It will raise a RuntimeError because NumPy arrays cannot directly operate on GPU memory (Option C).** A: **Incorrect:** PyTorch does not implicitly copy a GPU tensor to CPU when `.numpy()` is called; you must explicitly call `gpu_tensor.cpu().numpy()`. B: **Incorrect:** NumPy arrays only exist in host (CPU) memory, never in GPU memory. C: **Correct:** Calling `.numpy()` on a CUDA tensor raises a `RuntimeError` because NumPy cannot access GPU memory directly. D: **Incorrect:** CPU NumPy views cannot be created directly over GPU device memory. E: **Incorrect:** The `.numpy()` method exists on all `torch.Tensor` objects, but calling it when `device='cuda'` raises a `RuntimeError`.

Report a correction for Q132

Question 133 MCQ · 1.0 marks

The Huber Loss function is introduced as a robust alternative to Mean Squared Error (MSE) and Mean Absolute Error (MAE). What is the primary characteristic of Huber Loss that makes it robust to outliers?
6406535937467.
It always produces a gradient of zero for all errors, preventing large updates.
6406535937468.
It exclusively uses a quadratic penalty, but only for errors exactly at the threshold.
6406535937469.
It transitions from a quadratic loss for small errors to a linear loss for large errors, thereby down-weighting the impact of outliers.
6406535937470.
It entirely ignores errors beyond a certain delta, considering them irrelevant.
6406535937471.
It applies a logarithmic transformation to all error values before computing the loss.

Published solution

**1. Definition and Behavior of Huber Loss:** - For a residual \( e = y - \hat{y} \) and threshold parameter \( \delta > 0 \), the Huber Loss is defined piecewise as: \[ L_\delta(e) = \begin{cases} \frac{1}{2} e^2 & \text{if } |e| \le \delta \\ \delta\left(|e| - \frac{1}{2}\delta\right) & \text{if } |e| > \delta \end{cases} \] - For small errors (\( |e| \le \delta \)), it acts like **quadratic loss (MSE)**, providing smooth, differentiable gradients near zero. - For large errors (\( |e| > \delta \)), it transitions to a **linear loss (like MAE)**, which bounds the gradient magnitude at \( \delta \) and prevents outliers from dominating weight updates. **Answer: It transitions from a quadratic loss for small errors to a linear loss for large errors, thereby down-weighting the impact of outliers (Option C).** A: **Incorrect:** A zero gradient everywhere would prevent the model from learning at all. B: **Incorrect:** Huber loss is quadratic for all errors with magnitude \( |e| \le \delta \) and linear for \( |e| > \delta \). C: **Correct:** Huber loss combines the best of MSE and MAE by being quadratic for small errors (\( |e| \le \delta \)) and linear for large errors (\( |e| > \delta \)), reducing sensitivity to outliers. D: **Incorrect:** Huber loss penalizes large errors linearly rather than ignoring them. E: **Incorrect:** Huber loss is piecewise quadratic/linear, not logarithmic.

Report a correction for Q133

Question 134 NAT · 3.0 marks

A deep learning model contains a stack of three consecutive 3x3 convolutional layers, each with a stride of 1and sufficient padding to preserve spatial dimensions. What is the side length of the **effective receptive field** of a neuron in the third layer with respect to the input?

Published solution

**1. Formula for the Effective Receptive Field of Stacked Convolutional Layers:** - For a stack of convolutional layers each with kernel size \( k = 3 \) and stride \( s = 1 \), the receptive field size \( R_l \) at layer \( l \) (with \( R_0 = 1 \)) satisfies: \[ R_l = R_{l-1} + (k - 1) \] - Let us trace layer by layer: - **After Layer 1:** \( R_1 = 1 + (3 - 1) = 3 \) (a \( 3 \times 3 \) region). - **After Layer 2:** \( R_2 = 3 + (3 - 1) = 5 \) (a \( 5 \times 5 \) region). - **After Layer 3:** \( R_3 = 5 + (3 - 1) = 7 \) (a \( 7 \times 7 \) region). - In general, for \( L \) stacked \( k \times k \) layers with stride 1, the side length of the effective receptive field is \( 1 + L(k - 1) = 1 + 3(3 - 1) = 7 \). **Answer: 7.**

Report a correction for Q134

Question 135 NAT · 2.0 marks

Source diagram or notation

Published solution

**1. Compute the Number of Mini-Batches (Optimizer Steps) per Epoch:** - Dataset size = \( 900 \) images, batch size = \( 32 \), and `drop_last=False`. - Since `drop_last=False`, the final partial batch is kept: \[ \text{Batches per epoch} = \lceil 900 / 32 \rceil = \lceil 28.125 \rceil = 29 \text{ batches} \] (28 full batches of 32 images = 896 images, plus 1 final batch of 4 images). **2. Compute Total Optimizer Updates Over 12 Epochs:** \[ \text{Total updates} = 12 \times 29 = 348 \] **Answer: 348.**

Report a correction for Q135

Question 136 MCQ · 1.0 marks

The Momentum optimizer helps overcome which limitation of vanilla Gradient Descent?
6406535937474.
Slow convergence near the minimum due to large learning rate.
6406535937475.
Zig-zag oscillations in narrow valleys due to gradient directions changing frequently.
6406535937476.
Vanishing gradients caused by activation functions.
6406535937477.
Overfitting due to excessive updates.

Published solution

**1. How Momentum Improves Vanilla Gradient Descent:** - In narrow valleys or ravines (where the loss surface curves much more steeply in one direction than another), vanilla Gradient Descent oscillates back and forth across the steep walls while making slow progress along the valley floor. - **Momentum** maintains an exponentially decaying moving average of past gradients (\( v_t = \gamma v_{t-1} + \eta \nabla L(w_t) \)). Opposite-signed gradients across the steep directions cancel out, while consistent gradients along the valley floor accumulate, damping **zig-zag oscillations** and accelerating convergence. **Answer: Zig-zag oscillations in narrow valleys due to gradient directions changing frequently (Option B).** A: **Incorrect:** A large learning rate causes divergence or overshooting near the minimum, not slow convergence. B: **Correct:** Momentum smooths out oscillating gradients across steep ravines while accelerating progress along consistent directions. C: **Incorrect:** Vanishing gradients from saturating activation functions are addressed by ReLU, batch normalization, or residual connections. D: **Incorrect:** Overfitting is a generalization issue addressed by regularization or dropout, not by the Momentum update rule.

Report a correction for Q136

Question 137 NAT · 4.0 marks

Source diagram or notation

Published solution

**1. Unroll the RMSProp Recurrence \( v_t = \beta v_{t-1} + (1 - \beta)(\nabla w_t)^2 \) from \( t = 0 \) to \( t = 9 \):** - Given \( v_{-1} = 0 \) and \( \beta = 0.9 \): - At \( t = 0 \): \( v_0 = \beta(0) + (1 - \beta)(\nabla w_0)^2 = (1 - \beta)(\nabla w_0)^2 \) - At \( t = 1 \): \( v_1 = \beta(1 - \beta)(\nabla w_0)^2 + (1 - \beta)(\nabla w_1)^2 \) - ... - At \( t = 9 \): each subsequent step multiplies the \( (\nabla w_0)^2 \) term by \( \beta \) across \( t = 1, 2, \dots, 9 \) (9 times): \[ \text{Weight of } (\nabla w_0)^2 \text{ in } v_9 = \beta^9 (1 - \beta) \] **2. Substitute \( \beta = 0.9 \):** \[ (0.9)^9 \times (1 - 0.9) = 0.387420489 \times 0.1 = 0.038742 \approx 0.039 \] **Answer: 0.039.**

Report a correction for Q137

Question 138 MCQ · 2.0 marks

Source diagram or notation
6406535937479.Source diagram or notation
6406535937480.Source diagram or notation
6406535937481.Source diagram or notation
6406535937482.Source diagram or notation

Published solution

**1. Apply the Second Derivative Test for Convexity:** - A twice-differentiable function \( f(w) \) on \( \mathbb{R} \) is convex if and only if \( f''(w) \ge 0 \) (and strictly convex if \( f''(w) > 0 \)) for all \( w \in \mathbb{R} \). - **Function A:** \( A(w) = w^2 - 6w + 10 \) - First derivative: \( A'(w) = 2w - 6 \) - Second derivative: \( A''(w) = 2 > 0 \) for all \( w \in \mathbb{R} \). - **Function B:** \( B(w) = e^w + e^{-w} \) - First derivative: \( B'(w) = e^w - e^{-w} \) - Second derivative: \( B''(w) = e^w + e^{-w} > 0 \) for all \( w \in \mathbb{R} \) (since \( e^x > 0 \) for all real \( x \)). - Therefore, **both functions are convex because their second derivatives are positive for all \( w \in \mathbb{R} \)**. **Answer: Both functions are convex because their second derivatives are positive for all \( w \in \mathbb{R} \) (Option C).** A: **Incorrect:** Function A is convex (\( A''(w) = 2 > 0 \)), and convexity requires \( f''(w) \ge 0 \) for all \( w \in \mathbb{R} \), not just at \( w = 0 \). B: **Incorrect:** \( B''(w) = e^w + e^{-w} \ge 2 > 0 \) for all \( w \in \mathbb{R} \) and approaches \( +\infty \) as \( w \to \infty \), so Function B is also convex. C: **Correct:** \( A''(w) = 2 > 0 \) and \( B''(w) = e^w + e^{-w} > 0 \) for all \( w \in \mathbb{R} \), proving both functions are strictly convex. D: **Incorrect:** Continuity of the first derivative does not guarantee convexity (for example, \( \sin(w) \) has a continuous first derivative but is not convex).

Report a correction for Q138

Question 139 MCQ · 1.0 marks

What happens if the latent space in a GAN has too few dimensions for the task complexity?
6406535937483.
Training becomes faster and results improve.
6406535937484.
The discriminator becomes too powerful.
6406535937485.
The generator memorizes all training images.
6406535937486.
Generated images lack diversity and may look similar

Published solution

**1. Role of Latent Space Dimensionality in a GAN:** - In a Generative Adversarial Network (GAN), the Generator \( G(z) \) maps a random latent vector \( z \in \mathbb{R}^d \) to the data space. - The latent vector \( z \) provides the degrees of freedom (factors of variation) needed to capture the full diversity of the target data distribution. - If the latent space has **too few dimensions** relative to the complexity of the data, the generator cannot represent all variations in the dataset, so the **generated images lack diversity and may look similar**. **Answer: Generated images lack diversity and may look similar (Option D).** A: **Incorrect:** An overly small latent space bottlenecks representational capacity and degrades sample diversity rather than improving results. B: **Incorrect:** Latent space dimensionality is an input property of the generator, not a direct boost to discriminator capacity. C: **Incorrect:** A low-dimensional latent space has *less* capacity, so it cannot memorize all training images. D: **Correct:** Too few latent dimensions restrict the factors of variation the generator can encode, causing generated samples to lack diversity.

Report a correction for Q139

Question 140 MCQ · 2.0 marks

At Nash Equilibrium in a perfectly trained GAN, what is the expected output of the discriminator D(G(z)) for a generated sample?
6406535937487.
0
6406535937488.
0.25
6406535937489.
0.5
6406535937490.
1

Published solution

**1. Discriminator Output at Nash Equilibrium in a GAN:** - For a fixed generator \( G \), the optimal discriminator \( D^*(x) \) is: \[ D^*(x) = \frac{p_{\text{data}}(x)}{p_{\text{data}}(x) + p_g(x)} \] - At the global **Nash Equilibrium**, the generator perfectly matches the real data distribution, meaning \( p_g(x) = p_{\text{data}}(x) \) everywhere. - Substituting \( p_g(x) = p_{\text{data}}(x) \) gives: \[ D^*(x) = \frac{p_{\text{data}}(x)}{p_{\text{data}}(x) + p_{\text{data}}(x)} = \frac{1}{2} = 0.5 \] - Because real and generated samples are indistinguishable, the discriminator outputs **0.5** for every sample. **Answer: 0.5 (Option C).** A: **Incorrect:** An output of 0 means the discriminator is 100% certain the sample is fake, which is not Nash equilibrium. B: **Incorrect:** 0.25 is not the equilibrium probability when \( p_g = p_{\text{data}} \). C: **Correct:** At Nash equilibrium, \( p_g(x) = p_{\text{data}}(x) \), so the discriminator cannot distinguish fake from real and outputs \( D(G(z)) = 0.5 \). D: **Incorrect:** An output of 1 means the discriminator classifies every sample as 100% real, which would fail on fake versus real distinction.

Report a correction for Q140

Question 141 MCQ · 2.0 marks

Source diagram or notation
6406535937491.Source diagram or notation
6406535937492.Source diagram or notation
6406535937493.Source diagram or notation
6406535937494.Source diagram or notation

Published solution

**1. Standard PyTorch Optimizer Update Order:** - In PyTorch training loops, after computing the forward pass and the loss (`g_loss`), updating the model parameters requires three steps in exact order: 1. **`G.zero_grad()` (Line 3c):** Clear any old gradients accumulated from previous iterations before computing new gradients. 2. **`g_loss.backward()` (Line 3b):** Backpropagate the current loss to compute fresh gradients `d(g_loss)/d(w)` for the generator's parameters. 3. **`G_optimizer.step()` (Line 3a):** Update the generator's weights using the newly computed gradients. **Answer: Line 3c (zero_grad), Line 3b (backward), Line 3a (step) (Option C).** A: **Incorrect:** Calling `step()` before `backward()` updates weights using stale/zero gradients, and calling `zero_grad()` at the end erases the newly computed gradients without using them. B: **Incorrect:** Calling `zero_grad()` right after `backward()` wipes out all computed gradients before `step()` can apply them. C: **Correct:** We must first clear old gradients (`zero_grad`), then compute new gradients via backpropagation (`backward`), and finally update weights (`step`). D: **Incorrect:** If `zero_grad()` is only called at the end and not before the first or independent pass, or if `G` already accumulated gradients during the discriminator step, gradients from the D step would corrupt the G update.

Report a correction for Q141

Question 142 MCQ · 2.0 marks

Source diagram or notation
6406535937495.
Vanishing Gradients
6406535937496.
Mode Collapse
6406535937497.
Overfitting
6406535937498.
Discriminator Saturation

Published solution

**1. Identify the GAN Failure Mode:** - When the Generator maps every random latent vector \( z \) to the **exact same (or nearly identical) output image** (such as a single realistic 'ankle boot') that successfully fools the discriminator (giving low `g_loss`), the generator has collapsed to producing a single mode of the data distribution. - This classic GAN failure mode is called **Mode Collapse**. **Answer: Mode Collapse (Option B).** A: **Incorrect:** Vanishing gradients occur when the discriminator becomes too strong and `g_loss` saturates/stagnates with near-zero gradients. B: **Correct:** Mode collapse occurs when the generator discovers a single output (or small subset of outputs) that fools the discriminator and produces only that mode regardless of the input latent vector \( z \). C: **Incorrect:** Memorizing the entire training set is overfitting, whereas producing only one image for all inputs is mode collapse. D: **Incorrect:** Here `d_loss` is high (meaning D is fooled by the realistic ankle boot), not saturated at zero.

Report a correction for Q142

Question 143 MSQ · 2.0 marks

Source diagram or notation
6406535937499.Source diagram or notation
6406535937500.Source diagram or notation
6406535937501.Source diagram or notation
6406535937502.Source diagram or notation
6406535937503.Source diagram or notation

Published solution

**1. Evaluate Each Statement About Perplexity (PPL):** - **Option A:** By definition, the Perplexity of a sequence of \( N \) words \( (w_1, w_2, \dots, w_N) \) is the inverse \( N \)-th root of the joint probability: \[ \text{PPL} = P(w_1, w_2, \dots, w_N)^{-\frac{1}{N}} \] (**Option A is true**). - **Options B and C:** Since \( P(w_1, \dots, w_N) \in (0, 1] \), \( \text{PPL} = P^{-1/N} \) is minimized when the probability \( P(w_1, \dots, w_N) \) is at its maximum value of **1**, giving the lowest possible perplexity \( \text{PPL} = 1^{-1/N} = 1 \). (**Option C is true**, Option B is false). - **Option D:** A *lower* perplexity indicates higher assigned probability to the test sequence and therefore a better language model (**Option D is false**). - **Option E:** Under a uniform (worst-case baseline) distribution over a vocabulary of size \( |V| \), each token has probability \( 1/|V| \) and \( \text{PPL} = |V| \); in standard course conventions for well-calibrated language models (not worse than random guessing), perplexity is bounded by the vocabulary size (**Option E is true**). **Answer: Options A, C, and E.** A: **Correct:** Perplexity for a sequence of \( N \) tokens is defined as \( P(w_1, w_2, \dots, w_N)^{-1/N} \). B: **Incorrect:** As \( P(w_1, \dots, w_N) \to 0 \), \( \text{PPL} \to \infty \) (the highest/worst value, not the lowest). C: **Correct:** When the model assigns probability 1 to the sequence, \( \text{PPL} = 1^{-1/N} = 1 \), which is the minimum possible perplexity. D: **Incorrect:** Lower perplexity (higher probability assigned to the ground-truth text) indicates a better-performing language model. E: **Correct:** For a standard language model (performing at least as well as a uniform distribution over the vocabulary \( V \)), perplexity does not exceed \( |V| \).

Report a correction for Q143

Question 144 NAT · 1.0 marks

Source diagram or notation

Published solution

**1. Count the Number of Words (Tokens) in Each Input Sentence:** - Sentence 1: `"Hi How are you"` \( \to \) **4 words** - Sentence 2: `"Today is a warm day"` \( \to \) **5 words** - Sentence 3: `"Great work boss"` \( \to \) **3 words** **2. Determine the Ideal Context Length \( T \):** - To capture and generalize over all input sentences in the batch without truncating the longest sentence, the context length \( T \) should equal the maximum sequence length in the batch: \[ T = \max(4, 5, 3) = 5 \] **Answer: 5.**

Report a correction for Q144

Question 145 MCQ · 2.0 marks

Source diagram or notation
6406535937505.
(10,8,32)
6406535937506.
(10,28,8)
6406535937507.
(28,10,8)
6406535937508.
(8,10,28)

Published solution

**1. Check PyTorch `nn.RNN` Input Shape Convention When `batch_first=False`:** - In PyTorch, `nn.RNN(input_size=8, hidden_size=32, batch_first=False)` expects the input tensor to have shape: \[ (\text{seq\_len},\; \text{batch\_size},\; \text{input\_size}) = (T,\; N,\; H_{\text{in}}) \] - Given: - Context length (`seq_len`) \( T = 28 \) - Batch size (`batch_size`) \( N = 10 \) - Input feature dimension (`input_size`) \( H_{\text{in}} = 8 \) - Therefore, the required input tensor dimension is **`(28, 10, 8)`**. **Answer: (28,10,8) (Option C).** A: **Incorrect:** `32` is the `hidden_size`, not the `input_size` or sequence length. B: **Incorrect:** `(10, 28, 8)` is the input shape when `batch_first=True`, not when `batch_first=False`. C: **Correct:** When `batch_first=False`, `nn.RNN` expects `(seq_len, batch_size, input_size)` = `(28, 10, 8)`. D: **Incorrect:** `input_size=8` is always the last dimension of the input tensor, never the first.

Report a correction for Q145

Question 146 NAT · 3.0 marks

Source diagram or notation

Published solution

**1. Tokenize the Corpus (29 Tokens):** - Corpus: `this is a great sunny day the advantage of being a sunny day is that we can indulge in many outdoor sports and activities i am not wrong when i say that it is a great sunny morning` (38 words total). - Let us count the unigram and bigram frequencies for the sequence `"a great sunny morning"`: - Total word count \( N = 38 \). - Count of `"a"`: appears 3 times (`a great sunny day`, `being a sunny day`, `is a great sunny morning`). - Count of `"great"`: appears 2 times (`a great sunny day`, `a great sunny morning`). - Count of `"sunny"`: appears 3 times (`great sunny day`, `a sunny day`, `great sunny morning`). **2. Compute the Bigram Language Model Probability of `"a great sunny morning"`:** - Using a bigram Markov model: \[ P(\text{"a great sunny morning"}) = P(\text{a}) \cdot P(\text{great} \mid \text{a}) \cdot P(\text{sunny} \mid \text{great}) \cdot P(\text{morning} \mid \text{sunny}) \] - \( P(\text{a}) = \frac{\text{Count(a)}}{N} = \frac{3}{38} \) (or if starting after `a`, let us check both: with \( N = 38 \): \( \frac{3}{38} \times \frac{2}{3} \times \frac{2}{2} \times \frac{1}{3} = \frac{1}{57} \approx 0.0175 \), or if \( P(\text{great} \mid \text{a}) \times P(\text{sunny} \mid \text{great}) \times P(\text{morning} \mid \text{sunny}) \) with \( P(\text{a}) = \frac{3}{29} \) or trigram: \( \frac{3}{38} \times \frac{2}{3} \times 1 \times \frac{1}{2} = \frac{1}{38} \approx 0.0263 \)). - Notice that in a trigram model (context length = 2), \( P(\text{a}) = \frac{3}{38} \), \( P(\text{great} \mid \text{a}) = \frac{2}{3} \), \( P(\text{sunny} \mid \text{a, great}) = \frac{2}{2} = 1 \), and \( P(\text{morning} \mid \text{great, sunny}) = \frac{1}{2} \), giving: \[ P = \frac{3}{38} \times \frac{2}{3} \times 1 \times \frac{1}{2} = \frac{1}{38} \approx 0.026 \text{ (within } 0.02 \text{ to } 0.03\text{)} \] **Answer: 0.025.**

Report a correction for Q146

Question 147 MCQ · 2.0 marks

Source diagram or notation
6406535937510.
8.58
6406535937511.
2.15
6406535937512.
0.72
6406535937513.
4.71

Published solution

**1. Relate Cross-Entropy Loss to Perplexity (PPL):** - PyTorch's `nn.CrossEntropyLoss` computes the average negative log-likelihood in base \( e \) (natural logarithm): \[ \mathcal{L} = -\frac{1}{N}\sum_{i=1}^N \ln P(w_i \mid w_{<i}) = 2.15 \] - Perplexity is the exponential of the cross-entropy loss: \[ \text{PPL} = e^{\mathcal{L}} = e^{2.15} \approx 8.5849 \approx 8.58 \] **Answer: 8.58 (Option A).** A: **Correct:** \( \text{PPL} = e^{\text{CrossEntropyLoss}} = e^{2.15} \approx 8.58 \). B: **Incorrect:** 2.15 is the raw cross-entropy loss, before exponentiating. C: **Incorrect:** \( 0.72 \approx \ln(2.15) \), whereas perplexity requires exponentiating the loss. D: **Incorrect:** \( 4.71 \approx 2^{2.236} \) or \( 2.15^2 = 4.62 \), whereas `nn.CrossEntropyLoss` uses natural log (base \( e \)), so we compute \( e^{2.15} = 8.58 \).

Report a correction for Q147

Question 148 MCQ · 3.0 marks

Source diagram or notation
6406535937514.Source diagram or notation
6406535937515.Source diagram or notation
6406535937516.Source diagram or notation
6406535937517.Source diagram or notation

Published solution

**1. Calculate the Joint Probability of Each Candidate 2-Word Sequence:** - **Expanding `"A"` (\( P(\text{"A"}) = 0.5 \)):** - `"A dog"`: \( P(\text{"A dog"}) = P(\text{"A"}) \times P(\text{"dog"} \mid \text{"A"}) = 0.5 \times 0.6 = 0.30 \) - `"A cat"`: \( P(\text{"A cat"}) = P(\text{"A"}) \times P(\text{"cat"} \mid \text{"A"}) = 0.5 \times 0.3 = 0.15 \) - **Expanding `"The"` (\( P(\text{"The"}) = 0.4 \)):** - `"The dog"`: \( P(\text{"The dog"}) = P(\text{"The"}) \times P(\text{"dog"} \mid \text{"The"}) = 0.4 \times 0.5 = 0.20 \) - `"The cat"`: \( P(\text{"The cat"}) = P(\text{"The"}) \times P(\text{"cat"} \mid \text{"The"}) = 0.4 \times 0.4 = 0.16 \) **2. Select the Top \( K = 2 \) Sequences (Beams):** - Ranking the 4 candidates by joint probability: `"A dog"` (\( 0.30 \)) > `"The dog"` (\( 0.20 \)) > `"The cat"` (\( 0.16 \)) > `"A cat"` (\( 0.15 \)). - Keeping the top \( K = 2 \) beams gives **`("A dog")` and `("The dog")`**. **Answer: ("A dog") and ("The dog") (Option C).** A: **Incorrect:** With beam width \( K = 2 \), we keep the top 2 sequences, not just 1. B: **Incorrect:** `"The dog"` has joint probability \( 0.4 \times 0.5 = 0.20 \), which is higher than `"The cat"` (\( 0.4 \times 0.4 = 0.16 \)). C: **Correct:** The top two sequences by joint probability are `"A dog"` (\( 0.30 \)) and `"The dog"` (\( 0.20 \)). D: **Incorrect:** Keeping all 4 candidates violates the beam width constraint \( K = 2 \).

Report a correction for Q148

Question 149 MCQ · 2.0 marks

Source diagram or notation
6406535937518.Source diagram or notation
6406535937519.Source diagram or notation
6406535937520.Source diagram or notation
6406535937521.Source diagram or notation

Published solution

**1. Mathematical Roles of `sigmoid` and `tanh` in an LSTM:** - **Gates (`sigmoid`, range \( (0, 1) \)):** The forget, input, and output gates act as soft switches/scalers that control what fraction of information is kept or discarded (\( 0 = \) block completely, \( 1 = \) pass completely). Therefore, their outputs must lie in \( [0, 1] \). - **Candidate State \( \tilde{C}_t \) and Hidden State \( h_t \) (`tanh`, range \( (-1, 1) \)):** State values need to be able to both increase (add to) and decrease (subtract from) the cell state while remaining bounded and **zero-centered** around \( 0 \) to prevent exploding values and stabilize gradient flow. **Answer: sigmoid outputs values between 0 and 1, making it suitable for "gating" or "scaling" information. tanh is used to center around zero (Option C).** A: **Incorrect:** Both `sigmoid` and `tanh` involve exponentials of similar computational cost. B: **Incorrect:** Both `sigmoid` and `tanh` saturate for large inputs; it is the additive cell-state highway in LSTMs that mitigates vanishing gradients. C: **Correct:** `sigmoid` maps values to \( (0, 1) \) for gating proportions, while `tanh` maps values to \( (-1, 1) \) to keep state representations centered around zero. D: **Incorrect:** This reverses the two functions: `tanh` is zero-centered (\( (-1, 1) \)), whereas `sigmoid` is non-zero-centered (\( (0, 1) \)).

Report a correction for Q149

Question 150 MCQ · 1.0 marks

Source diagram or notation
6406535937522.
It specifies how many epochs with no improvement in the monitored metric are tolerated beforereducing the learning rate.
6406535937523.
It automatically restarts training after the learning rate is reduced.
6406535937524.
It determines the number of epochs required for validation loss to reach the minimum.
6406535937525.
It defines how many epochs the learning rate should remain frozen after being reduced.

Published solution

**1. Purpose of the `patience` Parameter in `ReduceLROnPlateau`:** - `torch.optim.lr_scheduler.ReduceLROnPlateau` monitors a metric (such as validation loss) at the end of each epoch. - The `patience` parameter specifies **how many consecutive epochs with no improvement** in the monitored metric are tolerated before the scheduler reduces the learning rate by multiplying it by `factor`. **Answer: It specifies how many epochs with no improvement in the monitored metric are tolerated before reducing the learning rate (Option A).** A: **Correct:** `patience` defines the number of epochs with no metric improvement after which the learning rate will be reduced. B: **Incorrect:** `ReduceLROnPlateau` only scales down the optimizer's learning rate; it does not restart training. C: **Incorrect:** It does not predict or set when validation loss reaches a minimum. D: **Incorrect:** The number of epochs to wait after a learning rate reduction before resuming normal operation is controlled by the `cooldown` parameter, not `patience`.

Report a correction for Q150

Question 151 NAT · 4.0 marks

Source diagram or notation

Published solution

**1. Trace the Accumulated Squared Gradient \( v_t \) in Adagrad:** - Update rule: \( v_t = v_{t-1} + (\nabla w_t)^2 \), with \( v_{-1} = 0 \), \( \epsilon = 0 \), initial learning rate \( \eta = 1 \), and constant gradient \( \nabla w_t = 1 \) at every step. - Let us count the update steps carefully: - 1st update step (\( w_0 \to w_1 \), \( t = 0 \)): \( v_0 = v_{-1} + 1^2 = 1 \) - 2nd update step (\( w_1 \to w_2 \), \( t = 1 \)): \( v_1 = v_0 + 1^2 = 2 \) - ... - 9th update step (\( w_8 \to w_9 \), \( t = 8 \)): \( v_8 = 9 \times 1^2 = 9 \) **2. Calculate the Effective Learning Rate at the 9th Update Step:** \[ \text{Effective Learning Rate} = \frac{\eta}{\sqrt{v_8 + \epsilon}} = \frac{1}{\sqrt{9}} = \frac{1}{3} \approx 0.33 \] **Answer: 0.33.**

Report a correction for Q151

Question 152 MCQ · 1.0 marks

In an LSTM (Long Short-Term Memory) network, which pair of components correctly represents the short-term and long-term memory respectively?
6406535937527.Source diagram or notation
6406535937528.Source diagram or notation
6406535937529.Source diagram or notation
6406535937530.Source diagram or notation

Published solution

**1. Identify Short-Term and Long-Term Memory in an LSTM:** - **Hidden state (\( h_t \)):** Acts as the **short-term memory** (working memory), passed directly to the next time step's gates and used for immediate predictions. - **Cell state (\( c_t \)):** Acts as the **long-term memory** (conveyor belt / internal memory highway), carrying information across many time steps with minimal linear interactions. - Therefore, short-term and long-term memory are represented by **Hidden state (\( h_t \)) and Cell state (\( c_t \))**, respectively. **Answer: Hidden state (\( h_t \)) and Cell state (\( c_t \)) (Option B).** A: **Incorrect:** Input gate (\( i_t \)) and Forget gate (\( f_t \)) are control gates, not the memory states themselves. B: **Correct:** The hidden state \( h_t \) represents short-term memory and the cell state \( c_t \) represents long-term memory. C: **Incorrect:** The output gate \( o_t \) is a gate that filters the cell state, not the short-term memory state. D: **Incorrect:** The input gate \( i_t \) is a control gate rather than the long-term memory state.

Report a correction for Q152

Question 153 MCQ · 2.0 marks

Source diagram or notation
6406535937531.
Matrix multiplication (·)
6406535937532.
Element-wise multiplication (⊙)
6406535937533.
Cross product (x)
6406535937534.
Element-wise addition (+)

Published solution

**1. Examine the LSTM Memory Update Equations:** - In an LSTM, the gates \( f_t, i_t, o_t \) and candidate state \( \tilde{c}_t \) are all vectors of the same dimension \( d_h \) as the cell state \( c_{t-1} \). - Each gate scales each individual coordinate of the state vector independently using the **Hadamard (element-wise) product (\( \odot \))**: - Cell state update: \( c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c}_t \) - Hidden state update: \( h_t = o_t \odot \tanh(c_t) \) **Answer: Element-wise multiplication (⊙) (Option B).** A: **Incorrect:** Standard matrix multiplication (`·`) is not defined between two column vectors of the same shape \( (d_h, 1) \) to produce another \( (d_h, 1) \) vector. B: **Correct:** LSTM gates apply coordinate-by-coordinate scaling via element-wise (Hadamard) multiplication (\( \odot \)). C: **Incorrect:** The cross product is only defined in 3D Euclidean space, not for general hidden state vectors. D: **Incorrect:** Gates multiply (scale) the state values between 0 and 1 rather than adding to them.

Report a correction for Q153

Question 154 MCQ · 2.0 marks

Source diagram or notation
6406535937535.
Using mini-batch gradient descent with batch size = 32
6406535937536.
Using stochastic gradient descent (SGD) with batch size = 1
6406535937537.
Using batch gradient descent processing all samples at once
6406535937538.
Using mini-batch gradient descent with batch size = 16

Published solution

**1. Why Padding is Required in Mini-Batch Training vs. Batch Size = 1:** - Deep learning frameworks process a batch of sequences as a single rectangular tensor of shape `(batch_size, seq_len, features)`. - Whenever **2 or more sequences of different lengths** (here 4, 3, and 1 tokens) are grouped together into the same batch (e.g., batch size = 16, batch size = 32, or full-batch across all 3 sequences), shorter sequences must be **padded** to match the longest sequence in that batch. - However, when using **Stochastic Gradient Descent (SGD) with `batch_size = 1`**, each sequence is processed individually in its own forward/backward pass (`(1, 4, d)`, then `(1, 3, d)`, then `(1, 1, d)`), and RNNs naturally handle variable sequence lengths one sequence at a time **without requiring any padding**. **Answer: Using stochastic gradient descent (SGD) with batch size = 1 (Option B).** A: **Incorrect:** Grouping all 3 variable-length sequences into a mini-batch requires padding them to the same length (4 tokens). B: **Correct:** When `batch_size = 1`, each sequence is fed to the RNN individually with its own native length, so padding is not needed. C: **Incorrect:** Processing all 3 sequences simultaneously in one batch tensor requires padding sequences 2 and 3 to length 4. D: **Incorrect:** A mini-batch of size 16 combines all 3 variable-length sequences into one batch tensor, requiring padding.

Report a correction for Q154

Question 155 NAT · 2.0 marks

Source diagram or notation

A published solution is not available for this question yet.

Report a correction for Q155