Practice
1. What is the time complexity of calculating the Euclidean distance between two vectors of length n?
easy
Solution
Step 1: Understand Euclidean distance calculation
Euclidean distance involves element-wise operations and a square root.Step 2: Analyze operations
Each element is processed once, leading to O(n) complexity.Final Answer:
Option D -> Option DQuick Check:
Element-wise operations imply O(n). [OK]
Hint: Element-wise operations imply O(n). [OK]
Common Mistakes:
2. 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:
3. 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:
4.
def calculate_f1(confusion_matrix):
tp = confusion_matrix[0, 0]
fp = confusion_matrix[1, 0]
fn = confusion_matrix[0, 1]
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1_score = 2 * (precision * recall) / (precision + recall)
return f1_score
confusion_matrix = np.array([[50, 10], [5, 35]])
print(calculate_f1(confusion_matrix))medium
Solution
Step 1: Calculate precision and recall
Precision = 0.9091, Recall = 0.8333.Step 2: Calculate F1-score
F1 = 2 * (0.9091 * 0.8333) / (0.9091 + 0.8333) = 0.8696.Final Answer:
Option B -> Option BQuick Check:
F1 combines precision and recall. [OK]
Hint: F1 combines precision and recall. [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:
