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. In the context of cross-validation, which method is most appropriate for imbalanced datasets?
easy
Solution
Step 1: Identify the need for balanced class distribution.
Imbalanced datasets require maintaining class distribution in each fold.Step 2: Eliminate wrong options.
K-Fold does not ensure class balance (A), Time Series Split is for temporal data (C), Leave-One-Out is computationally expensive and doesn't address imbalance (D).Final Answer:
Option C -> Option CQuick Check:
Stratified keeps class balance. [OK]
Hint: Stratified keeps class balance. [OK]
Common Mistakes:
3. A model trained on standardized data is underperforming. What could be a potential issue?
medium
Solution
Step 1: Analyze the impact of standardization on model performance.
Standardization centers data around zero, which can affect models sensitive to feature means.Step 2: Identify the potential issue.
Some models may perform poorly if they rely on the original mean of the data.Final Answer:
Option A -> Option AQuick Check:
Model sensitive to mean? Standardization affects it. [OK]
Hint: Model sensitive to mean? Standardization affects it. [OK]
Common Mistakes:
4. A model trained with Adam optimizer is not converging. What is the most likely cause?
medium
Solution
Step 1: Identify common issues with Adam.
Adam can be sensitive to high learning rates, causing divergence.Step 2: Eliminate less likely causes.
Adam handles non-convex problems well, and batch size/weight decay are less likely to cause non-convergence.Final Answer:
Option B -> Option BQuick Check:
High lr can cause Adam to diverge. [check]
Hint: High lr can cause Adam to diverge. [check]
Common Mistakes:
5. You want to apply A/B testing to a recommendation system that updates in real-time. Which approach best handles the dynamic nature of the system?
hard
Solution
Step 1: Consider real-time requirements
Causal inference can integrate real-time data to adapt to changes.Step 2: Eliminate wrong options
Holdout and interleaving are less suited for real-time updates. Cross-validation is not typically used for real-time systems.Final Answer:
Option A -> Option AQuick Check:
Causal inference adapts to real-time changes. [OK]
Hint: Causal inference adapts to real-time changes. [OK]
Common Mistakes:
