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 does the following Python code snippet output when implementing the Skip-Gram model with negative sampling?
import numpy as np
vocab_size = 5
embedding_dim = 3
# Initialize random embeddings
embeddings = np.random.rand(vocab_size, embedding_dim)
# Select a word index
word_index = 2
# Get the embedding for the word
word_embedding = embeddings[word_index]
print(word_embedding.shape)easy
Solution
Step 1: Understand the code
The code initializes a random embedding matrix of shape (vocab_size, embedding_dim) and retrieves the embedding for a specific word index.Step 2: Determine the shape of the retrieved embedding
The embedding for a single word is a 1D array with length equal to embedding_dim, hence the shape is (3,).Final Answer:
Option C -> Option CQuick Check:
Single word embedding shape is (embedding_dim,) [OK]
Hint: Single word embedding shape is (embedding_dim,) [OK]
Common Mistakes:
3. In a multi-class classification problem, how would you modify the softmax function to handle very large input values?
medium
Solution
Step 1: Address numerical stability
Subtracting the max input value prevents overflow in exponentials.Step 2: Ensure correct probabilities
This adjustment maintains the relative differences between inputs.Final Answer:
Option A -> Option AQuick Check:
Subtract max for stability in softmax [OK]
Hint: Subtract max for stability in softmax [OK]
Common Mistakes:
4. You implemented a train-test split with stratification, but the test set has a different class distribution than expected. What is the most likely cause?
medium
Solution
Step 1: Identify the role of stratification
Stratification ensures class distribution is maintained across splits.Step 2: Diagnose the issue
If the stratify parameter is not set correctly, class distribution will not be maintained.Final Answer:
Option B -> Option BQuick Check:
Check stratify parameter for distribution issues. [OK]
Hint: Check stratify parameter for distribution issues. [OK]
Common Mistakes:
5. How can you optimize the mAP calculation for a large dataset with thousands of images and bounding boxes?
hard
Solution
Step 1: Identify the Bottleneck
Calculating IoU for many boxes is computationally expensive.Step 2: Evaluate Optimization Strategies
Use parallel processing to compute IoU for each image: Parallel processing can significantly speed up IoU calculations. Reduce the number of bounding boxes by increasing the confidence threshold: Reducing boxes might miss important detections. Precompute IoU values for all possible box pairs: Precomputing is infeasible due to combinatorial explosion. Use a more efficient data structure for storing bounding boxes: Efficient data structures help but don't address computation directly.Final Answer:
Option A -> Option AQuick Check:
Parallelize IoU for large datasets [OK]
Hint: Parallelize IoU for large datasets [OK]
Common Mistakes:
