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]
prompt = "Solve: 2 + 2 = ?\nLet's think step by step.\nFirst, we add 2 and 2.\nThe result is:"What will the model likely output?Solution
Step 1: Analyze the prompt
The prompt guides the model to solve the equation step-by-step, leading to the answer.Step 2: Eliminate wrong options
An error due to incomplete prompt. is incorrect as the prompt is complete. The model will output a step-by-step explanation. is incorrect because the prompt already provides steps. The model will output random numbers. is incorrect as the prompt is specific.Final Answer:
Option D -> Option DQuick Check:
Prompt guides to solve 2+2, answer is 4. [OK]
Solution
Step 1: Identify symptoms of vanishing gradients
Extremely small gradients often indicate the vanishing gradient problem, typically caused by certain activation functions like sigmoid or tanh.Step 2: Eliminate wrong options
The learning rate is too high. is incorrect because a high learning rate would cause divergence. The network is too shallow. is incorrect because a shallow network is less prone to vanishing gradients. The dataset is too small. is unrelated to gradient size.Final Answer:
Option C -> Option CQuick Check:
Small gradients often mean vanishing issue. [OK]
Solution
Step 1: Consider high-dimensional effects
In high dimensions, distance metrics often become less effective.Step 2: Eliminate wrong options
The model has too few neighbors. is incorrect as increasing neighbors may not help. The dataset is too small. is wrong because size isn't the main issue. The model is overfitting due to too many neighbors. is incorrect as overfitting is less likely with many neighbors.Final Answer:
Option B -> Option BQuick Check:
High dimensions dilute distance metrics. [OK]
Solution
Step 1: Identify the core ML task
Predicting future sales based on historical data aligns well with regression, which is suitable for continuous output prediction.Step 2: Eliminate wrong options
Use clustering to group similar products and predict demand is incorrect because clustering is unsupervised and doesn't predict demand. Use classification to categorize products into high and low demand is incorrect because classification is for discrete categories, not continuous predictions. Use reinforcement learning to dynamically adjust inventory levels is incorrect because reinforcement learning is complex and not necessary for static predictions.Final Answer:
Option A -> Option AQuick Check:
Use regression for continuous predictions like sales. [OK]
