Practice
1. Given the following PyTorch code snippet, what will be the output shape of the gradient for
W after backpropagation?import torch
W = torch.tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True)
x = torch.tensor([1.0, 2.0])
y = W @ x
loss = y.sum()
loss.backward()easy
Solution
Step 1: Determine the gradient shape
The gradient ofWwill have the same shape asW, which is (2, 2).Step 2: Eliminate wrong options
(2,) is incorrect because it suggests a vector shape. (2, 1) and D are incorrect because they suggest mismatched dimensions.Final Answer:
Option A -> Option AQuick Check:
Gradient shape matches tensor shape. [OK]
Hint: Gradient shape matches tensor shape. [OK]
Common Mistakes:
2.
import numpy as np
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
result = np.dot(x, y)
print(result)What does this code output?easy
Solution
Step 1: Understand the dot product operation.
The dot product of two vectors is the sum of the products of their corresponding elements.Step 2: Calculate the dot product.
(1*4) + (2*5) + (3*6) = 32.Final Answer:
Option C -> Option CQuick Check:
Dot product sums element-wise products. [OK]
Hint: Dot product sums element-wise products. [OK]
Common Mistakes:
3. A model performs well on the validation set but poorly on the test set. What is the most likely cause?
medium
Solution
Step 1: Identify the discrepancy
Good validation performance but poor test performance suggests a mismatch between sets.Step 2: Eliminate less likely causes
The model is underfitting the data. is incorrect as underfitting would affect both sets. The validation set is too small. is less likely unless the validation set is extremely small. The model has too many parameters. would likely affect both sets similarly.Final Answer:
Option A -> Option AQuick Check:
Mismatch between validation and test sets. [OK]
Hint: Mismatch between validation and test sets. [OK]
Common Mistakes:
4. When choosing between Least Squares and Gradient Descent for linear regression, which scenario makes Gradient Descent more suitable?
medium
Solution
Step 1: Identify the constraint
Gradient Descent is more suitable for large datasets that don't fit in memory because it can process data in batches.Step 2: Eliminate wrong options
Least Squares is efficient for small datasets (A), interpretability is not a deciding factor (C), and noise handling depends on regularization, not the optimization method (D).Final Answer:
Option C -> Option CQuick Check:
Gradient Descent handles large datasets in batches. [OK]
Hint: Gradient Descent handles large datasets in batches. [OK]
Common Mistakes:
5. A deployed model is showing unexpected behavior with high variance in predictions. What is the most likely cause?
medium
Solution
Step 1: Identify the symptom.
High variance in predictions suggests the model is not generalizing well.Step 2: Determine the most likely cause.
Data drift, where the input data distribution changes over time, is a common cause of unexpected behavior in production.Final Answer:
Option D -> Option DQuick Check:
Data drift causes unexpected variance. [OK]
Hint: Data drift causes unexpected variance. [OK]
Common Mistakes:
