Practice
1. You implemented early stopping in your training loop, but the model still overfits. What is the most likely reason?
medium
Solution
Step 1: Analyze early stopping behavior
Early stopping relies on validation performance to halt training.Step 2: Identify the root cause of overfitting
If the validation set is too small, it may not accurately reflect generalization, leading to overfitting despite early stopping.Final Answer:
Option A -> Option AQuick Check:
Small validation set can mislead early stopping. [OK]
Hint: Small validation set can mislead early stopping. [OK]
Common Mistakes:
2. In the implementation of Adam optimizer, the model is not converging. Which line of code is most likely causing the issue?
medium
Solution
Step 1: Identify the potential issue
The lineparameter -= learning_rate * m_hat / (np.sqrt(v_hat) + epsilon)is crucial for parameter updates. Ifepsilonis not properly set, it can cause division by zero or very small updates.Step 2: Eliminate other options
Options A, B, and C are standard parts of the Adam algorithm and unlikely to cause convergence issues unless there's a typo or logical error.Final Answer:
Option A -> Option AQuick Check:
Check epsilon in Adam's update step [OK]
Hint: Check epsilon in Adam's update step [OK]
Common Mistakes:
3. How can you optimize the computation of cosine similarity for a large dataset of vectors?
hard
Solution
Step 1: Identify computational bottlenecks
Looping over pairs is inefficient for large datasets.Step 2: Optimize using matrix operations
Precomputing norms and using matrix multiplication reduces redundant calculations.Final Answer:
Option C -> Option CQuick Check:
Matrix ops reduce redundancy. [OK]
Hint: Matrix ops reduce redundancy. [OK]
Common Mistakes:
4. 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:
5. How can you optimize the memory usage of a learned positional encoding implementation in PyTorch?
hard
Solution
Step 1: Consider memory optimization techniques
Using half-precision floating point reduces memory usage while maintaining sufficient precision for many applications.Step 2: Eliminate wrong options
Reduce the number of dimensions in the encoding. changes the model architecture. Use a sparse matrix for the encoding. is not applicable as the matrix is dense. Share the encoding matrix across multiple layers. may affect model performance and is not a direct memory optimization.Final Answer:
Option D -> Option DQuick Check:
Half-precision reduces memory without major precision loss. [OK]
Hint: Half-precision reduces memory without major precision loss. [OK]
Common Mistakes:
