Practice
1. What does the following Python code output when implementing logistic regression with a sigmoid activation function?
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
z = np.array([0, 2, -2])
output = sigmoid(z)
print(output)easy
Solution
Step 1: Calculate sigmoid for each element
Sigmoid function is applied element-wise:sigmoid(0) = 0.5,sigmoid(2) ≈ 0.88,sigmoid(-2) ≈ 0.12.Step 2: Check precision of calculations
Common mistake is rounding errors. Correct values are[0.5, 0.880797, 0.119203], rounded to[0.5, 0.88, 0.12].Final Answer:
Option C -> Option CQuick Check:
Sigmoid(0)=0.5, Sigmoid(2)≈0.88, Sigmoid(-2)≈0.12 [OK]
Hint: Sigmoid(0)=0.5, Sigmoid(2)≈0.88, Sigmoid(-2)≈0.12 [OK]
Common Mistakes:
2. What is the time complexity of updating the embeddings for a single word pair in the Skip-Gram model with negative sampling?
easy
Solution
Step 1: Identify the operations involved
Updating embeddings involves computing gradients and updating weights for the target word and k negative samples.Step 2: Determine the complexity
Each update involves a constant number of operations per sample, leading to O(k) complexity where k is the number of negative samples.Final Answer:
Option A -> Option AQuick Check:
Complexity is O(k) due to k negative samples [OK]
Hint: Complexity is O(k) due to k negative samples [OK]
Common Mistakes:
3. You implemented linear regression using gradient descent, but the model is not converging. What is the most likely cause?
medium
Solution
Step 1: Identify symptoms of non-convergence
Non-convergence often results from oscillations due to a high learning rate.Step 2: Eliminate other options
Low learning rate causes slow convergence, not non-convergence. Dataset size and feature count affect overfitting, not convergence.Final Answer:
Option B -> Option BQuick Check:
High learning rate causes oscillations. [OK]
Hint: High learning rate causes oscillations. [OK]
Common Mistakes:
4. How can you optimize a naive 2D convolution implementation for large images and kernels?
hard
Solution
Step 1: Identify optimization techniques
Using FFT can significantly reduce the computational complexity of convolution from O(N^2 * K^2) to O(N^2 log N) for large images and kernels.Step 2: Eliminate wrong options
Use a larger stride to reduce computation. reduces output size, not computation. Increase the kernel size to cover more area. increases computation. Use a smaller kernel to decrease computation. limits kernel effectiveness.Final Answer:
Option C -> Option CQuick Check:
FFT reduces convolution complexity. [OK]
Hint: FFT reduces convolution complexity. [OK]
Common Mistakes:
5. How can you optimize the dropout layer implementation to reduce computational overhead during training?
hard
Solution
Step 1: Identify Optimization Opportunities
In-place operations reduce memory usage and computational overhead by modifying data directly.Step 2: Eliminate Wrong Options
Use a fixed mask for all training iterations. reduces randomness, harming model performance. Precompute masks for all layers before training. increases memory usage. Reduce the dropout rate to minimize mask application. changes model behavior, not efficiency.Final Answer:
Option A -> Option AQuick Check:
In-place operations save memory and time. [OK]
Hint: In-place operations save memory and time. [OK]
Common Mistakes:
