PyTorch Deep Learning
- 30Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the fundamental definition of machine learning according to the course?
30 questions
- 1
What is the fundamental definition of machine learning according to the course?
Model answer
Machine learning is the process of turning data (images, text, numbers) into numbers and finding patterns in those numbers.
Explanation
This definition emphasizes the core idea of representing data numerically and then learning patterns from that representation.
- 2
How does supervised learning differ from traditional programming?
Model answer
Traditional programming uses inputs plus rules to produce outputs, while supervised learning uses inputs plus desired outputs to learn the rules (patterns).
Explanation
In supervised learning, the algorithm figures out the mapping from inputs to outputs by example, instead of being explicitly programmed.
- 3
When should you NOT use machine learning or deep learning? Provide two scenarios.
Model answer
When a simple rule-based system works well (e.g., a few steps to reproduce a recipe) or when errors are unacceptable (DL models are probabilistic, not deterministic).
Explanation
If a problem can be solved with a clear set of rules, ML/DL adds unnecessary complexity. And in high-stakes applications where zero errors are required, DL's inherent uncertainty is a drawback.
- 4
What type of data is deep learning best suited for, and what type is traditional machine learning best suited for?
Model answer
Deep learning is best for unstructured data (images, text, audio), while traditional machine learning (e.g., Random Forest, XGBoost) is best for structured data (tables of numbers).
Explanation
Neural networks excel at handling raw, unorganized data, whereas shallow algorithms often perform better on well-structured tabular data.
- 5
Describe the process by which a neural network takes input and produces an output.
Model answer
Input data is numerically encoded into a tensor, then passed through a neural network with input, hidden, and output layers. The network applies linear and nonlinear functions to learn patterns, and the output is converted into a human-understandable form.
Explanation
Each layer transforms the data, with hidden layers learning representations, and the final layer producing the output (e.g., a classification or regression value).
- 6
What is transfer learning, and why is it a powerful technique?
Model answer
Transfer learning takes patterns a model has learned from one dataset and applies them to a new, different problem. It is powerful because it allows leveraging pre-trained features, reducing the need for large amounts of data and training time.
Explanation
Instead of training from scratch, you start with a model already good at a related task and fine-tune it on your specific data.
- 7
What is PyTorch and what are its key features?
Model answer
PyTorch is a popular open-source deep learning framework developed by Facebook/Meta. It allows writing fast deep learning code in Python accelerated by GPUs, and provides pre-built models via
torch.hubandtorchvision.models.Explanation
PyTorch covers the entire ML stack: data preprocessing, model building, and deployment. It uses CUDA to leverage NVIDIA GPU acceleration.
- 8
What is a tensor in PyTorch?
Model answer
A tensor is a numerical representation of data and the fundamental building block in PyTorch. It can be a vector (1D), matrix (2D), or have higher dimensions.
Explanation
Tensors are used to encode input data, intermediate computations, and final outputs in neural networks.
- 9
List the seven main steps in the PyTorch workflow.
Model answer
- Data (preparing and loading) 2. Build/Pick a model 3. Fit the model to data 4. Make predictions (inference) 5. Evaluate the model 6. Improve through experimentation 7. Save and load the model.
Explanation
These steps provide a structured approach to any deep learning project, from data to deployment.
- 10
What are the roles of a loss function and an optimizer in the PyTorch workflow?
Model answer
The loss function measures how wrong the model's predictions are (lower is better). The optimizer adjusts the model's parameters to minimize the loss.
Explanation
Together, they drive the learning process: the loss gives a target, and the optimizer updates the weights to approach that target.
- 11
What are three common errors when working with PyTorch tensors and models?
Model answer
Wrong data type (dtype), wrong tensor shape, and wrong device (CPU vs GPU).
Explanation
These errors cause operations to fail silently or produce incorrect results. Always check dtype, shape, and device.
- 12
What is the rule for matrix multiplication when using
torch.mm(a, b)ora @ b?Model answer
The inner dimensions must match: for matrices of shape (a,b) and (b,c), the result is (a,c). If they don't match, transposing one may help.
Explanation
If shapes are (m,n) and (n,p), the product is (m,p). The inner dimension n must be equal.
- 13
How is a linear regression model built in PyTorch? Outline the key components of the
LinearRegressionModelclass.Model answer
Subclass
nn.Module, define__init__withnn.Parameterfor weight and bias, and implementforwardreturningweight * X + bias.Explanation
This manual approach teaches the underlying mechanics, though in practice
nn.Linearis used. - 14
Name the loss function and optimizer typically used for a regression problem in the course, and explain the purpose of the learning rate.
Model answer
Loss function:
nn.L1Loss()(MAE). Optimizer:torch.optim.SGD(). The learning rate is a hyperparameter that controls the size of parameter updates.Explanation
MAE measures absolute error; SGD updates weights in the direction opposite to the gradient, scaled by the learning rate.
- 15
List the five steps in the training loop for each epoch.
Model answer
- Forward pass (compute predictions) 2. Calculate loss 3. Optimizer zero gradients 4. Backpropagation (compute gradients) 5. Optimizer step (update parameters).
Explanation
This loop is the core of training: predict, measure, reset gradients, compute gradients, and update weights.
- 16
Why is
torch.inference_mode()used during evaluation, and what does it do?Model answer
It turns off gradient tracking, making computations faster and using less memory during inference.
Explanation
Gradients are not needed for evaluation, so disabling them improves performance without affecting results.
- 17
Describe the recommended way to save and load a PyTorch model.
Model answer
Save:
torch.save(model.state_dict(), 'model.pth'). Load: instantiate a new model and callnew_model.load_state_dict(torch.load('model.pth')).Explanation
Saving only the state dictionary (learned parameters) is efficient and avoids saving the entire model class.
- 18
What are the three types of classification problems covered in the course?
Model answer
Binary classification (two classes), multi-class classification (more than two but one label per sample), and multi-label classification (multiple labels per sample).
Explanation
These categories cover most real-world classification tasks, each requiring slight adjustments in output and loss.
- 19
What output activation functions are used for binary and multi-class classification, respectively?
Model answer
Binary:
torch.sigmoid()(outputs probability between 0 and 1). Multi-class:torch.softmax()(outputs probabilities summing to 1).Explanation
Sigmoid is suitable for probability of one class; softmax normalizes logits into a probability distribution over multiple classes.
- 20
What loss functions are recommended for binary and multi-class classification in PyTorch?
Model answer
Binary:
nn.BCEWithLogitsLoss(). Multi-class:nn.CrossEntropyLoss().Explanation
Both loss functions expect raw logits (not probabilities) for numerical stability; they internally apply sigmoid or softmax.
- 21
Describe the 'logits pipeline' from model output to final class label.
Model answer
Raw logits (linear output) → apply activation (sigmoid/softmax) to get prediction probabilities → convert to class labels (round for binary, argmax for multi-class).
Explanation
This pipeline ensures the model's raw scores are transformed into interpretable class predictions.
- 22
Why is non-linearity needed in neural networks? What is a common non-linear activation function?
Model answer
Without non-linearity, a network of only linear layers can only learn linear relationships. Non-linear activation functions like ReLU allow the network to learn complex patterns.
Explanation
ReLU turns negative values to zero and passes positives unchanged, introducing non-linearity while being computationally efficient.
- 23
What is the purpose of
torchvisionand what submodules does it contain for computer vision tasks?Model answer
torchvisionis the main domain library for computer vision. It includesdatasets(pre-built datasets),models(pre-trained architectures), andtransforms(image manipulation functions).Explanation
It provides convenient access to standard datasets, model architectures, and data preprocessing utilities.
- 24
What is the shape convention for images in PyTorch (with an example for FashionMNIST)?
Model answer
Shape is
[batch_size, color_channels, height, width]. For FashionMNIST, it is[batch_size, 1, 28, 28](grayscale).Explanation
Color channels: 1 for grayscale, 3 for RGB. This ordering is important for convolutional layers.
- 25
Why is batching used when training neural networks?
Model answer
Batching is computationally efficient (processing many samples at once) and provides more gradient updates per epoch (one per batch), speeding up learning.
Explanation
Processing batches instead of single samples utilizes GPU parallelism and reduces training time.
- 26
What is the purpose of the
nn.Conv2dlayer and what are its key hyperparameters?Model answer
nn.Conv2dlearns features by sliding a kernel (filter) over the image. Key hyperparameters:in_channels,out_channels(number of filters),kernel_size,stride, andpadding.Explanation
The kernel multiplies element-wise with input patches, and the output channels represent learned feature maps.
- 27
What does
nn.MaxPool2ddo and why is it used?Model answer
MaxPool2d is a non-learnable layer that downsamples the image by taking the maximum value from a small window (e.g., 2x2), reducing height and width.
Explanation
It reduces spatial dimensions, decreasing computation and making features more robust to small translations.
- 28
Outline the structure of the TinyVGG architecture used in the course.
Model answer
TinyVGG: Input → Conv Block 1 (Conv2d → ReLU → Conv2d → ReLU → MaxPool2d) → Conv Block 2 (same pattern) → Classifier (Flatten → Linear).
Explanation
This simple CNN follows a common pattern of convolutional blocks followed by fully connected layers for classification.
- 29
What three things should you always check if you encounter errors with custom image data in PyTorch?
Model answer
Data type (should be
float32), shape (should match model's expected input), and device (should be on same device as model).Explanation
These three are the most common sources of errors when working with image tensors.
- 30
How are the parameters of a model accessed and displayed (e.g., weight and bias)?
Model answer
Use
model.parameters()to view all parameters ormodel.state_dict()to see them as a dictionary of key-value pairs.Explanation
state_dictgives a clear view of each parameter's name and its tensor of values.

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