Practice
1. What is the time complexity of computing a confusion matrix for a binary classification problem with n predictions?
easy
Solution
Step 1: Analyze the operation
Computing a confusion matrix involves iterating over predictions once.Step 2: Determine complexity
Each prediction is checked once, leading to O(n) complexity.Final Answer:
Option C -> Option CQuick Check:
Confusion matrix computation is linear in predictions. [OK]
Hint: Confusion matrix computation is linear in predictions. [OK]
Common Mistakes:
2. What is the time complexity of calculating the entropy for a dataset with n samples?
easy
Solution
Step 1: Analyze entropy calculation
Entropy calculation involves counting occurrences and computing probabilities, both O(n).Step 2: Eliminate wrong options
O(n^2) and O(n log n) are incorrect as they overestimate the operations needed.Final Answer:
Option D -> Option DQuick Check:
Entropy calculation is linear in n [OK]
Hint: Entropy calculation is linear in n [OK]
Common Mistakes:
3. What does the following Python code snippet output when implementing sinusoidal positional encoding?
import numpy as np
def positional_encoding(position, d_model):
angle_rads = np.arange(position)[:, np.newaxis] / np.power(10000, (2 * (np.arange(d_model)[np.newaxis, :] // 2)) / np.float32(d_model))
angle_rads[:, 0::2] = np.sin(angle_rads[:, 0::2])
angle_rads[:, 1::2] = np.cos(angle_rads[:, 1::2])
return angle_rads
pe = positional_encoding(4, 4)
print(pe)easy
Solution
Step 1: Understand the code logic
The code generates a matrix where each row corresponds to a position and each column to a dimension, filled with sinusoidal values.Step 2: Eliminate wrong options
A 4x4 matrix with all zeros is incorrect because the matrix is not filled with zeros. A 4x4 identity matrix is incorrect because the matrix is not an identity matrix. A 4x4 matrix with random values is incorrect because the values are not random but deterministic sinusoidal values.Final Answer:
Option A -> Option AQuick Check:
Sinusoidal encoding alternates sine/cosine. [OK]
Hint: Sinusoidal encoding alternates sine/cosine. [OK]
Common Mistakes:
4. What is the time complexity of computing the scaled dot-product attention for a single query with n keys?
easy
Solution
Step 1: Identify operations
For a single query, the main operations are dot product and softmax, both O(n).Step 2: Eliminate incorrect complexities
O(n^2) and O(n log n) are incorrect as they imply more complex operations than present.Final Answer:
Option C -> Option CQuick Check:
Single query, n keys -> O(n) [OK]
Hint: Single query, n keys -> O(n) [OK]
Common Mistakes:
5. In a recommendation system, why might you choose NDCG over precision at k?
medium
Solution
Step 1: Understand NDCG vs Precision
NDCG accounts for the position of relevant items, giving higher scores to relevant items at higher ranks.Step 2: Evaluate Options
Precision at k does not consider the order of items, only their presence.Final Answer:
Option B -> Option BQuick Check:
NDCG values position. [OK]
Hint: NDCG values position. [OK]
Common Mistakes:
