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: Course Introduction

What is the core philosophy of the course?

30 questions

  1. 1

    What is the core philosophy of the course?

    1. A

      If in doubt, run the code

    2. B

      First understand theory, then practice

    3. C

      Read the documentation thoroughly before coding

    4. D

      Always use pre-trained models

    Correct answer
    A

    If in doubt, run the code

    Explanation

    The course motto is 'If in doubt, run the code,' emphasizing learning by writing code.

  2. 2

    What is the target audience for this course?

    1. A

      Complete beginners with no programming experience

    2. B

      Intermediate Python developers with ML experience

    3. C

      Beginners with 3-6 months of Python experience

    4. D

      Advanced deep learning researchers

    Correct answer
    C

    Beginners with 3-6 months of Python experience

    Explanation

    The course is designed for beginners with 3-6 months of Python experience.

  3. 3

    Where are the course materials available for free?

    1. A

      On the Zero to Mastery platform

    2. B

      On YouTube only

    3. C

      On the instructor's personal website

    4. D

      On GitHub and an online readable book at learnpytorch.io

    Correct answer
    D

    On 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.

  4. 4

    According to the course, what is machine learning?

    1. A

      Writing explicit rules for data processing

    2. B

      Using GPUs to accelerate computations

    3. C

      Turning data into numbers and finding patterns in those numbers

    4. D

      Building neural networks with many layers

    Correct answer
    C

    Turning 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.

  5. 5

    In supervised learning, what does the model learn?

    1. A

      The rules that map inputs to outputs given labeled data

    2. B

      The optimal hyperparameters for the neural network

    3. C

      The probability distribution of the input features

    4. D

      The structure of data without any labels

    Correct answer
    A

    The 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.

  6. 6

    When should you NOT use machine learning or deep learning?

    1. A

      When the environment continually changes

    2. B

      When you have a large dataset

    3. C

      When the problem has complex, long lists of rules

    4. D

      When the problem requires explainability

    Correct answer
    D

    When 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.

  7. 7

    What type of data are deep learning models best suited for?

    1. A

      Unstructured data such as images, text, and audio

    2. B

      Structured data such as tables of numbers

    3. C

      Time series data with regular patterns

    4. D

      Only numerical data with few features

    Correct answer
    A

    Unstructured 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.

  8. 8

    What is transfer learning?

    1. A

      Using a single model for both regression and classification

    2. B

      Transferring data from CPU to GPU for faster training

    3. C

      Applying patterns learned from one dataset to a different problem

    4. D

      Learning multiple tasks simultaneously

    Correct answer
    C

    Applying 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.

  9. 9

    What is a tensor in PyTorch?

    1. A

      A type of neural network layer

    2. B

      The fundamental numerical representation of data

    3. C

      A hyperparameter that controls learning rate

    4. D

      A function that calculates gradients

    Correct answer
    B

    The 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.

  10. 10

    What does PyTorch use to leverage GPU acceleration?

    1. A

      TensorFlow

    2. B

      OpenCL

    3. C

      CUDA

    4. D

      DirectX

    Correct answer
    C

    CUDA

    Explanation

    PyTorch uses CUDA, an interface for NVIDIA GPUs, to accelerate numerical computations.

  11. 11

    Which company originally developed PyTorch?

    1. A

      Microsoft

    2. B

      Amazon

    3. C

      Google

    4. D

      Facebook (Meta)

    Correct answer
    D

    Facebook (Meta)

    Explanation

    PyTorch was developed by Facebook (now Meta) and is open-sourced.

  12. 12

    What is the correct way to save and load a PyTorch model?

    1. A

      Save the entire model object with torch.save(model, 'model.pth')

    2. B

      Use model.save() and model.load() methods

    3. C

      Save the model's architecture separately and weights in a JSON file

    4. D

      Save only the state_dict with torch.save(model.state_dict(), 'model.pth') then load with load_state_dict

    Correct answer
    D

    Save 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.

  13. 13

    In a PyTorch training loop, what is the purpose of optimizer.zero_grad()?

    1. A

      To move the model to the GPU

    2. B

      To reset the gradients of model parameters before backpropagation

    3. C

      To initialize the model parameters

    4. D

      To stop training after reaching a loss threshold

    Correct answer
    B

    To 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.

  14. 14

    What is the correct order of steps in a training loop for one epoch?

    1. A

      Backward pass, optimizer step, forward pass, zero grad

    2. B

      Forward pass, backward pass, zero grad, optimizer step

    3. C

      Forward pass, calculate loss, zero grad, backward pass, optimizer step

    4. D

      Zero grad, forward pass, backward pass, optimizer step

    Correct answer
    C

    Forward 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().

  15. 15

    Why is torch.inference_mode() used during testing?

    1. A

      To turn off gradient tracking for faster computation

    2. B

      To convert the model to evaluation mode

    3. C

      To enable dropout for better generalization

    4. D

      To automatically adjust the learning rate

    Correct answer
    A

    To turn off gradient tracking for faster computation

    Explanation

    torch.inference_mode() disables gradient tracking, making forward passes faster and reducing memory usage.

  16. 16

    Which loss function is recommended for binary classification in PyTorch?

    1. A

      nn.L1Loss()

    2. B

      nn.BCEWithLogitsLoss()

    3. C

      nn.BCELoss()

    4. D

      nn.CrossEntropyLoss()

    Correct answer
    B

    nn.BCEWithLogitsLoss()

    Explanation

    nn.BCEWithLogitsLoss() is numerically more stable because it combines a sigmoid layer with binary cross-entropy loss.

  17. 17

    What activation function is used in the output layer for multi-class classification?

    1. A

      Softmax

    2. B

      ReLU

    3. C

      Sigmoid

    4. D

      Tanh

    Correct answer
    A

    Softmax

    Explanation

    Softmax converts logits to probabilities that sum to 1, suitable for multi-class classification.

  18. 18

    What is the purpose of non-linear activation functions like ReLU in a neural network?

    1. A

      To convert probabilities to class labels

    2. B

      To introduce non-linearity so the network can learn complex patterns

    3. C

      To reduce overfitting by adding randomness

    4. D

      To increase the number of parameters

    Correct answer
    B

    To 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.

  19. 19

    What does the nn.Linear layer learn?

    1. A

      A non-linear transformation using ReLU

    2. B

      A linear transformation of the input using weights and biases

    3. C

      A convolutional filter on image data

    4. D

      A pooling operation to downsample

    Correct answer
    B

    A 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.

  20. 20

    In the logits pipeline, how do you convert logits to prediction labels for binary classification?

    1. A

      Apply tanh then take sign

    2. B

      Apply sigmoid then round to 0 or 1

    3. C

      Apply ReLU then threshold at 0

    4. D

      Apply softmax then take argmax

    Correct answer
    B

    Apply 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.

  21. 21

    What is the shape of a single image in the FashionMNIST dataset?

    1. A

      28x28 with 3 color channels

    2. B

      28x28 with 1 color channel

    3. C

      64x64 with 1 color channel

    4. D

      32x32 with 3 color channels

    Correct answer
    B

    28x28 with 1 color channel

    Explanation

    FashionMNIST consists of 28x28 grayscale images, so a single image has shape [1, 28, 28] (channels, height, width).

  22. 22

    Why is batching used when training with DataLoader?

    1. A

      To shuffle the data randomly once per epoch

    2. B

      To reduce the total number of training epochs

    3. C

      To ensure the model sees all data before updating parameters

    4. D

      To process data in smaller chunks for computational efficiency and more frequent gradient updates

    Correct answer
    D

    To 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.

  23. 23

    What does nn.Conv2d learn?

    1. A

      A single value per channel after global average pooling

    2. B

      Local patterns by sliding a kernel across the image

    3. C

      A set of global weights for all spatial locations

    4. D

      The spatial arrangement of pixels

    Correct answer
    B

    Local 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.

  24. 24

    What is the purpose of nn.MaxPool2d in a CNN?

    1. A

      To increase the number of feature maps

    2. B

      To learn non-linear transformations

    3. C

      To apply dropout for regularization

    4. D

      To reduce the spatial dimensions (height and width) by taking the maximum in a window

    Correct answer
    D

    To 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.

  25. 25

    In the TinyVGG architecture, what follows the convolutional blocks before the classifier?

    1. A

      A fully connected layer

    2. B

      A dropout layer

    3. C

      A flatten layer

    4. D

      A global average pooling layer

    Correct answer
    C

    A 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.

  26. 26

    What is the correct order of the three common errors in PyTorch?

    1. A

      Wrong shape, wrong data type, wrong device

    2. B

      Wrong device, wrong data type, wrong shape

    3. C

      Wrong shape, wrong device, wrong data type

    4. D

      Wrong data type, wrong shape, wrong device

    Correct answer
    D

    Wrong data type, wrong shape, wrong device

    Explanation

    The top 3 errors are: wrong data type (dtype), wrong shape, and wrong device (CPU/GPU mismatch).

  27. 27

    What is the result of a matrix multiplication between tensors of shape (3,2) and (2,4)?

    1. A

      A tensor of shape (3,2)

    2. B

      A tensor of shape (3,4)

    3. C

      Invalid because inner dimensions do not match

    4. D

      A tensor of shape (2,2)

    Correct answer
    B

    A 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).

  28. 28

    Which function is used to create a custom dataset in PyTorch?

    1. A

      torch.utils.data.TensorDataset

    2. B

      torch.utils.data.Dataset

    3. C

      torch.utils.data.DataLoader

    4. D

      torchvision.datasets

    Correct answer
    B

    torch.utils.data.Dataset

    Explanation

    Custom datasets are created by subclassing torch.utils.data.Dataset and implementing len and getitem.

  29. 29

    What is the default learning rate value commonly used as a starting point?

    1. A

      0.001

    2. B

      0.01

    3. C

      0.1

    4. D

      0.0001

    Correct answer
    B

    0.01

    Explanation

    A common starting learning rate is 0.01 for SGD, though it may need tuning.

  30. 30

    What does the nn.L1Loss() function compute?

    1. A

      Mean squared error between predictions and targets

    2. B

      Huber loss combining MSE and MAE

    3. C

      Cross entropy loss for classification

    4. D

      Mean absolute error between predictions and targets

    Correct answer
    D

    Mean absolute error between predictions and targets

    Explanation

    nn.L1Loss() computes the mean absolute error (MAE), which is the average of absolute differences.

Question 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