Practice
1. In a dataset with both categorical and numerical features, which scaling method is most appropriate?
medium
Solution
Step 1: Identify Feature Types
Numerical features benefit from scaling, while categorical features require encoding.Step 2: Choose Appropriate Methods
Min-Max scaling is suitable for numerical features, and one-hot encoding is standard for categorical features.Final Answer:
Option B -> Option BQuick Check:
Scale numerical, encode categorical. [OK]
Hint: Scale numerical, encode categorical. [OK]
Common Mistakes:
2. In the following learned positional encoding implementation, the model is not learning as expected. What is the most likely cause?
import torch
import torch.nn as nn
class LearnedPositionalEncoding(nn.Module):
def __init__(self, max_len, d_model):
super().__init__()
self.positional_encoding = nn.Parameter(torch.zeros(max_len, d_model))
def forward(self, x):
return x + self.positional_encoding[:x.size(1), :]
model = LearnedPositionalEncoding(100, 512)
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)medium
Solution
Step 1: Identify the initialization issue
The positional encoding is initialized to zeros, which may not provide a useful starting point for learning.Step 2: Eliminate wrong options
The learning rate is too low. is incorrect because the learning rate is standard. The optimizer is not suitable for this task. is incorrect because Adam is generally suitable. The positional encoding is not being updated. is incorrect because the parameter is part of the model and should be updated.Final Answer:
Option A -> Option AQuick Check:
Check initialization of learned parameters. [OK]
Hint: Check initialization of learned parameters. [OK]
Common Mistakes:
3. In a dataset with highly imbalanced classes, how should you implement train-test split with stratification to ensure robust model evaluation?
medium
Solution
Step 1: Understand stratification in imbalanced datasets
Stratification should focus on maintaining the distribution of the minority class.Step 2: Apply correct strategy
Ensuring stratification based on the minority class helps in capturing its distribution in both sets.Final Answer:
Option A -> Option AQuick Check:
Stratify on minority class for balance. [OK]
Hint: Stratify on minority class for balance. [OK]
Common Mistakes:
4. How can you optimize the memory usage of a Min-Max scaling implementation for a large dataset?
hard
Solution
Step 1: Identify Memory Bottlenecks
Loading large datasets entirely into memory can be inefficient.Step 2: Optimize Memory Usage
Processing data in chunks reduces memory footprint, making it feasible to handle large datasets.Final Answer:
Option A -> Option AQuick Check:
Chunk processing saves memory. [OK]
Hint: Chunk processing saves memory. [OK]
Common Mistakes:
5. How can you optimize the memory usage of a learned positional encoding implementation in PyTorch?
hard
Solution
Step 1: Consider memory optimization techniques
Using half-precision floating point reduces memory usage while maintaining sufficient precision for many applications.Step 2: Eliminate wrong options
Reduce the number of dimensions in the encoding. changes the model architecture. Use a sparse matrix for the encoding. is not applicable as the matrix is dense. Share the encoding matrix across multiple layers. may affect model performance and is not a direct memory optimization.Final Answer:
Option D -> Option DQuick Check:
Half-precision reduces memory without major precision loss. [OK]
Hint: Half-precision reduces memory without major precision loss. [OK]
Common Mistakes:
