Practice
import torch
import torch.nn as nn
class SimpleModel(nn.Module):
def __init__(self):
super(SimpleModel, self).__init__()
self.features = nn.Sequential(
nn.Linear(512, 256),
nn.ReLU(),
nn.Linear(256, 128)
)
self.classifier = nn.Linear(128, 10)
def forward(self, x):
x = self.features(x)
x = self.classifier(x)
return x
model = SimpleModel()
input_data = torch.randn(32, 512)
output = model(input_data)
print(output.shape)Solution
Step 1: Trace the forward pass.
The input shape is (32, 512). After passing through the features, it becomes (32, 128). The classifier then outputs (32, 10).Step 2: Eliminate wrong options.
torch.Size([32, 512]) is incorrect because the output is not the same as the input. torch.Size([32, 256]) and C are intermediate shapes, not the final output.Final Answer:
Option C -> Option CQuick Check:
Final layer determines output shape. [check]
Solution
Step 1: Identify the role of batch size in Batch Normalization.
Batch Normalization relies on accurate batch statistics, which can be unreliable with small batch sizes.Step 2: Eliminate other causes.
The learning rate is too high, causing instability. is a common issue but not specific to Batch Norm. The model architecture is too deep, causing vanishing gradients. is unrelated to normalization. The dataset is imbalanced, affecting the normalization process. affects model performance but not directly related to Batch Norm instability.Final Answer:
Option A -> Option AQuick Check:
Small batch size causes unstable Batch Norm. [OK]
Solution
Step 1: Identify the task requirement
Highly heterogeneous node importance suggests the need for attention mechanisms.Step 2: Compare GCN and GAT
GAT uses attention to weigh node importance, unlike GCN.Final Answer:
Option B -> Option BQuick Check:
Use GAT for node importance heterogeneity. [check]
Solution
Step 1: Identify the constraint
Gradient Descent is more suitable for large datasets that don't fit in memory because it can process data in batches.Step 2: Eliminate wrong options
Least Squares is efficient for small datasets (A), interpretability is not a deciding factor (C), and noise handling depends on regularization, not the optimization method (D).Final Answer:
Option C -> Option CQuick Check:
Gradient Descent handles large datasets in batches. [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]
