1/25
A quick reference set covering common mistakes in Python coding practice, including tensor definitions, bias usage, and handling multiple conditions.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What is the correct way to define a tensor with torch.tensor?
Use a tuple with a single argument, enclosed in brackets ( ).
What common mistake happens when defining a tensor?
Forgetting that torch.tensor expects a tuple with just one argument.
How should you check for bias in a class method?
Use if self.bias: — always include self for class functions.
What is the role of self in Python class methods?
It ensures the method has access to the instance’s attributes and functions.
What should you be careful of when using multiple and and or statements?
Verify all possible cases and ensure logic is grouped correctly.
What happens if one of the conditions in a complex and/or chain isn’t satisfied?
The result may not behave as expected — test each case explicitly.
What is the shape of the weight matrix
(out_features, in_features)
How do you define self.weights
self.weights = nn.Parameters(torch.empty(out_featuree, in_features))
Bias parameter
self.register_parameter(“bias”, None)
Initializjing weights
nn.init.xavier_uniform(self.weight)
Matrix Multiplication
torch.nn.functional.linear(x, self.weight, self.bias)
What are Modules and Parameters
Modules is a nueral network
Parameter is weight for one layer.
Relu
torch.clamp(x, min=0)
Tanx
torch.ones_like(x)/ (torch.oneslike(x) + torch.exp(-x))
Leaky Relu
torch.where(x>=0, x, x*negative_slope)
Gradient is negative slope
What is channels in computer vision
self.channels = channels in the dataset that represent different features or color depths of the images, typically corresponding to RGB in color images.
How do you increase number of channels
Run multiple number of kernels in parallel.
Paramerters for kernel
stride, padding, kernel_size
What does x.shape for for compute rvision
batch_size, in_channels, input_h, input_w
Padding
x = F.pad(x,(padding[1],padding[1], padding[0]. padding[0]])
Symbol for integer multiplication
//
What does a*b do for tensors
It deoes elementwise multiplicaiton and not mtrix multiplixation.
How do you get sum of all entires in a matrix
torch.sum(a)
Max Pooling`
Runs a max kernel over the input. The max value is taken from each region covered by the kernel, reducing the dimensions of the input.