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 initialization impact
K-Means++ initialization helps in spreading initial centroids to avoid poor local minima.Step 2: Eliminate wrong options
Random initialization can lead to poor local minima. Using centroids from a previous run might not improve if the previous run was suboptimal. Initializing all centroids to the same point is clearly incorrect.Final Answer:
Option A -> Option AQuick Check:
K-Means++ spreads centroids well [OK]
import torch
rnn = torch.nn.RNN(input_size=10, hidden_size=20, num_layers=2)
input = torch.randn(5, 3, 10)
h0 = torch.randn(2, 3, 20)
output, hn = rnn(input, h0)
print(output.shape)Solution
Step 1: Understand RNN output shape.
The output shape of an RNN is (seq_len, batch, hidden_size).Step 2: Apply to the given code.
Here, seq_len=5, batch=3, hidden_size=20, so the output shape is (5, 3, 20).Final Answer:
Option D -> Option DQuick Check:
RNN output: (seq_len, batch, hidden_size). [check]
Solution
Step 1: Understand p-value definition
A p-value is the probability of observing the data, or something more extreme, given that the null hypothesis is true.Step 2: Eliminate wrong options
The probability that the null hypothesis is true. is incorrect because p-value is not the probability that the null hypothesis is true. The probability of the alternative hypothesis being true. is incorrect because it does not relate to the alternative hypothesis. The probability of making a Type I error. is incorrect because it confuses p-value with Type I error probability.Final Answer:
Option A -> Option AQuick Check:
P-value is about data given null hypothesis [OK]
Solution
Step 1: Identify the need for integration
A hybrid system allows for leveraging the strengths of both historical and real-time data.Step 2: Evaluate the options
Use a batch processing system to handle both data types simultaneously. does not effectively integrate real-time updates. Train separate models for historical and real-time data and average their predictions. may lead to inconsistent predictions. Rely solely on real-time data for predictions to ensure up-to-date results. ignores valuable historical data.Final Answer:
Option A -> Option AQuick Check:
Hybrid systems leverage both data types effectively. [OK]
