Practice
1.
import numpy as np
data = np.array([1, 2, 3, 4, 5])
mean = np.mean(data)
std = np.std(data)
standardized_data = (data - mean) / std
print(standardized_data)What does the code output?easy
Solution
Step 1: Understand Standardization
Standardization transforms data to have a mean of 0 and a standard deviation of 1.Step 2: Calculate the Output
The standardized values are calculated as (data - mean) / std, resulting in [-1.41, -0.71, 0, 0.71, 1.41].Final Answer:
Option C -> Option CQuick Check:
Standardization centers data around 0. [OK]
Hint: Standardization centers data around 0. [OK]
Common Mistakes:
2.
import numpy as np
def numerical_gradient(f, x):
h = 1e-4
grad = np.zeros_like(x)
for i in range(x.size):
x[i] += h
fxh1 = f(x)
x[i] -= 2 * h
fxh2 = f(x)
grad[i] = (fxh1 - fxh2) / (2 * h)
x[i] += h
return grad
# Test function
f = lambda x: x[0]**2 + x[1]**2
x = np.array([3.0, 4.0])
print(numerical_gradient(f, x))easy
Solution
Step 1: Understand the numerical gradient calculation
The function calculates the gradient using central difference approximation.Step 2: Calculate the gradient for each element
For x = [3.0, 4.0], the gradient is [6.0, 8.0] because the derivative of x^2 is 2x.Final Answer:
Option A -> Option AQuick Check:
Central difference gives exact gradient for quadratic. [OK]
Hint: Central difference gives exact gradient for quadratic. [OK]
Common Mistakes:
3. What is the time complexity of generating a sinusoidal positional encoding matrix of size
position x d_model?easy
Solution
Step 1: Analyze the operations
The code iterates over each position and each dimension, performing constant-time operations.Step 2: Eliminate wrong options
O(position^2) is incorrect because the complexity is not quadratic in position. O(d_model^2) is incorrect because the complexity is not quadratic in d_model. O(1) is incorrect because the complexity is not constant.Final Answer:
Option C -> Option CQuick Check:
Iterate over position and dimension. [OK]
Hint: Iterate over position and dimension. [OK]
Common Mistakes:
4. In a multi-class classification problem, how should precision and recall be calculated from a confusion matrix?
medium
Solution
Step 1: Understand multi-class metrics
Precision and recall should be calculated for each class separately.Step 2: Determine the correct aggregation method
Average the precision and recall across all classes to get a balanced view.Final Answer:
Option A -> Option AQuick Check:
Average class-wise metrics for multi-class. [OK]
Hint: Average class-wise metrics for multi-class. [OK]
Common Mistakes:
5. How can you optimize the numerical gradient computation for a large neural network?
hard
Solution
Step 1: Identify optimization strategies for numerical gradient computation
Parallelizing the computation can significantly reduce time for large networks.Step 2: Eliminate ineffective strategies
Options A, C, and D do not directly optimize the gradient computation process.Final Answer:
Option B -> Option BQuick Check:
Parallelize for large networks. [OK]
Hint: Parallelize for large networks. [OK]
Common Mistakes:
