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]
from sklearn.tree import DecisionTreeClassifier
import numpy as np
X = np.array([[0, 0], [1, 1], [1, 0], [0, 1]])
y = np.array([0, 1, 1, 0])
clf = DecisionTreeClassifier(criterion='gini')
clf.fit(X, y)
print(clf.predict([[0, 0], [1, 1]]))What is the output of the above code?Solution
Step 1: Understand the training data.
The data is perfectly separable, and the decision tree will learn to classify based on the given labels.Step 2: Predict using the trained model.
For input [0, 0], the label is 0, and for [1, 1], the label is 1.Final Answer:
Option C -> Option CQuick Check:
Check training labels for predictions. [OK]
import numpy as np
data = np.array([1, 2, 3, 4, 5])
mask = data > 3
result = data[mask]
print(result)Solution
Step 1: Understand the code logic
The mask is applied to filter elements greater than 3.Step 2: Determine the output
Only elements 4 and 5 satisfy the condition, so result is [4, 5].Final Answer:
Option A -> Option AQuick Check:
Mask filters elements > 3. [OK]
Solution
Step 1: Identify the best approach for handling label drift.
A feedback loop allows the model to adapt to changes in label distribution by learning from recent interactions.Step 2: Eliminate wrong options.
Static mappings (Use a static label mapping based on historical data.) and increasing dataset size (Increase the size of the training dataset.) don't adapt to real-time changes. Feature selection (Apply feature selection to reduce dimensionality.) doesn't address label drift.Final Answer:
Option A -> Option AQuick Check:
Feedback loop adapts to label drift [OK]
Solution
Step 1: Identify the requirements.
Real-time systems require low latency and high throughput.Step 2: Choose the approach that meets these requirements.
Online learning with a streaming framework allows for real-time updates and low latency.Final Answer:
Option A -> Option AQuick Check:
Streaming fits real-time needs. [OK]
