Practice
import torch.nn as nn
class MyModel(nn.Module):
def __init__(self):
super(MyModel, self).__init__()
self.layer_norm = nn.LayerNorm(10)
def forward(self, x):
return self.layer_norm(x)
model = MyModel()
input_tensor = torch.randn(5, 10)
output = model(input_tensor)
print(output.shape)What is the output shape of the above code?Solution
Step 1: Analyze the LayerNorm application.
LayerNorm normalizes across the last dimension, maintaining the input shape.Step 2: Determine the output shape.
The input tensor has shape (5, 10), and LayerNorm does not alter the shape, so the output is also (5, 10).Final Answer:
Option C -> Option CQuick Check:
LayerNorm keeps input shape. [OK]
Solution
Step 1: Identify the role of positional encodings.
Positional encodings provide sequence order information, crucial for context.Step 2: Eliminate wrong options.
The model's attention heads are not properly initialized. is incorrect as initialization affects convergence, not context. The model's feedforward layers are too shallow. is incorrect because feedforward depth affects capacity, not context. The model's dropout rate is too high. is incorrect as dropout affects regularization, not context.Final Answer:
Option B -> Option BQuick Check:
Positional encodings ensure context. [OK]
Solution
Step 1: Identify overfitting causes.
Data leakage during feature selection can lead to overfitting as the model sees information from the validation set.Step 2: Eliminate wrong options.
Too few features usually lead to underfitting. An inappropriate scoring function affects feature ranking, not directly overfitting. High variance can cause overfitting but is not specific to wrapper methods.Final Answer:
Option A -> Option AQuick Check:
Data leakage = overfitting risk. [OK]
Solution
Step 1: Identify convergence issues
Centroids initialized too close can cause slow convergence or getting stuck in local minima.Step 2: Eliminate other causes
Too many clusters can cause overfitting but not convergence issues. Data normalization affects distance calculation but not convergence. Euclidean distance is standard for K-Means.Final Answer:
Option A -> Option AQuick Check:
Close centroids = slow convergence [OK]
Solution
Step 1: Analyze the metrics
ROC-AUC can be misleading in imbalanced datasets as it doesn't focus on the minority class.Step 2: Eliminate wrong options
Overfitting (A) and underfitting (D) are not directly related to the discrepancy between ROC-AUC and minority class performance. High bias (C) would affect overall performance, not just minority class.Final Answer:
Option A -> Option AQuick Check:
ROC-AUC can mislead in imbalanced datasets. [OK]
