Practice
1. What is the time complexity of applying a dropout layer to an input of size n during training?
easy
Solution
Step 1: Analyze Dropout Operation
Applying dropout involves generating a mask and element-wise multiplication, both O(n) operations.Step 2: Eliminate Wrong Options
O(1) suggests constant time, which is incorrect. O(n^2) suggests quadratic time, which is excessive. O(log n) suggests logarithmic time, which is not applicable.Final Answer:
Option D -> Option DQuick Check:
Dropout involves element-wise operations. [OK]
Hint: Dropout involves element-wise operations. [OK]
Common Mistakes:
2. What does the following Python code snippet output when implementing Mini-Batch SGD with Momentum?
import numpy as np
velocity = np.array([0.0, 0.0])
gradient = np.array([0.1, 0.2])
learning_rate = 0.01
momentum = 0.9
velocity = momentum * velocity - learning_rate * gradient
print(velocity)easy
Solution
Step 1: Calculate the velocity update
The formula for velocity update isvelocity = momentum * velocity - learning_rate * gradient. Given the initial velocity is zero, the update becomesvelocity = -learning_rate * gradient.Step 2: Substitute the values
Substitutelearning_rate = 0.01andgradient = [0.1, 0.2]into the formula:velocity = -0.01 * [0.1, 0.2] = [-0.001, -0.002].Final Answer:
Option C -> Option CQuick Check:
Velocity update is negative of learning rate times gradient [OK]
Hint: Velocity update is negative of learning rate times gradient [OK]
Common Mistakes:
3. You implemented Robust Scaling but your model's performance dropped. What is the most likely cause?
medium
Solution
Step 1: Understand Robust Scaling
Robust Scaling uses the median and IQR, which reduces the influence of outliers.Step 2: Identify the Issue
If outliers are important, reducing their influence can harm model performance.Final Answer:
Option D -> Option DQuick Check:
Robust Scaling reduces outlier impact. [OK]
Hint: Robust Scaling reduces outlier impact. [OK]
Common Mistakes:
4. In the following implementation of scaled dot-product attention, the output is incorrect. What is the likely cause?
import torch
import torch.nn.functional as F
queries = torch.randn(2, 3)
keys = torch.randn(2, 3)
values = torch.randn(2, 3)
scores = torch.matmul(queries, keys.T) / torch.sqrt(torch.tensor(3.0))
attention_weights = F.softmax(scores, dim=0)
output = torch.matmul(attention_weights, values)medium
Solution
Step 1: Identify the issue
Softmax should be applied on the last dimension, not the first.Step 2: Eliminate other causes
Scaling factor and tensor shapes are correct; normalization is handled by softmax.Final Answer:
Option B -> Option BQuick Check:
Softmax on last dim for attention [OK]
Hint: Softmax on last dim for attention [OK]
Common Mistakes:
5. How can the calculation of precision, recall, and F1-score be optimized for a large confusion matrix?
hard
Solution
Step 1: Identify bottlenecks
Calculating metrics for each class can be parallelized.Step 2: Choose the best optimization strategy
Parallel processing allows simultaneous computation, reducing time complexity.Final Answer:
Option C -> Option CQuick Check:
Parallelize class-wise computations. [OK]
Hint: Parallelize class-wise computations. [OK]
Common Mistakes:
