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: Compare GELU and ReLU characteristics.
GELU provides smoother gradients due to its probabilistic nature, which can help in convergence.Step 2: Evaluate each option.
GELU is not cheaper (A), doesn't entirely avoid dying neurons (C), and isn't more interpretable (D).Final Answer:
Option D -> Option DQuick Check:
GELU smooths gradients, aids convergence. [OK]
Solution
Step 1: Understand slice-based evaluation trade-offs
More slices can provide detailed insights but may reduce interpretability.Step 2: Eliminate wrong options
Balancing model complexity with training time. is unrelated to slice evaluation. Balancing data augmentation with overfitting. is about data augmentation, not slicing. Balancing feature selection with model accuracy. is about feature selection, not slicing.Final Answer:
Option C -> Option CQuick Check:
More slices = less interpretability. [OK]
Solution
Step 1: Identify focal loss dependency.
Focal loss requires tuning of its parameters (gamma, alpha) to be effective.Step 2: Eliminate other causes.
High learning rate and underfitting are general issues, not specific to focal loss. Dataset imbalance is assumed.Final Answer:
Option A -> Option AQuick Check:
Focal loss needs parameter tuning. [OK]
Solution
Step 1: Apply the No Free Lunch Theorem
The theorem suggests no single model is best for all scenarios, so testing is essential.Step 2: Eliminate wrong options
Use the same model that worked for the previous user base. is incorrect because past success doesn't guarantee future performance. Increase the model complexity to handle diverse user preferences. is incorrect because complexity doesn't ensure better results. Rely on collaborative filtering as it works well for recommendations. is incorrect because collaborative filtering isn't universally optimal.Final Answer:
Option C -> Option CQuick Check:
Test models with new data. [OK]
