1. Home
  2. Explore
  3. Computer Science
  4. PyTorch Deep Learning

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

PyTorch Deep Learning

  • 30Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Core ML/DL Concepts

What is the fundamental definition of machine learning according to the course?

30 questions

  1. 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. 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. 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. 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. 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. 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. 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.hub and torchvision.models.

    Explanation

    PyTorch covers the entire ML stack: data preprocessing, model building, and deployment. It uses CUDA to leverage NVIDIA GPU acceleration.

  8. 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. 9

    List the seven main steps in the PyTorch workflow.

    Model answer
    1. 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. 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. 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. 12

    What is the rule for matrix multiplication when using torch.mm(a, b) or a @ b?

    Model answer

    The inner dimensions must match: for matrices of shape (a,b)(a, b)(a,b) and (b,c)(b, c)(b,c), the result is (a,c)(a, c)(a,c). If they don't match, transposing one may help.

    Explanation

    If shapes are (m,n)(m, n)(m,n) and (n,p)(n, p)(n,p), the product is (m,p)(m, p)(m,p). The inner dimension nnn must be equal.

  13. 13

    How is a linear regression model built in PyTorch? Outline the key components of the LinearRegressionModel class.

    Model answer

    Subclass nn.Module, define __init__ with nn.Parameter for weight and bias, and implement forward returning weight * X + bias.

    Explanation

    This manual approach teaches the underlying mechanics, though in practice nn.Linear is used.

  14. 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. 15

    List the five steps in the training loop for each epoch.

    Model answer
    1. 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. 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. 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 call new_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. 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. 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. 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. 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. 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. 23

    What is the purpose of torchvision and what submodules does it contain for computer vision tasks?

    Model answer

    torchvision is the main domain library for computer vision. It includes datasets (pre-built datasets), models (pre-trained architectures), and transforms (image manipulation functions).

    Explanation

    It provides convenient access to standard datasets, model architectures, and data preprocessing utilities.

  24. 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. 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. 26

    What is the purpose of the nn.Conv2d layer and what are its key hyperparameters?

    Model answer

    nn.Conv2d learns features by sliding a kernel (filter) over the image. Key hyperparameters: in_channels, out_channels (number of filters), kernel_size, stride, and padding.

    Explanation

    The kernel multiplies element-wise with input patches, and the output channels represent learned feature maps.

  27. 27

    What does nn.MaxPool2d do 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. 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. 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. 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 or model.state_dict() to see them as a dictionary of key-value pairs.

    Explanation

    state_dict gives a clear view of each parameter's name and its tensor of values.

1 of 30
Question 1 of 30

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent