Practice
1. Given the following PyTorch code snippet, what will be the output shape of the gradient for
W after backpropagation?import torch
W = torch.tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True)
x = torch.tensor([1.0, 2.0])
y = W @ x
loss = y.sum()
loss.backward()easy
Solution
Step 1: Determine the gradient shape
The gradient ofWwill have the same shape asW, which is (2, 2).Step 2: Eliminate wrong options
(2,) is incorrect because it suggests a vector shape. (2, 1) and D are incorrect because they suggest mismatched dimensions.Final Answer:
Option A -> Option AQuick Check:
Gradient shape matches tensor shape. [OK]
Hint: Gradient shape matches tensor shape. [OK]
Common Mistakes:
2. What will be the output shape of the following code snippet using K-Fold cross-validation with 5 splits on a dataset of 100 samples?
from sklearn.model_selection import KFold
kf = KFold(n_splits=5)
for train_index, test_index in kf.split(range(100)):
print(len(test_index))easy
Solution
Step 1: Calculate the number of samples per fold.
100 samples divided by 5 splits results in 20 samples per fold.Step 2: Eliminate wrong options.
25 samples per fold (B) is incorrect, 6 outputs (C) is incorrect, 4 outputs (D) is incorrect.Final Answer:
Option A -> Option AQuick Check:
100 samples, 5 splits = 20 per fold. [OK]
Hint: 100 samples, 5 splits = 20 per fold. [OK]
Common Mistakes:
3. In the context of MLflow, which component is primarily responsible for storing and managing model artifacts?
easy
Solution
Step 1: Identify the role of each MLflow component
MLflow Registry is designed to store and manage model artifacts.Step 2: Eliminate wrong options
MLflow Tracking logs metrics and parameters, MLflow Projects handles reproducibility, and MLflow Models deals with model packaging.Final Answer:
Option A -> Option AQuick Check:
Registry = Artifacts [OK]
Hint: Registry = Artifacts [OK]
Common Mistakes:
4.
import numpy as np
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
result = np.dot(x, y)
print(result)What does this code output?easy
Solution
Step 1: Understand the dot product operation.
The dot product of two vectors is the sum of the products of their corresponding elements.Step 2: Calculate the dot product.
(1*4) + (2*5) + (3*6) = 32.Final Answer:
Option C -> Option CQuick Check:
Dot product sums element-wise products. [OK]
Hint: Dot product sums element-wise products. [OK]
Common Mistakes:
5. 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:
