Practice
import torch
x = torch.tensor([-1.0, 0.0, 1.0])
output = torch.nn.functional.relu(x)
print(output)What is the output of this code?Solution
Step 1: Understand ReLU behavior.
ReLU outputs zero for negative inputs and the input itself for non-negative inputs.Step 2: Apply ReLU to each element.
For -1.0, output is 0.0; for 0.0, output is 0.0; for 1.0, output is 1.0.Final Answer:
Option A -> Option AQuick Check:
ReLU zeros negatives, keeps positives. [OK]
Solution
Step 1: Identify the purpose of calibration.
Calibration aims to ensure that predicted probabilities reflect true likelihoods.Step 2: Evaluate each metric.
Accuracy, precision, and F1 score do not consider probability estimates, only classification decisions. Log Loss penalizes incorrect probability estimates, making it suitable for calibration.Final Answer:
Option C -> Option CQuick Check:
Log Loss evaluates probability accuracy. [OK]
import numpy as np
np.random.seed(0)
weights = [0.1, 0.3, 0.6]
choices = ['A', 'B', 'C']
result = np.random.choice(choices, p=weights)
print(result)Solution
Step 1: Understand weighted sampling.
np.random.choice with 'p' parameter uses specified probabilities for sampling.Step 2: Analyze the code.
Weights [0.1, 0.3, 0.6] mean 'C' is most likely, but not guaranteed.Final Answer:
Option A -> Option AQuick Check:
np.random.choice uses 'p' for weighted sampling [[check]]
Solution
Step 1: Analyze pooling impact
Without pooling, feature maps remain large, increasing model complexity and risk of overfitting.Step 2: Eliminate wrong options
Pooling layers are too aggressive, losing important features is incorrect because aggressive pooling would reduce overfitting. Pooling layers are applied after every convolutional layer is incorrect as regular pooling helps reduce overfitting. Pooling layers use a large stride, reducing model complexity is incorrect because large strides reduce complexity, not increase it.Final Answer:
Option B -> Option BQuick Check:
No pooling increases overfitting risk. [OK]
Solution
Step 1: Compare LSTM and GRU.
GRU is simpler and often faster due to fewer parameters, making it suitable for limited resources.Step 2: Eliminate wrong options.
LSTM's complexity isn't always needed, GRU isn't always more accurate, and LSTM's longer sequence handling isn't a universal advantage.Final Answer:
Option C -> Option CQuick Check:
GRU: fewer parameters, faster. [OK]
