Practice
1. Given the following Python code snippet, what is the output?
import numpy as np
relevance_scores = [3, 2, 3, 0, 1, 2]
ideal_dcg = np.sum([3/np.log2(i+2) for i in range(len(relevance_scores))])
print(round(ideal_dcg, 2))easy
Solution
Step 1: Calculate the ideal DCG
Use the formula DCG = Σ(rel_i / log2(i+2)) for each relevance score.Step 2: Perform the calculation
3/1 + 2/1.585 + 3/2 + 0/2.322 + 1/2.585 + 2/2.807 = 6.86.Final Answer:
Option B -> Option BQuick Check:
DCG uses log2(i+2) for position i. [OK]
Hint: DCG uses log2(i+2) for position i. [OK]
Common Mistakes:
2. When choosing between Least Squares and Gradient Descent for linear regression, which scenario makes Gradient Descent more suitable?
medium
Solution
Step 1: Identify the constraint
Gradient Descent is more suitable for large datasets that don't fit in memory because it can process data in batches.Step 2: Eliminate wrong options
Least Squares is efficient for small datasets (A), interpretability is not a deciding factor (C), and noise handling depends on regularization, not the optimization method (D).Final Answer:
Option C -> Option CQuick Check:
Gradient Descent handles large datasets in batches. [OK]
Hint: Gradient Descent handles large datasets in batches. [OK]
Common Mistakes:
3. How would you adapt dropout for a recurrent neural network (RNN) to prevent overfitting without disrupting temporal dependencies?
hard
Solution
Step 1: Understand dropout in RNNs
Using the same dropout mask at each time step helps maintain temporal dependencies.Step 2: Eliminate wrong options
Apply dropout to the input and output layers only. is incorrect because it doesn't address hidden state dropout. Apply dropout to the hidden states at each time step. is incorrect because applying dropout to hidden states at each time step can disrupt dependencies. Increase the dropout rate progressively over time. is incorrect because increasing dropout rate over time is not a standard practice and can lead to underfitting.Final Answer:
Option D -> Option DQuick Check:
Same mask preserves RNN dependencies. [OK]
Hint: Same mask preserves RNN dependencies. [OK]
Common Mistakes:
4. You need to design a recurrent neural network for a real-time translation system. Which approach would best handle the vanishing gradient problem while maintaining low latency?
hard
Solution
Step 1: Consider latency and vanishing gradient.
GRUs are simpler and faster, reducing latency while handling vanishing gradients.Step 2: Evaluate other options.
Deep LSTM (A) increases latency, standard RNN (C) struggles with gradients, bidirectional LSTM (D) adds complexity and latency.Final Answer:
Option B -> Option BQuick Check:
GRU: fast, handles vanishing gradients. [check]
Hint: GRU: fast, handles vanishing gradients. [check]
Common Mistakes:
5. You are tasked with evaluating a model for a rare disease detection system. Which metric would you prioritize and why?
hard
Solution
Step 1: Consider the context
In rare disease detection, the minority class (disease cases) is critical.Step 2: Evaluate metric suitability
PR-AUC is more informative for minority class performance. ROC-AUC (A) and Accuracy (C) can be misleading. Log Loss (D) is useful but doesn't focus on minority class.Final Answer:
Option D -> Option DQuick Check:
PR-AUC for minority class focus. [OK]
Hint: PR-AUC for minority class focus. [OK]
Common Mistakes:
