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: Understand the role of the margin
The margin in SVM is the distance between the decision boundary and the nearest data points from either class.Step 2: Eliminate wrong options
To minimize the number of support vectors is incorrect because the number of support vectors is not minimized. To ensure the model is non-linear is incorrect because the margin itself does not ensure non-linearity. To reduce the dimensionality of the data is incorrect because the margin does not reduce dimensionality.Final Answer:
Option B -> Option BQuick Check:
Margin maximizes boundary distance [OK]
Solution
Step 1: Compare SHAP and LIME.
SHAP provides consistent and accurate explanations for complex models, while LIME is faster but less accurate for non-linear models.Step 2: Match the scenario to the technique.
SHAP is preferred for complex, non-linear models due to its accuracy and consistency.Final Answer:
Option D -> Option DQuick Check:
SHAP excels with complex, non-linear models. [OK]
Solution
Step 1: Identify when pretraining is less beneficial.
Pretraining is less useful when no relevant pretrained models exist.Step 2: Eliminate wrong options.
The task is similar to the one the pretrained model was trained on. favors using pretrained models due to task similarity. The task has a very large and diverse dataset available. also favors pretrained models due to data availability. The task requires real-time inference with minimal latency. is unrelated to the choice between pretraining and training from scratch.Final Answer:
Option A -> Option AQuick Check:
No pretrained model? Train from scratch. [check]
Solution
Step 1: Identify the goal
Effect size measures the magnitude of a feature's impact, not just its statistical significance.Step 2: Choose the correct metric
Cohen's d is a standard measure for effect size, especially in comparing means.Final Answer:
Option D -> Option DQuick Check:
Effect size? Use Cohen's d [OK]
