Practice
1.
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:
2. 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:
3. 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:
4. How can you optimize the computation of a confusion matrix for a large dataset with millions of predictions?
hard
Solution
Step 1: Identify bottleneck
Large datasets require efficient computation, often limited by CPU processing.Step 2: Choose optimization strategy
Parallel processing with Dask can distribute computation across cores.Final Answer:
Option B -> Option BQuick Check:
Parallel processing speeds up large data tasks. [OK]
Hint: Parallel processing speeds up large data tasks. [OK]
Common Mistakes:
5. How can you optimize the memory usage of a NumPy-based backpropagation implementation for a large neural network?
hard
Solution
Step 1: Identify memory bottlenecks
Intermediate results can consume significant memory.Step 2: Optimize memory usage
In-place operations reduce memory overhead by modifying data directly.Final Answer:
Option A -> Option AQuick Check:
In-place operations save memory [OK]
Hint: In-place operations save memory [OK]
Common Mistakes:
