Practice
1.
import torch
import torch.nn.functional as F
query = torch.tensor([[1.0, 0.0]])
key = torch.tensor([[0.5, 0.5], [1.0, 0.0]])
value = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
attention_scores = torch.matmul(query, key.T)
attention_weights = F.softmax(attention_scores, dim=-1)
output = torch.matmul(attention_weights, value)
print(output)What does this code output?easy
Solution
Step 1: Calculate attention scores.
Query-key dot product gives scores: [[0.5, 1.0]].Step 2: Apply softmax to scores.
Softmax gives weights: [[0.2689, 0.7311]].Step 3: Compute weighted sum of values.
Output = [[0.2689*1.0 + 0.7311*3.0, 0.2689*2.0 + 0.7311*4.0]] = [[1.5, 3.0]].Final Answer:
Option A -> Option AQuick Check:
Softmax weights applied to values. [OK]
Hint: Softmax weights applied to values. [OK]
Common Mistakes:
2. In the context of data labeling strategies, which method is best suited for generating large amounts of labeled data quickly but with potentially lower accuracy?
easy
Solution
Step 1: Understand the methods.
Human annotation is accurate but slow. Weak supervision uses heuristics or external data sources to generate labels quickly but may be less accurate.Step 2: Eliminate wrong options.
Programmatic labeling is similar to weak supervision but often requires more setup. Active learning involves human input and is not as fast.Final Answer:
Option A -> Option AQuick Check:
Weak supervision = fast, less accurate [OK]
Hint: Weak supervision = fast, less accurate [OK]
Common Mistakes:
3. In the context of Support Vector Machines, what is the primary purpose of the margin?
easy
Solution
Step 1: Understand the role of the margin
The margin in SVM is the distance between the decision boundary and the nearest data points from either class.Step 2: Eliminate wrong options
To minimize the number of support vectors is incorrect because the number of support vectors is not minimized. To ensure the model is non-linear is incorrect because the margin itself does not ensure non-linearity. To reduce the dimensionality of the data is incorrect because the margin does not reduce dimensionality.Final Answer:
Option B -> Option BQuick Check:
Margin maximizes boundary distance [OK]
Hint: Margin maximizes boundary distance [OK]
Common Mistakes:
4. You have a model that is overfitting. Which approach is more suitable to address this issue?
medium
Solution
Step 1: Identify methods to combat overfitting
Dropout is a regularization technique that helps prevent overfitting by randomly dropping units during training.Step 2: Eliminate wrong options
Increase the model complexity by adding more layers. increases overfitting risk, Reduce the size of the training dataset. reduces data, worsening generalization, and Use a smaller learning rate. affects convergence speed, not overfitting directly.Final Answer:
Option A -> Option AQuick Check:
Dropout reduces overfitting [OK]
Hint: Dropout reduces overfitting [OK]
Common Mistakes:
5. In a dataset with highly correlated features, which regularization technique is preferable and why?
medium
Solution
Step 1: Identify the issue with correlated features.
Highly correlated features can cause instability in L1 Lasso.Step 2: Choose the technique that addresses this.
Elastic Net combines L1 and L2, providing stability and feature selection.Step 3: Eliminate wrong options.
L1 Lasso struggles with multicollinearity. L2 Ridge does not select features. No regularization ignores the problem.Final Answer:
Option A -> Option AQuick Check:
Elastic Net = L1 + L2 for correlation. [OK]
Hint: Elastic Net = L1 + L2 for correlation. [OK]
Common Mistakes:
