Practice
import torch
Q = torch.rand(2, 3, 4)
K = torch.rand(2, 4, 4)
V = torch.rand(2, 4, 5)
output = torch.matmul(torch.matmul(Q, K.transpose(-2, -1)), V)Solution
Step 1: Analyze matrix multiplications
The first multiplicationtorch.matmul(Q, K.transpose(-2, -1))results in a shape of (2, 3, 4). The second multiplication with V results in (2, 3, 5).Step 2: Eliminate wrong options
(2, 4, 5) is incorrect because it assumes incorrect dimensions for Q. (2, 3, 4) is incorrect because it doesn't account for the final multiplication with V. (2, 5, 5) is incorrect because it assumes incorrect dimensions for the final output.Final Answer:
Option D -> Option DQuick Check:
Check matrix dimensions after each multiplication. [OK]
Solution
Step 1: Analyze the problem
Poor performance on a specific slice often indicates distribution mismatch.Step 2: Eliminate wrong options
The model is overfitting to the training data. is incorrect as overfitting would affect overall performance. The model has too many parameters. is unrelated to slice-specific issues. The learning rate is too high. affects convergence, not slice performance.Final Answer:
Option A -> Option AQuick Check:
Slice mismatch = distribution issue. [OK]
Solution
Step 1: Consider computational efficiency.
Filter methods are computationally inexpensive as they do not involve training models.Step 2: Eliminate wrong options.
Wrapper methods and recursive feature elimination are computationally intensive. Embedded methods require model training, which can be resource-heavy.Final Answer:
Option D -> Option DQuick Check:
Filter = low cost, no model. [OK]
Solution
Step 1: Identify LSTM-specific issues.
Incorrect initialization of forget gate biases can lead to vanishing gradients.Step 2: Eliminate wrong options.
Too many layers can cause vanishing gradients, but it's not LSTM-specific. High learning rates cause exploding gradients, and dropout affects overfitting, not gradient flow.Final Answer:
Option A -> Option AQuick Check:
Forget gate bias affects gradient flow. [OK]
Solution
Step 1: Understand the need for balance.
Fraud detection requires a balance between catching frauds and minimizing false alarms.Step 2: Choose the metric that balances precision and recall.
F1 Score is the harmonic mean of precision and recall, providing a balance.Final Answer:
Option A -> Option AQuick Check:
F1 Score balances precision and recall. [OK]
