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. A Graph Neural Network model is underperforming on a node classification task. The model's architecture and hyperparameters seem appropriate. What could be a potential cause of this issue?
medium
Solution
Step 1: Analyze the graph structure
Isolated nodes can disrupt message passing, leading to poor performance.Step 2: Eliminate other causes
Overfitting, learning rate, and batch size issues would manifest differently.Final Answer:
Option D -> Option DQuick Check:
Check for isolated nodes disrupting message passing. [check]
Hint: Check for isolated nodes disrupting message passing. [check]
Common Mistakes:
3. You notice that your LSTM model is not learning effectively and suspect vanishing gradients. What is a likely cause specific to LSTM architecture?
medium
Solution
Step 1: Identify LSTM-specific issues.
Incorrect initialization of forget gate biases can lead to vanishing gradients.Step 2: Eliminate wrong options.
Too many layers can cause vanishing gradients, but it's not LSTM-specific. High learning rates cause exploding gradients, and dropout affects overfitting, not gradient flow.Final Answer:
Option A -> Option AQuick Check:
Forget gate bias affects gradient flow. [OK]
Hint: Forget gate bias affects gradient flow. [OK]
Common Mistakes:
4. How would you apply slice-based evaluation to improve a sentiment analysis model for a multilingual dataset?
hard
Solution
Step 1: Understand the application of slice-based evaluation
Slice-based evaluation helps identify performance issues in specific data subsets.Step 2: Apply to multilingual context
Creating slices based on language allows for targeted performance analysis and improvements.Final Answer:
Option B -> Option BQuick Check:
Slice by language for targeted analysis. [OK]
Hint: Slice by language for targeted analysis. [OK]
Common Mistakes:
5. How would you adapt K-Means to handle a dataset with categorical features?
hard
Solution
Step 1: Understand K-Means limitations
K-Means is not suitable for categorical data as it relies on Euclidean distance.Step 2: Choose the right adaptation
K-Modes is designed for clustering categorical data, making it the best choice.Final Answer:
Option B -> Option BQuick Check:
K-Modes for categorical data [OK]
Hint: K-Modes for categorical data [OK]
Common Mistakes:
