Practice
1.
import torch
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
for epoch in range(10):
for data, target in dataloader:
optimizer.zero_grad()
output = model(data)
loss = loss_fn(output, target)
loss.backward()
optimizer.step()
print(optimizer.param_groups[0]['lr'])What will be printed after the loop?easy
Solution
Step 1: Understand the code.
The learning rate is set to 0.1 and not changed in the loop.Step 2: Check for learning rate updates.
SGD without a scheduler keeps the learning rate constant.Final Answer:
Option C -> Option CQuick Check:
SGD without scheduler keeps lr constant. [check]
Hint: SGD without scheduler keeps lr constant. [check]
Common Mistakes:
2. A model trained with K-Fold cross-validation is underperforming on unseen data. What is a likely cause?
medium
Solution
Step 1: Consider data leakage as a common issue.
Data leakage can occur if the same data points appear in both training and validation sets.Step 2: Eliminate wrong options.
Too many folds (A) typically doesn't cause overfitting, too few folds (C) would not cause underperformance on unseen data, model complexity (D) is unrelated to cross-validation setup.Final Answer:
Option B -> Option BQuick Check:
Check for data leakage in CV. [OK]
Hint: Check for data leakage in CV. [OK]
Common Mistakes:
3. In a scenario where computational resources are limited, which approach is more suitable for hyperparameter tuning and why?
medium
Solution
Step 1: Evaluate resource constraints
Cross-validation is computationally expensive but provides robust tuning.Step 2: Eliminate less suitable options
Use a single train-test split to save resources. risks overfitting. Use a train-validation split and skip the test set. skips the test set, risking unseen data performance. Use a larger test set to ensure model generalization. misallocates resources to testing rather than tuning.Final Answer:
Option C -> Option CQuick Check:
Cross-validation ensures robust tuning despite cost. [OK]
Hint: Cross-validation ensures robust tuning despite cost. [OK]
Common Mistakes:
4. When choosing between a Graph Convolutional Network (GCN) and a Graph Attention Network (GAT) for a task with highly heterogeneous node importance, which is more appropriate and why?
medium
Solution
Step 1: Identify the task requirement
Highly heterogeneous node importance suggests the need for attention mechanisms.Step 2: Compare GCN and GAT
GAT uses attention to weigh node importance, unlike GCN.Final Answer:
Option B -> Option BQuick Check:
Use GAT for node importance heterogeneity. [check]
Hint: Use GAT for node importance heterogeneity. [check]
Common Mistakes:
5. In a real-time prediction system, how should you handle data splits to ensure both model performance and system efficiency?
hard
Solution
Step 1: Consider real-time constraints
Real-time systems need to adapt to new data while maintaining performance.Step 2: Evaluate options for adaptability and efficiency
Use a single train-test split to minimize latency. risks overfitting. Use a large test set to ensure model robustness. misallocates resources. Use a static validation set to simplify the system. lacks adaptability to new data.Final Answer:
Option D -> Option DQuick Check:
Rolling window adapts to new data efficiently. [OK]
Hint: Rolling window adapts to new data efficiently. [OK]
Common Mistakes:
