PyTorch Deep Learning
- 30Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the core philosophy of the course?
What is the core philosophy of the course?
30 questions
- 1
What is the core philosophy of the course?
- A
If in doubt, run the code
- B
First understand theory, then practice
- C
Read the documentation thoroughly before coding
- D
Always use pre-trained models
Correct answer
AIf in doubt, run the code
Explanation
The course motto is 'If in doubt, run the code,' emphasizing learning by writing code.
- A
- 2
What is the target audience for this course?
- A
Complete beginners with no programming experience
- B
Intermediate Python developers with ML experience
- C
Beginners with 3-6 months of Python experience
- D
Advanced deep learning researchers
Correct answer
CBeginners with 3-6 months of Python experience
Explanation
The course is designed for beginners with 3-6 months of Python experience.
- A
- 3
Where are the course materials available for free?
- A
On the Zero to Mastery platform
- B
On YouTube only
- C
On the instructor's personal website
- D
On GitHub and an online readable book at learnpytorch.io
Correct answer
DOn GitHub and an online readable book at learnpytorch.io
Explanation
Course materials are available on GitHub (mrdbourke/pytorch-deep-learning) and as an online book at learnpytorch.io.
- A
- 4
According to the course, what is machine learning?
- A
Writing explicit rules for data processing
- B
Using GPUs to accelerate computations
- C
Turning data into numbers and finding patterns in those numbers
- D
Building neural networks with many layers
Correct answer
CTurning data into numbers and finding patterns in those numbers
Explanation
Machine learning is defined as turning data (anything) into numbers and finding patterns in those numbers.
- A
- 5
In supervised learning, what does the model learn?
- A
The rules that map inputs to outputs given labeled data
- B
The optimal hyperparameters for the neural network
- C
The probability distribution of the input features
- D
The structure of data without any labels
Correct answer
AThe rules that map inputs to outputs given labeled data
Explanation
In supervised learning, the model learns the mapping (rules) from inputs to desired outputs using labeled data.
- A
- 6
When should you NOT use machine learning or deep learning?
- A
When the environment continually changes
- B
When you have a large dataset
- C
When the problem has complex, long lists of rules
- D
When the problem requires explainability
Correct answer
DWhen the problem requires explainability
Explanation
DL models are often uninterpretable, so they should not be used when explainability is required. A simple rule-based system is preferred when possible.
- A
- 7
What type of data are deep learning models best suited for?
- A
Unstructured data such as images, text, and audio
- B
Structured data such as tables of numbers
- C
Time series data with regular patterns
- D
Only numerical data with few features
Correct answer
AUnstructured data such as images, text, and audio
Explanation
Deep learning excels at unstructured data (images, text, audio), while traditional ML works better on structured data.
- A
- 8
What is transfer learning?
- A
Using a single model for both regression and classification
- B
Transferring data from CPU to GPU for faster training
- C
Applying patterns learned from one dataset to a different problem
- D
Learning multiple tasks simultaneously
Correct answer
CApplying patterns learned from one dataset to a different problem
Explanation
Transfer learning takes patterns a model has learned from one dataset and applies them to a new, different problem.
- A
- 9
What is a tensor in PyTorch?
- A
A type of neural network layer
- B
The fundamental numerical representation of data
- C
A hyperparameter that controls learning rate
- D
A function that calculates gradients
Correct answer
BThe fundamental numerical representation of data
Explanation
A tensor is the fundamental building block of data in PyTorch; it is a numerical representation that can be a vector, matrix, or higher-dimensional array.
- A
- 10
What does PyTorch use to leverage GPU acceleration?
- A
TensorFlow
- B
OpenCL
- C
CUDA
- D
DirectX
Correct answer
CCUDA
Explanation
PyTorch uses CUDA, an interface for NVIDIA GPUs, to accelerate numerical computations.
- A
- 11
Which company originally developed PyTorch?
- A
Microsoft
- B
Amazon
- C
Google
- D
Facebook (Meta)
Correct answer
DFacebook (Meta)
Explanation
PyTorch was developed by Facebook (now Meta) and is open-sourced.
- A
- 12
What is the correct way to save and load a PyTorch model?
- A
Save the entire model object with torch.save(model, 'model.pth')
- B
Use model.save() and model.load() methods
- C
Save the model's architecture separately and weights in a JSON file
- D
Save only the state_dict with torch.save(model.state_dict(), 'model.pth') then load with load_state_dict
Correct answer
DSave only the state_dict with torch.save(model.state_dict(), 'model.pth') then load with load_state_dict
Explanation
The recommended way is to save the model's state_dict (learned parameters) and load it into a new model instance.
- A
- 13
In a PyTorch training loop, what is the purpose of optimizer.zero_grad()?
- A
To move the model to the GPU
- B
To reset the gradients of model parameters before backpropagation
- C
To initialize the model parameters
- D
To stop training after reaching a loss threshold
Correct answer
BTo reset the gradients of model parameters before backpropagation
Explanation
optimizer.zero_grad() resets the gradients to zero before computing new gradients in backpropagation, preventing accumulation from previous iterations.
- A
- 14
What is the correct order of steps in a training loop for one epoch?
- A
Backward pass, optimizer step, forward pass, zero grad
- B
Forward pass, backward pass, zero grad, optimizer step
- C
Forward pass, calculate loss, zero grad, backward pass, optimizer step
- D
Zero grad, forward pass, backward pass, optimizer step
Correct answer
CForward pass, calculate loss, zero grad, backward pass, optimizer step
Explanation
The correct order is: forward pass, calculate loss, optimizer.zero_grad(), loss.backward(), optimizer.step().
- A
- 15
Why is torch.inference_mode() used during testing?
- A
To turn off gradient tracking for faster computation
- B
To convert the model to evaluation mode
- C
To enable dropout for better generalization
- D
To automatically adjust the learning rate
Correct answer
ATo turn off gradient tracking for faster computation
Explanation
torch.inference_mode() disables gradient tracking, making forward passes faster and reducing memory usage.
- A
- 16
Which loss function is recommended for binary classification in PyTorch?
- A
nn.L1Loss()
- B
nn.BCEWithLogitsLoss()
- C
nn.BCELoss()
- D
nn.CrossEntropyLoss()
Correct answer
Bnn.BCEWithLogitsLoss()
Explanation
nn.BCEWithLogitsLoss() is numerically more stable because it combines a sigmoid layer with binary cross-entropy loss.
- A
- 17
What activation function is used in the output layer for multi-class classification?
- A
Softmax
- B
ReLU
- C
Sigmoid
- D
Tanh
Correct answer
ASoftmax
Explanation
Softmax converts logits to probabilities that sum to 1, suitable for multi-class classification.
- A
- 18
What is the purpose of non-linear activation functions like ReLU in a neural network?
- A
To convert probabilities to class labels
- B
To introduce non-linearity so the network can learn complex patterns
- C
To reduce overfitting by adding randomness
- D
To increase the number of parameters
Correct answer
BTo introduce non-linearity so the network can learn complex patterns
Explanation
Non-linear activation functions allow the network to learn non-linear relationships; without them, the network would only be able to learn linear patterns.
- A
- 19
What does the nn.Linear layer learn?
- A
A non-linear transformation using ReLU
- B
A linear transformation of the input using weights and biases
- C
A convolutional filter on image data
- D
A pooling operation to downsample
Correct answer
BA linear transformation of the input using weights and biases
Explanation
nn.Linear applies a linear transformation: y = xW^T + b, where weights and biases are learnable parameters.
- A
- 20
In the logits pipeline, how do you convert logits to prediction labels for binary classification?
- A
Apply tanh then take sign
- B
Apply sigmoid then round to 0 or 1
- C
Apply ReLU then threshold at 0
- D
Apply softmax then take argmax
Correct answer
BApply sigmoid then round to 0 or 1
Explanation
Logits are passed through sigmoid to get probabilities, then rounded (threshold 0.5) to obtain binary labels.
- A
- 21
What is the shape of a single image in the FashionMNIST dataset?
- A
28x28 with 3 color channels
- B
28x28 with 1 color channel
- C
64x64 with 1 color channel
- D
32x32 with 3 color channels
Correct answer
B28x28 with 1 color channel
Explanation
FashionMNIST consists of 28x28 grayscale images, so a single image has shape [1, 28, 28] (channels, height, width).
- A
- 22
Why is batching used when training with DataLoader?
- A
To shuffle the data randomly once per epoch
- B
To reduce the total number of training epochs
- C
To ensure the model sees all data before updating parameters
- D
To process data in smaller chunks for computational efficiency and more frequent gradient updates
Correct answer
DTo process data in smaller chunks for computational efficiency and more frequent gradient updates
Explanation
Batching makes computation more efficient (vectorization) and provides more gradient updates per epoch, leading to faster convergence.
- A
- 23
What does nn.Conv2d learn?
- A
A single value per channel after global average pooling
- B
Local patterns by sliding a kernel across the image
- C
A set of global weights for all spatial locations
- D
The spatial arrangement of pixels
Correct answer
BLocal patterns by sliding a kernel across the image
Explanation
Conv2d learns filters (kernels) that slide across the input image to detect local features like edges, textures, etc.
- A
- 24
What is the purpose of nn.MaxPool2d in a CNN?
- A
To increase the number of feature maps
- B
To learn non-linear transformations
- C
To apply dropout for regularization
- D
To reduce the spatial dimensions (height and width) by taking the maximum in a window
Correct answer
DTo reduce the spatial dimensions (height and width) by taking the maximum in a window
Explanation
MaxPool2d downsamples the feature map by taking the maximum value in each local window, reducing spatial size and providing translation invariance.
- A
- 25
In the TinyVGG architecture, what follows the convolutional blocks before the classifier?
- A
A fully connected layer
- B
A dropout layer
- C
A flatten layer
- D
A global average pooling layer
Correct answer
CA flatten layer
Explanation
After the convolutional blocks, a Flatten layer is used to convert the 2D feature maps into a 1D vector for the linear classifier.
- A
- 26
What is the correct order of the three common errors in PyTorch?
- A
Wrong shape, wrong data type, wrong device
- B
Wrong device, wrong data type, wrong shape
- C
Wrong shape, wrong device, wrong data type
- D
Wrong data type, wrong shape, wrong device
Correct answer
DWrong data type, wrong shape, wrong device
Explanation
The top 3 errors are: wrong data type (dtype), wrong shape, and wrong device (CPU/GPU mismatch).
- A
- 27
What is the result of a matrix multiplication between tensors of shape (3,2) and (2,4)?
- A
A tensor of shape (3,2)
- B
A tensor of shape (3,4)
- C
Invalid because inner dimensions do not match
- D
A tensor of shape (2,2)
Correct answer
BA tensor of shape (3,4)
Explanation
For (3,2) @ (2,4), inner dimensions (2 and 2) match, and the result has shape (3,4) (outer dimensions).
- A
- 28
Which function is used to create a custom dataset in PyTorch?
- A
torch.utils.data.TensorDataset
- B
torch.utils.data.Dataset
- C
torch.utils.data.DataLoader
- D
torchvision.datasets
Correct answer
Btorch.utils.data.Dataset
Explanation
Custom datasets are created by subclassing torch.utils.data.Dataset and implementing len and getitem.
- A
- 29
What is the default learning rate value commonly used as a starting point?
- A
0.001
- B
0.01
- C
0.1
- D
0.0001
Correct answer
B0.01
Explanation
A common starting learning rate is 0.01 for SGD, though it may need tuning.
- A
- 30
What does the nn.L1Loss() function compute?
- A
Mean squared error between predictions and targets
- B
Huber loss combining MSE and MAE
- C
Cross entropy loss for classification
- D
Mean absolute error between predictions and targets
Correct answer
DMean absolute error between predictions and targets
Explanation
nn.L1Loss() computes the mean absolute error (MAE), which is the average of absolute differences.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.