Practice
1.
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?easy
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]
Hint: LayerNorm keeps input shape. [OK]
Common Mistakes:
2.
import numpy as np
from sklearn.decomposition import PCA
X = np.array([[1, 2], [3, 4], [5, 6]])
pca = PCA(n_components=1)
X_transformed = pca.fit_transform(X)
print(X_transformed)What is the shape of X_transformed?easy
Solution
Step 1: Understand PCA output shape
PCA reduces the dimensionality of the data to the specified number of components.Step 2: Calculate the expected shape
With 3 samples and 1 component, the output shape is (3, 1).Final Answer:
Option D -> Option DQuick Check:
PCA output shape: (n_samples, n_components) [OK]
Hint: PCA output shape: (n_samples, n_components) [OK]
Common Mistakes:
3. For a real-time video surveillance system, which object detection model would be more suitable and why?
medium
Solution
Step 1: Identify system requirements
Real-time systems prioritize speed over marginal accuracy improvements.Step 2: Match model to requirements
YOLO is designed for fast processing, making it suitable for real-time applications.Final Answer:
Option C -> Option CQuick Check:
Real-time = Speed, choose YOLO [OK]
Hint: Real-time = Speed, choose YOLO [OK]
Common Mistakes:
4. When choosing between LSTM and GRU for a sequence modeling task, which scenario would favor using GRU over LSTM?
medium
Solution
Step 1: Compare LSTM and GRU.
GRUs are simpler and computationally more efficient than LSTMs.Step 2: Match to scenario.
GRU is preferred when computational efficiency is a priority.Final Answer:
Option A -> Option AQuick Check:
GRU is simpler, faster than LSTM. [check]
Hint: GRU is simpler, faster than LSTM. [check]
Common Mistakes:
5. You need to train a model with a learning rate that decreases over time. Which approach would best suit this requirement?
hard
Solution
Step 1: Identify the requirement.
The requirement is for a learning rate that decreases over time.Step 2: Match the requirement to the solution.
A learning rate scheduler with SGD allows for controlled decrease over time.Final Answer:
Option D -> Option DQuick Check:
Scheduler with SGD for decreasing lr. [check]
Hint: Scheduler with SGD for decreasing lr. [check]
Common Mistakes:
