Practice
1. What does the following Python code snippet output when implementing the forward pass of batch normalization?
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6]])
mean = np.mean(X, axis=0)
var = np.var(X, axis=0)
X_norm = (X - mean) / np.sqrt(var + 1e-8)
print(X_norm)easy
Solution
Step 1: Understand the code
The code calculates the mean and variance for each feature, normalizes the data, and prints it.Step 2: Check the normalization
Batch normalization ensures each feature has zero mean and unit variance.Final Answer:
Option C -> Option CQuick Check:
Batch norm: zero mean, unit variance [OK]
Hint: Batch norm: zero mean, unit variance [OK]
Common Mistakes:
2. What is the time complexity of finding the nearest neighbors using a brute force approach in a KNN classifier?
easy
Solution
Step 1: Understand brute force KNN
Brute force KNN involves calculating the distance from the query point to all training points.Step 2: Analyze complexity
For each of the n training points, we compute the distance in d dimensions, leading to O(n * d).Final Answer:
Option C -> Option CQuick Check:
Brute force KNN: O(n * d) [OK]
Hint: Brute force KNN: O(n * d) [OK]
Common Mistakes:
3. What is the time complexity of computing the covariance matrix for a dataset with n samples and d features?
easy
Solution
Step 1: Analyze the covariance matrix computation
Computing the covariance matrix involves calculating pairwise covariances for d features, each requiring O(n) operations.Step 2: Eliminate wrong options
O(n^2) is incorrect as it doesn't account for features. O(d^2) is incorrect because it ignores the sample size. O(nd^2) overestimates the complexity.Final Answer:
Option D -> Option DQuick Check:
Covariance: O(nd) for n samples, d features. [OK]
Hint: Covariance: O(nd) for n samples, d features. [OK]
Common Mistakes:
4. What is the time complexity of computing the ROC curve using the sklearn library?
easy
Solution
Step 1: Understand ROC computation
ROC curve computation involves sorting the scores, which is O(n log n).Step 2: Eliminate wrong options
O(n^2) is incorrect as it suggests quadratic complexity, O(n) suggests linear complexity which ignores sorting, and O(log n) is too low.Final Answer:
Option A -> Option AQuick Check:
ROC curve involves sorting, hence O(n log n) [OK]
Hint: ROC curve involves sorting, hence O(n log n) [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:
