Practice
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?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]
Solution
Step 1: Understand slice-based evaluation
Slice-based evaluation focuses on analyzing model performance on specific data subsets.Step 2: Eliminate wrong options
It reduces the overall training time of the model. is incorrect as slice-based evaluation doesn't affect training time. It automatically tunes hyperparameters for better performance. is incorrect because it doesn't involve hyperparameter tuning. It ensures the model is robust to adversarial attacks. is incorrect as it doesn't directly address adversarial robustness.Final Answer:
Option D -> Option DQuick Check:
Slice-based evaluation identifies weak data subsets. [OK]
Solution
Step 1: Identify the cause of performance drop.
Covariate drift can cause a sudden drop in performance if input distributions change.Step 2: Eliminate wrong options.
Overfitting (The model was overfitted to the training data.) and parameter count (The model has too many parameters.) would affect initial performance. Incorrect scaling (The feature scaling was incorrect.) would cause consistent issues, not sudden drops.Final Answer:
Option A -> Option AQuick Check:
Sudden drop? Check for covariate drift [OK]
Solution
Step 1: Identify high variance symptoms
High variance indicates overfitting, where the model performs well on training data but poorly on unseen data.Step 2: Choose the right approach
Adding more training data helps the model generalize better, reducing overfitting.Final Answer:
Option B -> Option BQuick Check:
High variance = more data [OK]
Solution
Step 1: Understand user behavior
Users watching only the first few videos means early precision is crucial.Step 2: Choose the metric
Precision at K directly measures the quality of the top K recommendations, aligning with user behavior.Final Answer:
Option A -> Option AQuick Check:
Precision at K focuses on top results. [OK]
