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.
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6]])
X_meaned = X - np.mean(X, axis=0)
cov_matrix = np.cov(X_meaned, rowvar=False)
print(cov_matrix)What does this code output?easy
Solution
Step 1: Understand the covariance matrix calculation
The covariance matrix is calculated for the features (columns) of the dataset.Step 2: Eliminate wrong options
A 3x3 covariance matrix is incorrect because the covariance matrix is not 3x3 for a 2-feature dataset. A 2x3 covariance matrix and D are incorrect because covariance matrices are square.Final Answer:
Option C -> Option CQuick Check:
Covariance matrix is square, size = features. [OK]
Hint: Covariance matrix is square, size = features. [OK]
Common Mistakes:
3.
import numpy as np
# Backpropagation for a single neuron
inputs = np.array([1.0, 2.0, 3.0])
weights = np.array([0.2, 0.8, -0.5])
bias = 2.0
learning_rate = 0.01
d_output = np.array([1.0]) # Gradient of loss w.r.t output
# Incorrect gradient calculation
weights_gradient = d_output * inputs
weights -= learning_rate * weights_gradient
print(weights)medium
Solution
Step 1: Identify error in gradient calculation
The code incorrectly applies the gradient directly without considering the chain rule.Step 2: Correct approach
Should multiply by the derivative of the activation function.Final Answer:
Option D -> Option DQuick Check:
Always apply chain rule in backpropagation [OK]
Hint: Always apply chain rule in backpropagation [OK]
Common Mistakes:
4. How can you optimize the backward pass of batch normalization to improve computational efficiency?
hard
Solution
Step 1: Identify optimization techniques
Fusing operations can reduce computational overhead.Step 2: Evaluate each option
Fusing batch normalization with linear layers reduces redundant computations.Final Answer:
Option A -> Option AQuick Check:
Fuse layers to optimize batch norm [OK]
Hint: Fuse layers to optimize batch norm [OK]
Common Mistakes:
5. How can you optimize the memory usage of the Skip-Gram model with negative sampling when dealing with a large vocabulary?
hard
Solution
Step 1: Identify memory bottlenecks
Large vocabularies lead to large embedding matrices, consuming significant memory.Step 2: Evaluate optimization strategies
Sparse embeddings store only non-zero entries, significantly reducing memory usage compared to dense matrices.Final Answer:
Option B -> Option BQuick Check:
Sparse embeddings save memory for large vocabularies [OK]
Hint: Sparse embeddings save memory for large vocabularies [OK]
Common Mistakes:
