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

Study methods

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

Deep Learning with PyTorch

  • 131Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Neural Foundations

Which description best captures the structure of a basic deep learning model?

131 questions

  1. 1

    Which description best captures the structure of a basic deep learning model?

    1. A

      Hidden layers provide the training labels, while input layers produce predictions.

    2. B

      Inputs connect directly to outputs, and every network must contain exactly one hidden layer.

    3. C

      Inputs pass through hidden layers to produce outputs, and a network may have one or many hidden layers.

    4. D

      Outputs pass through the input layer before being processed by hidden layers.

    Correct answer
    C

    Inputs pass through hidden layers to produce outputs, and a network may have one or many hidden layers.

    Explanation

    A neural network consists of input, hidden, and output layers. Networks can contain different numbers of hidden layers, including none.

  2. 2

    Why are these models called neural networks?

    1. A

      Their original inspiration was interconnected cells, called neurons, in the human brain.

    2. B

      They require neurons from biological tissue to calculate model predictions.

    3. C

      They process only data collected from human brains and nervous systems.

    4. D

      Their layers reproduce the brain's biological structure exactly.

    Correct answer
    A

    Their original inspiration was interconnected cells, called neurons, in the human brain.

    Explanation

    The original intuition was to create models inspired by how the brain learns through interconnected neurons; the models do not reproduce the brain exactly.

  3. 3

    Compared with many other machine learning models, what is a common data requirement of deep learning?

    1. A

      It often requires at least hundreds of thousands of data points to derive patterns.

    2. B

      It requires exactly the same amount of data as every other machine learning model.

    3. C

      It can learn patterns without data if its network has enough hidden layers.

    4. D

      It generally requires only a few dozen examples because layers create new data.

    Correct answer
    A

    It often requires at least hundreds of thousands of data points to derive patterns.

    Explanation

    Layered deep learning models commonly need substantially more data than other machine learning approaches, often at least hundreds of thousands of data points.

  4. 4

    Which statement about PyTorch is supported by the material?

    1. A

      It was developed by an academic research lab and is maintained only by Facebook.

    2. B

      It was developed as part of NumPy and later became a general-purpose Python interpreter.

    3. C

      It was developed by Meta AI in Facebook's AI research lab and later moved under the Linux Foundation.

    4. D

      It was developed by the Linux Foundation and later moved into Meta AI's research lab.

    Correct answer
    C

    It was developed by Meta AI in Facebook's AI research lab and later moved under the Linux Foundation.

    Explanation

    PyTorch was originally developed by Meta AI as part of Facebook's AI research lab and later moved under the Linux Foundation.

  5. 5

    What is the fundamental data structure used by PyTorch?

    1. A

      A Python class, which automatically converts all data into predictions.

    2. B

      A tensor, which is similar to an array or matrix and supports mathematical operations.

    3. C

      A label, which holds the input features and the model's hidden states.

    4. D

      A dataframe, which stores every model layer and its learned parameters.

    Correct answer
    B

    A tensor, which is similar to an array or matrix and supports mathematical operations.

    Explanation

    Tensors are PyTorch's fundamental data structure. They can be created from Python lists or NumPy arrays and support mathematical operations.

  6. 6

    What does checking a tensor's shape and data type help a developer verify?

    1. A

      That the model will produce the correct predictions for every input.

    2. B

      That the tensor's dimensions and format are compatible with the model and task.

    3. C

      That the model has already learned accurate weights from the tensor.

    4. D

      That the tensor contains no missing values and needs no further inspection.

    Correct answer
    B

    That the tensor's dimensions and format are compatible with the model and task.

    Explanation

    Inspecting a tensor's shape and data type helps ensure it aligns with the model and task, and can assist with debugging.

  7. 7

    When can two PyTorch tensors be added or subtracted according to the material?

    1. A

      When one tensor has fewer dimensions than the other.

    2. B

      When their total numbers of elements are equal, regardless of shape.

    3. C

      When their data types are the same, even if their shapes differ.

    4. D

      When their shapes are the same, so their dimensions align exactly.

    Correct answer
    D

    When their shapes are the same, so their dimensions align exactly.

    Explanation

    The described addition and subtraction operations require compatible shapes; in this material, compatibility means the same shape.

  8. 8

    How is each value in a matrix product formed?

    1. A

      By multiplying matching positions in both matrices and retaining each product separately.

    2. B

      By adding a row of the first matrix to a column of the second and averaging the values.

    3. C

      By multiplying a row of the first matrix by a column of the second and summing the products.

    4. D

      By summing the first matrix's rows and copying those totals into the second matrix.

    Correct answer
    C

    By multiplying a row of the first matrix by a column of the second and summing the products.

    Explanation

    Each value in a matrix product is the sum of the element-wise products of a row from the first matrix and a column from the second.

  9. 9

    What do the input and output layer dimensions represent when designing a network for classification?

    1. A

      The input dimension is the number of classes, and the output dimension is the number of features.

    2. B

      The input dimension is the number of features, and the output dimension is the number of classes.

    3. C

      Both dimensions are determined by the number of hidden layers in the network.

    4. D

      The input dimension is the number of samples, and the output dimension is the number of features.

    Correct answer
    B

    The input dimension is the number of features, and the output dimension is the number of classes.

    Explanation

    The input layer has one neuron per dataset feature, while the output layer has one neuron per class being predicted.

  10. 10

    A linear layer receives an input with three features and should produce two output values. Which dimensions should be specified?

    1. A

      Three input features and two output features.

    2. B

      Three input features and three output features.

    3. C

      Two input features and three output features.

    4. D

      Two input features and two output features.

    Correct answer
    A

    Three input features and two output features.

    Explanation

    The layer's input dimension must match the input tensor's three features, and its output dimension should be two.

  11. 11

    What roles do weights and biases play in a linear layer?

    1. A

      Weights encode the true labels, while a bias measures prediction accuracy.

    2. B

      Weights set the number of classes, while a bias determines the input tensor's shape.

    3. C

      Weights control the learning rate, while a bias determines the batch size.

    4. D

      Weights reflect feature importance, while a bias adds a baseline term independent of the weights.

    Correct answer
    D

    Weights reflect feature importance, while a bias adds a baseline term independent of the weights.

    Explanation

    Weights determine how input features contribute to a neuron's output. The bias is an additional term that can provide a baseline output.

  12. 12

    What is the main constraint when stacking linear layers in sequence?

    1. A

      Each layer's input dimension must match the preceding layer's output dimension.

    2. B

      Each layer must have the same input and output dimension.

    3. C

      Every layer must have fewer neurons than the layer before it.

    4. D

      The final layer must have more outputs than the first layer has inputs.

    Correct answer
    A

    Each layer's input dimension must match the preceding layer's output dimension.

    Explanation

    The dimensions must connect: each layer must accept the number of values produced by the previous layer.

  13. 13

    A fully connected layer receives eight values and has four neurons. How many learnable parameters does it have?

    1. A

      Twelve: eight input weights and four output biases in total.

    2. B

      Forty: eight weights and two biases for each of four neurons.

    3. C

      Thirty-six: eight weights and one bias for each of four neurons.

    4. D

      Thirty-two: eight weights for each of four neurons and no biases.

    Correct answer
    C

    Thirty-six: eight weights and one bias for each of four neurons.

    Explanation

    Each of the four neurons has eight weights and one bias, so the layer has four times nine, or thirty-six, parameters.

  14. 14

    A network has a first layer with four neurons, each with eight weights and one bias, and a second layer with two neurons, each with four weights and one bias. What is its total parameter count?

    1. A

      Forty parameters.

    2. B

      Forty-six parameters.

    3. C

      Fifty parameters.

    4. D

      Thirty-six parameters.

    Correct answer
    B

    Forty-six parameters.

    Explanation

    The first layer has four times nine, or thirty-six, parameters. The second has two times five, or ten. Together they have forty-six.

  15. 15

    Why can adding layers increase both a model's usefulness and its training cost?

    1. A

      More parameters eliminate training time by allowing the model to skip optimization.

    2. B

      More layers reduce the number of parameters but require more data transformations at evaluation.

    3. C

      More parameters can represent more complex patterns but may take longer to train and increase overfitting risk.

    4. D

      More layers guarantee better generalization but prevent the model from fitting complex datasets.

    Correct answer
    C

    More parameters can represent more complex patterns but may take longer to train and increase overfitting risk.

    Explanation

    Greater model capacity can help a network handle complex datasets, but additional parameters can increase training time and overfitting risk.

  16. 16

    What is the purpose of a nonlinear activation between linear layers?

    1. A

      It converts all model parameters into probabilities before training begins.

    2. B

      It ensures every hidden layer has the same number of neurons as the output layer.

    3. C

      It enables the network to learn complex interactions beyond purely linear relationships.

    4. D

      It removes the need for weights and biases in the linear layers.

    Correct answer
    C

    It enables the network to learn complex interactions beyond purely linear relationships.

    Explanation

    Nonlinear activations let networks learn more complex relationships than a stack of linear operations alone.

  17. 17

    What is the pre-activation output of a network?

    1. A

      The gradient of the loss before it is used to update the parameters.

    2. B

      The ground-truth value before it is converted into a tensor.

    3. C

      The model's final class label after a probability threshold has been applied.

    4. D

      The output of the last linear layer before it is passed through an activation function.

    Correct answer
    D

    The output of the last linear layer before it is passed through an activation function.

    Explanation

    The pre-activation output is the output of the final linear layer before an activation function transforms it.

  18. 18

    Why is sigmoid commonly used for binary classification?

    1. A

      It converts a class label into a vector of zeros and ones for any number of classes.

    2. B

      It maps model outputs to any real number, allowing direct prediction of continuous targets.

    3. C

      It transforms a single model output into a value between zero and one that can represent a probability.

    4. D

      It transforms any number of outputs into class probabilities that always sum to one.

    Correct answer
    C

    It transforms a single model output into a value between zero and one that can represent a probability.

    Explanation

    Sigmoid maps an input to the range from zero to one, making its output interpretable as a binary-class probability.

  19. 19

    A binary classifier produces a sigmoid output of 0.7. Using the described threshold rule, what label should it predict?

    1. A

      Class one, because the probability is greater than 0.5.

    2. B

      Class one, because every sigmoid output represents the positive class.

    3. C

      Class zero, because every probability below one is negative.

    4. D

      Class zero, because the probability is greater than 0.5.

    Correct answer
    A

    Class one, because the probability is greater than 0.5.

    Explanation

    With the stated threshold, probabilities greater than 0.5 are assigned to class one; values below 0.5 are assigned to class zero.

  20. 20

    What does a softmax output represent in a multiclass classification task?

    1. A

      A single probability that identifies whether the input belongs to any class.

    2. B

      A vector of unbounded scores whose largest value is always negative.

    3. C

      A probability distribution whose values are between zero and one and sum to one.

    4. D

      A set of independent probabilities that may sum to any value.

    Correct answer
    C

    A probability distribution whose values are between zero and one and sum to one.

    Explanation

    Softmax produces one probability per class; each value lies between zero and one, and the values sum to one.

  21. 21

    A softmax classifier outputs probabilities for three classes. How is its predicted class selected?

    1. A

      Choose the first class whose probability is greater than zero.

    2. B

      Choose the class with the highest probability.

    3. C

      Choose the class whose probability is closest to 0.5.

    4. D

      Choose the class with the lowest probability.

    Correct answer
    B

    Choose the class with the highest probability.

    Explanation

    For multiclass prediction, the assigned label is the class with the largest softmax probability.

  22. 22

    Why is a sigmoid activation generally unsuitable for hidden layers in a deep network?

    1. A

      It makes all input features have identical weights.

    2. B

      For very large or small inputs, its gradients become very small and can cause vanishing gradients.

    3. C

      Its outputs are unbounded, so hidden-layer values grow without limit.

    4. D

      It requires every hidden layer to have exactly one neuron.

    Correct answer
    B

    For very large or small inputs, its gradients become very small and can cause vanishing gradients.

    Explanation

    Sigmoid can saturate at large positive or negative inputs, producing very small gradients that hinder parameter updates during backpropagation.

  23. 23

    How does ReLU transform its input?

    1. A

      It returns zero for positive values and the input for negative values.

    2. B

      It maps every input to a probability distribution over classes.

    3. C

      It returns the input for positive values and zero for negative values.

    4. D

      It maps every input into the range between zero and one.

    Correct answer
    C

    It returns the input for positive values and zero for negative values.

    Explanation

    ReLU returns the maximum of its input and zero: positive inputs pass through, while negative inputs become zero.

  24. 24

    How does leaky ReLU differ from standard ReLU for negative inputs?

    1. A

      It maps negative inputs to one and positive inputs to zero.

    2. B

      It sets negative inputs to zero but increases the gradient for positive inputs.

    3. C

      It multiplies negative inputs by a small coefficient, leaving a nonzero gradient.

    4. D

      It converts negative inputs to positive values by taking their absolute value.

    Correct answer
    C

    It multiplies negative inputs by a small coefficient, leaving a nonzero gradient.

    Explanation

    Leaky ReLU applies a small negative-slope coefficient to negative inputs, so their gradients remain nonzero.

  25. 25

    When is cross-entropy loss appropriate, and what does it compare?

    1. A

      For regression, it compares model weights with the optimizer's learning rate.

    2. B

      For regression, it compares continuous predictions with squared target values.

    3. C

      For classification, it compares model scores with the encoded ground-truth class.

    4. D

      For classification, it compares only the model's final predicted label with the input features.

    Correct answer
    C

    For classification, it compares model scores with the encoded ground-truth class.

    Explanation

    Cross-entropy is commonly used for classification. In the described workflow, it receives the model's scores and the one-hot encoded target.

  26. 26

    With three classes, what one-hot vector represents class one when class indices are zero-based?

    1. A

      A vector with one in the second position and zero elsewhere.

    2. B

      A vector with one in the third position and zero elsewhere.

    3. C

      A vector with equal values in all three positions.

    4. D

      A vector with one in the first position and zero elsewhere.

    Correct answer
    A

    A vector with one in the second position and zero elsewhere.

    Explanation

    One-hot encoding places a one at the position corresponding to the class index. Class one therefore has its one in the second position.

  27. 27

    Which output-layer design is appropriate for the regression example described?

    1. A

      A linear layer with one output and no final sigmoid or softmax activation.

    2. B

      A sigmoid layer with one output so every prediction is between zero and one.

    3. C

      A softmax layer with one output so each prediction is a class probability.

    4. D

      A softmax layer with one output for each training sample.

    Correct answer
    A

    A linear layer with one output and no final sigmoid or softmax activation.

    Explanation

    The regression model predicts continuous values, so the example uses a one-output linear layer without a final classification activation.

  28. 28

    What does mean squared error measure?

    1. A

      The mean of the squared differences between predictions and ground-truth values.

    2. B

      The largest difference between a prediction and a ground-truth value.

    3. C

      The fraction of predictions that match their one-hot encoded labels.

    4. D

      The mean of the absolute differences between predictions and class indices.

    Correct answer
    A

    The mean of the squared differences between predictions and ground-truth values.

    Explanation

    MSE averages the squared errors between predictions and targets. Squaring prevents positive and negative errors from canceling and penalizes larger errors more.

  29. 29

    What does a loss function provide during model training?

    1. A

      A guarantee that the model will generalize to unseen data.

    2. B

      A fixed count of how many features are in each training sample.

    3. C

      A numerical measure of prediction error that training aims to minimize.

    4. D

      A class label that replaces the model's predicted output.

    Correct answer
    C

    A numerical measure of prediction error that training aims to minimize.

    Explanation

    A loss function compares predictions with ground truth and produces a numerical value indicating how poorly the model predicted; training aims to reduce it.

  30. 30

    What is the purpose of a forward pass?

    1. A

      To convert predicted class indices into one-hot encoded targets.

    2. B

      To pass inputs through the model's layers and produce predictions using its current parameters.

    3. C

      To compute parameter gradients and update the weights using the optimizer.

    4. D

      To split a dataset into training, validation, and test subsets.

    Correct answer
    B

    To pass inputs through the model's layers and produce predictions using its current parameters.

    Explanation

    During a forward pass, input data flows through the network's layers until the model produces its output.

  31. 31

    Why is a model's output before training updates not necessarily meaningful?

    1. A

      Its weights and biases may still be randomly initialized and need to be tuned through training.

    2. B

      The output becomes meaningful only after every input is converted to a one-hot vector.

    3. C

      A forward pass cannot produce predictions until the test set is evaluated.

    4. D

      Random initialization means the model has already minimized the loss.

    Correct answer
    A

    Its weights and biases may still be randomly initialized and need to be tuned through training.

    Explanation

    A model initially has randomly initialized weights and biases. Training updates these parameters so the predictions can become useful.

  32. 32

    In a classification dataset, why might the animal name column be excluded from the input features?

    1. A

      The name column contains the target labels rather than the animal's name.

    2. B

      Names cannot be stored in a CSV file or loaded into a dataframe.

    3. C

      The name itself does not determine the animal's classification, unlike its relevant characteristics.

    4. D

      Names must be used as the output layer's neuron count.

    Correct answer
    C

    The name itself does not determine the animal's classification, unlike its relevant characteristics.

    Explanation

    The example uses characteristics such as hair, feathers, and legs as features and omits the animal name because it does not determine the class.

  33. 33

    What is the role of a PyTorch TensorDataset?

    1. A

      It converts model outputs into loss values without requiring targets.

    2. B

      It randomly initializes the model's weights and biases.

    3. C

      It organizes feature and target tensors so samples can be accessed together.

    4. D

      It calculates class accuracy for every training batch.

    Correct answer
    C

    It organizes feature and target tensors so samples can be accessed together.

    Explanation

    TensorDataset stores tensors such as features and labels together, allowing an individual sample to return its input and corresponding target.

  34. 34

    What does a DataLoader's batch size determine?

    1. A

      How many classes the model is permitted to predict.

    2. B

      How many epochs the optimizer runs before updating parameters.

    3. C

      How many samples are included in each iteration over the data.

    4. D

      How many features are stored in each individual sample.

    Correct answer
    C

    How many samples are included in each iteration over the data.

    Explanation

    Batch size is the number of samples the DataLoader provides in an iteration.

  35. 35

    Why shuffle training samples between epochs?

    1. A

      Ensuring the same samples are always grouped together can prevent overfitting.

    2. B

      Changing their labels can help balance the classes automatically.

    3. C

      Reducing the number of samples can make each epoch complete faster.

    4. D

      Randomizing their order can help improve the model's generalization.

    Correct answer
    D

    Randomizing their order can help improve the model's generalization.

    Explanation

    Shuffling randomizes sample order at each epoch and can help the model generalize rather than depend on a fixed ordering.

  36. 36

    What is one epoch?

    1. A

      One prediction from the output layer.

    2. B

      One complete pass through the training data.

    3. C

      One update to a single model parameter.

    4. D

      One batch from the validation data.

    Correct answer
    B

    One complete pass through the training data.

    Explanation

    An epoch is a full pass through the training dataset or its DataLoader.

  37. 37

    A dataset has five samples and a batch size of two. If the final partial batch is retained, how many samples are in the last batch?

    1. A

      Two samples.

    2. B

      Five samples.

    3. C

      One sample.

    4. D

      Three samples.

    Correct answer
    C

    One sample.

    Explanation

    Two batches of two account for four samples, leaving one sample for the final batch.

  38. 38

    Why must predictions and targets both be floating-point tensors in the described MSE workflow?

    1. A

      The DataLoader can batch data only when all tensors contain floating-point values.

    2. B

      The regression loss and model parameters use floating-point values.

    3. C

      MSE accepts only integer labels, so both tensors must be converted to floats.

    4. D

      Floating-point tensors automatically encode each target as a class.

    Correct answer
    B

    The regression loss and model parameters use floating-point values.

    Explanation

    The regression example casts features and targets to floats, matching the floating-point data type used by the model parameters and MSE workflow.

  39. 39

    Why does a training loop clear gradients before processing a new batch?

    1. A

      Clearing gradients reinitializes the model's weights before every forward pass.

    2. B

      Clearing gradients changes the target labels into the correct data type.

    3. C

      Optimizers retain gradients by default, so clearing them prevents previous gradients from carrying over.

    4. D

      Gradients can be computed only once per epoch, so they must be deleted between batches.

    Correct answer
    C

    Optimizers retain gradients by default, so clearing them prevents previous gradients from carrying over.

    Explanation

    Gradients accumulate unless cleared. The training loop uses the optimizer's zero-grad operation to start each batch with clean gradients.

  40. 40

    What does backpropagation calculate?

    1. A

      The input dimensions required by each linear layer.

    2. B

      Gradients of the loss with respect to model parameters.

    3. C

      The model's final accuracy without using target labels.

    4. D

      The number of samples in each class of the dataset.

    Correct answer
    B

    Gradients of the loss with respect to model parameters.

    Explanation

    Backpropagation computes loss gradients for model parameters, which can then guide updates to weights and biases.

  41. 41

    What does the optimizer do during a training step?

    1. A

      It selects which output class is the ground truth.

    2. B

      It calculates the number of hidden layers required by the dataset.

    3. C

      It converts the training data into one-hot encoded labels.

    4. D

      It uses parameter gradients to update the model's parameters.

    Correct answer
    D

    It uses parameter gradients to update the model's parameters.

    Explanation

    The optimizer applies parameter updates based on the gradients computed from the loss.

  42. 42

    Why should a parameter with a positive loss gradient generally be decreased during gradient descent?

    1. A

      Decreasing the parameter guarantees the loss reaches its global minimum immediately.

    2. B

      Moving against the gradient direction tends to reduce the loss.

    3. C

      The optimizer can update parameters only when their gradients are positive.

    4. D

      Positive gradients indicate that the parameter has no effect on the loss.

    Correct answer
    B

    Moving against the gradient direction tends to reduce the loss.

    Explanation

    Gradient descent updates parameters in the direction opposite the loss gradient, so a positive gradient calls for a decrease in the parameter.

  43. 43

    How does the learning rate affect stochastic gradient descent?

    1. A

      It controls whether the model uses sigmoid or softmax.

    2. B

      It determines the number of output classes in the final layer.

    3. C

      It determines how many samples are included in a batch.

    4. D

      It controls the step size used for parameter updates.

    Correct answer
    D

    It controls the step size used for parameter updates.

    Explanation

    The learning rate is a tunable hyperparameter that controls the size of optimizer updates.

  44. 44

    What is a likely effect of setting the learning rate too low?

    1. A

      The optimizer repeatedly overshoots the minimum with large steps.

    2. B

      Training progresses slowly because the optimizer takes small steps.

    3. C

      The model automatically becomes more complex and overfits.

    4. D

      The loss becomes independent of the model's parameters.

    Correct answer
    B

    Training progresses slowly because the optimizer takes small steps.

    Explanation

    A very small learning rate makes updates small, so the optimizer may take much longer to approach a minimum.

  45. 45

    What is a likely effect of setting the learning rate too high?

    1. A

      The optimizer becomes unable to calculate gradients.

    2. B

      The optimizer takes smaller steps near the minimum than intended.

    3. C

      The optimizer can overshoot and bounce around rather than settle at a minimum.

    4. D

      The model's output layer automatically gains extra neurons.

    Correct answer
    C

    The optimizer can overshoot and bounce around rather than settle at a minimum.

    Explanation

    An excessively high learning rate can cause updates to jump across the minimum, preventing convergence.

  46. 46

    What does momentum contribute to an optimizer?

    1. A

      It forces the learning rate to be zero whenever a gradient is small.

    2. B

      It shuffles samples and changes their order between epochs.

    3. C

      It replaces gradients with the model's accuracy score.

    4. D

      It uses inertia from past updates to help movement continue smoothly and pass local dips.

    Correct answer
    D

    It uses inertia from past updates to help movement continue smoothly and pass local dips.

    Explanation

    Momentum incorporates the effect of previous steps, helping the optimizer move smoothly and sometimes overcome local minima.

  47. 47

    Why can momentum help on a non-convex loss surface?

    1. A

      It removes the need to compute gradients during training.

    2. B

      It can keep updates substantial after large previous steps, helping the optimizer move past a local minimum.

    3. C

      It guarantees that every model parameter decreases at every step.

    4. D

      It makes every local minimum equal to the global minimum.

    Correct answer
    B

    It can keep updates substantial after large previous steps, helping the optimizer move past a local minimum.

    Explanation

    Momentum can preserve a large step even when the current gradient is small, helping the optimizer pass local dips that might trap it otherwise.

  48. 48

    How does Adam combine ideas from other optimizers?

    1. A

      It combines adaptive learning-rate behavior associated with RMSprop and momentum from past gradients.

    2. B

      It combines batch shuffling with a fixed learning rate for every update.

    3. C

      It combines softmax predictions with cross-entropy targets.

    4. D

      It combines one-hot encoding with the parameter count of a linear layer.

    Correct answer
    A

    It combines adaptive learning-rate behavior associated with RMSprop and momentum from past gradients.

    Explanation

    Adam combines RMSprop-like adaptation with a momentum concept that averages past gradients, giving more weight to recent gradients.

  49. 49

    What kind of data is Adagrad especially suited to, according to the material?

    1. A

      Sparse data with features that are observed infrequently.

    2. B

      Dense data in which every feature appears in every sample.

    3. C

      Image data that has already been converted to class indices.

    4. D

      Sequential data that must be split randomly across time.

    Correct answer
    A

    Sparse data with features that are observed infrequently.

    Explanation

    Adagrad decreases learning rates for parameters that are updated infrequently, making it well-suited to sparse data.

  50. 50

    Which optimizer is presented as a common default choice for general training?

    1. A

      Adagrad, because it never changes learning rates.

    2. B

      Adam, because it is versatile and widely used.

    3. C

      Plain SGD, because it always outperforms adaptive methods.

    4. D

      RMSprop, because it does not use gradient information.

    Correct answer
    B

    Adam, because it is versatile and widely used.

    Explanation

    Adam is described as a versatile, widely used optimizer and a common go-to choice.

  51. 51

    What is the purpose of using a validation set?

    1. A

      To adjust model weights as the only source of training data.

    2. B

      To provide the final unbiased performance score after all tuning.

    3. C

      To replace the training set when calculating gradients.

    4. D

      To tune hyperparameters such as learning rate and momentum.

    Correct answer
    D

    To tune hyperparameters such as learning rate and momentum.

    Explanation

    The training set adjusts model parameters, the validation set supports hyperparameter tuning, and the test set evaluates final performance.

  52. 52

    What does the test set primarily measure?

    1. A

      The best learning rate before training begins.

    2. B

      The model's final performance after training and model selection.

    3. C

      The model's ability to memorize the training labels.

    4. D

      The model's parameter updates during each training batch.

    Correct answer
    B

    The model's final performance after training and model selection.

    Explanation

    The test set is used to evaluate the model's final performance, while training and validation serve different roles.

  53. 53

    How is mean training loss for an epoch calculated in the described procedure?

    1. A

      Sum the batch losses and divide by the number of model parameters.

    2. B

      Average the training accuracy and multiply it by the number of batches.

    3. C

      Sum the batch losses and divide by the number of training batches.

    4. D

      Subtract the validation loss from the total number of training samples.

    Correct answer
    C

    Sum the batch losses and divide by the number of training batches.

    Explanation

    The procedure adds each batch's loss and divides the total by the number of batches to obtain mean training loss.

  54. 54

    Why use evaluation mode and disable gradient calculations during validation?

    1. A

      Evaluation mode handles layers that behave differently, and gradients are unnecessary when weights are not being updated.

    2. B

      Evaluation mode recalculates training gradients, while disabling gradients updates weights more accurately.

    3. C

      Both steps convert validation labels into training labels.

    4. D

      They make the validation set part of the optimizer's parameter list.

    Correct answer
    A

    Evaluation mode handles layers that behave differently, and gradients are unnecessary when weights are not being updated.

    Explanation

    Evaluation mode sets the model's layers to evaluation behavior, and disabling gradients avoids unnecessary calculations because validation does not update weights.

  55. 55

    Which pattern is evidence of overfitting?

    1. A

      Training and validation accuracy both remain at chance level.

    2. B

      Validation loss falls while training loss rises steadily.

    3. C

      Training loss continues to fall while validation loss begins to rise.

    4. D

      Both training and validation loss fall at the same rate.

    Correct answer
    C

    Training loss continues to fall while validation loss begins to rise.

    Explanation

    When training loss decreases but validation loss rises, the model may be fitting the training data too closely and generalizing poorly.

  56. 56

    In multiclass classification, how can a vector of class probabilities be turned into predicted class indices?

    1. A

      Use argmax along the class dimension to select the highest-probability class.

    2. B

      Apply one-hot encoding to the input features.

    3. C

      Use the mean along the class dimension and round the result.

    4. D

      Use the minimum probability as the predicted class index.

    Correct answer
    A

    Use argmax along the class dimension to select the highest-probability class.

    Explanation

    Argmax selects the class with the highest predicted probability and returns its index.

  57. 57

    What does precision measure for a class?

    1. A

      The fraction of all examples of that class that were correctly found.

    2. B

      The fraction of all examples assigned to any class correctly.

    3. C

      The fraction of predictions for that class that are correct.

    4. D

      The number of false negatives divided by the number of classes.

    Correct answer
    C

    The fraction of predictions for that class that are correct.

    Explanation

    Precision measures how many predicted positives are correct. Recall measures how many actual positives were correctly identified.

  58. 58

    What does recall measure for a class?

    1. A

      The fraction of predictions for that class that are correct.

    2. B

      The fraction of all predictions that belong to the largest class.

    3. C

      The fraction of all actual examples of that class that were correctly predicted.

    4. D

      The number of correct predictions divided by the number of model parameters.

    Correct answer
    C

    The fraction of all actual examples of that class that were correctly predicted.

    Explanation

    Recall measures the fraction of actual positive examples that the model correctly identifies.

  59. 59

    How does macro averaging aggregate per-class precision or recall?

    1. A

      It reports only the score for the largest class.

    2. B

      It pools all class counts first, so larger classes dominate the result.

    3. C

      It weights each class's score by its number of samples.

    4. D

      It computes the metric for each class and takes their unweighted mean.

    Correct answer
    D

    It computes the metric for each class and takes their unweighted mean.

    Explanation

    Macro averaging gives every class equal weight by averaging the independently calculated class scores.

  60. 60

    How does weighted averaging differ from macro averaging?

    1. A

      It weights each class's metric according to the number of samples in that class.

    2. B

      It gives every class equal weight regardless of its size.

    3. C

      It reports the minimum score among all classes.

    4. D

      It computes one global metric without calculating class-specific scores.

    Correct answer
    A

    It weights each class's metric according to the number of samples in that class.

    Explanation

    Weighted averaging uses class sizes as weights, so classes with more samples have greater influence on the final result.

  61. 61

    Which averaging approach calculates metrics globally from the total true positives, false positives, and false negatives?

    1. A

      Per-class averaging.

    2. B

      Weighted averaging.

    3. C

      Micro averaging.

    4. D

      Macro averaging.

    Correct answer
    C

    Micro averaging.

    Explanation

    Micro averaging aggregates the counts across all classes before computing precision or recall.

  62. 62

    When might macro averaging be especially useful?

    1. A

      When performance on smaller classes matters as much as performance on larger classes.

    2. B

      When errors in larger classes should dominate the overall score.

    3. C

      When only the most common class is relevant.

    4. D

      When the goal is to pool all class counts into one global metric.

    Correct answer
    A

    When performance on smaller classes matters as much as performance on larger classes.

    Explanation

    Macro averaging weights classes equally, making it useful when performance on smaller classes should not be overshadowed by larger ones.

  63. 63

    Which condition can contribute to overfitting?

    1. A

      A linear output layer used for a continuous regression target.

    2. B

      A validation set, a test set, or a shuffled training loader.

    3. C

      A large dataset, a small model, or low weight values.

    4. D

      A small dataset, excessive model capacity, or large weights.

    Correct answer
    D

    A small dataset, excessive model capacity, or large weights.

    Explanation

    The material identifies small datasets, models with too much capacity, and large weights as factors that can promote overfitting.

  64. 64

    What does dropout do during training?

    1. A

      It adds extra neurons whenever the model's loss increases.

    2. B

      It permanently removes the same neurons from the model before every training run.

    3. C

      It randomly deactivates a fraction of neurons so the model relies less on particular features.

    4. D

      It randomly changes target labels to increase class diversity.

    Correct answer
    C

    It randomly deactivates a fraction of neurons so the model relies less on particular features.

    Explanation

    Dropout is a regularization technique that randomly sets some neuron outputs to zero during training.

  65. 65

    How does dropout behave during evaluation?

    1. A

      It deactivates the same fraction of neurons as during training.

    2. B

      It removes the output layer and uses the hidden layer predictions.

    3. C

      It replaces the model's weights with random values.

    4. D

      It is disabled so all neurons are active for stable predictions.

    Correct answer
    D

    It is disabled so all neurons are active for stable predictions.

    Explanation

    Dropout is used during training but disabled during evaluation, when all neurons are active.

  66. 66

    How does weight decay help reduce overfitting?

    1. A

      It penalizes large weights, encouraging parameters to remain smaller.

    2. B

      It prevents the model from calculating gradients.

    3. C

      It increases the number of training samples by repeating each batch.

    4. D

      It increases model capacity by adding additional layers.

    Correct answer
    A

    It penalizes large weights, encouraging parameters to remain smaller.

    Explanation

    Weight decay adds a regularization penalty that encourages smaller weights and can reduce excessive weight growth.

  67. 67

    Why should data augmentation be chosen with the task and labels in mind?

    1. A

      Every transformation necessarily makes the label more accurate.

    2. B

      Transformations never affect image meaning, so their choice is irrelevant.

    3. C

      Some transformations can change what an example depicts while its original label remains unchanged.

    4. D

      Augmentation is useful only when the original dataset has no labels.

    Correct answer
    C

    Some transformations can change what an example depicts while its original label remains unchanged.

    Explanation

    A transformation can make an image appear to belong to a different class, such as flipping a handwritten character, while leaving its label unchanged.

  68. 68

    What information does a grayscale pixel value represent in the described image format?

    1. A

      A shade from black to white, represented by an integer from zero to 255.

    2. B

      The pixel's position in the image, represented by an integer from one to 255.

    3. C

      A class probability represented by a number from zero to one.

    4. D

      Three separate color-channel intensities, each stored as a floating-point value.

    Correct answer
    A

    A shade from black to white, represented by an integer from zero to 255.

    Explanation

    A grayscale pixel records a shade between black and white; the described representation uses integers from zero to 255.

  69. 69

    How is a typical color image pixel represented?

    1. A

      By one grayscale value and two model parameters.

    2. B

      By its height, width, and batch position.

    3. C

      By intensities for red, green, and blue color channels.

    4. D

      By a single class index and two label indicators.

    Correct answer
    C

    By intensities for red, green, and blue color channels.

    Explanation

    A color pixel is typically described by three values for the red, green, and blue channels.

  70. 70

    Why is an image dataset arranged into category-specific directories suitable for ImageFolder?

    1. A

      The directory structure automatically converts image pixels into model weights.

    2. B

      The directory structure lets the dataset associate image files with their category labels.

    3. C

      The directory structure prevents images from being resized or transformed.

    4. D

      The directory structure ensures every category contains the same number of images.

    Correct answer
    B

    The directory structure lets the dataset associate image files with their category labels.

    Explanation

    With images stored in directories representing categories, ImageFolder can construct a dataset with category labels.

  71. 71

    A loaded color image has shape one by three by 128 by 128. What do those dimensions represent?

    1. A

      Color channels, batch size, width, and height.

    2. B

      Height, width, color channels, and batch size.

    3. C

      Batch size, color channels, height, and width.

    4. D

      Batch size, height, width, and number of categories.

    Correct answer
    C

    Batch size, color channels, height, and width.

    Explanation

    The described tensor uses batch-first image dimensions: batch size, channels, height, and width.

  72. 72

    Why might image dimensions be permuted before displaying a color image?

    1. A

      The permutation converts a color image into a grayscale image.

    2. B

      The permutation removes the image's class label from the tensor.

    3. C

      Display tools commonly expect height and width before the color-channel dimension.

    4. D

      Display tools require color channels to be stored as the batch dimension.

    Correct answer
    C

    Display tools commonly expect height and width before the color-channel dimension.

    Explanation

    The model-style image tensor places channels before height and width, while image display commonly expects the channel dimension last.

  73. 73

    What is data augmentation for images?

    1. A

      Duplicating the model's output layer to increase the number of predictions.

    2. B

      Applying transformations such as flips or rotations to create varied training examples.

    3. C

      Removing all images whose labels are difficult for the model.

    4. D

      Replacing each image with a randomly generated class label.

    Correct answer
    B

    Applying transformations such as flips or rotations to create varied training examples.

    Explanation

    Data augmentation creates varied versions of training images, increasing training-set diversity and potentially improving robustness.

  74. 74

    Why can feeding a large image directly into a dense layer be inefficient?

    1. A

      It forces every image pixel to have the same color value.

    2. B

      It automatically converts the image into a sequence of class labels.

    3. C

      It cannot be used with floating-point inputs or gradient descent.

    4. D

      It can create an enormous number of parameters and may fail to capture spatial patterns across image locations.

    Correct answer
    D

    It can create an enormous number of parameters and may fail to capture spatial patterns across image locations.

    Explanation

    Flattening large images for dense layers can produce very large parameter counts, and dense connections do not naturally preserve spatial relationships.

  75. 75

    How does a convolutional filter produce values in a feature map?

    1. A

      It selects the most common class label in each region of the image.

    2. B

      It sorts all pixels by brightness and stores the median value.

    3. C

      It connects each input pixel to every output class independently.

    4. D

      It slides across input patches and computes a dot product at each position.

    Correct answer
    D

    It slides across input patches and computes a dot product at each position.

    Explanation

    At each location, the filter and input patch are multiplied element by element and summed to produce a feature-map value.

  76. 76

    What is one purpose of zero padding in a convolutional layer?

    1. A

      It can help preserve spatial dimensions and give border pixels more equal treatment.

    2. B

      It converts every convolution into a fully connected operation.

    3. C

      It ensures that every filter has only one learnable parameter.

    4. D

      It adds new image classes to the model's output.

    Correct answer
    A

    It can help preserve spatial dimensions and give border pixels more equal treatment.

    Explanation

    Padding adds zeros around an input, helping maintain spatial dimensions and reducing the disadvantage border pixels would otherwise face.

  77. 77

    What does a two-by-two max-pooling window do at each position?

    1. A

      It passes forward the smallest value in that window.

    2. B

      It sums the window values and uses the sum as a class score.

    3. C

      It passes forward the average of all values in that window.

    4. D

      It passes forward the largest value in that window.

    Correct answer
    D

    It passes forward the largest value in that window.

    Explanation

    Max pooling selects the maximum value from each window. With the described non-overlapping two-by-two window, it halves height and width.

  78. 78

    What is the usual role of the feature extractor and classifier in the described convolutional network?

    1. A

      The classifier extracts pixel values, while the feature extractor assigns the final class.

    2. B

      Convolutional, activation, and pooling layers extract image features; a flattened representation is passed to a classifier.

    3. C

      The feature extractor stores the labels, while the classifier resizes the images.

    4. D

      The classifier performs data augmentation, while the feature extractor calculates the loss.

    Correct answer
    B

    Convolutional, activation, and pooling layers extract image features; a flattened representation is passed to a classifier.

    Explanation

    The convolutional feature extractor transforms the image into useful features; the classifier maps those features to class outputs.

  79. 79

    Why should test images generally not receive random training augmentations during evaluation?

    1. A

      Test images cannot be converted to tensors if they are resized.

    2. B

      Random transformations prevent the model from entering evaluation mode.

    3. C

      The test loader uses augmentation to calculate training gradients.

    4. D

      Evaluation should measure predictions on the intended test images, not randomly altered versions of them.

    Correct answer
    D

    Evaluation should measure predictions on the intended test images, not randomly altered versions of them.

    Explanation

    Training augmentation adds variety, but evaluation should assess predictions on the specific test examples rather than random transformations of them.

  80. 80

    What is sequential data?

    1. A

      Data whose values are all generated independently from one another.

    2. B

      Data whose rows can always be randomly rearranged without changing their meaning.

    3. C

      Data containing only images with three color channels.

    4. D

      Data in which the order of points matters and may encode temporal or spatial dependencies.

    Correct answer
    D

    Data in which the order of points matters and may encode temporal or spatial dependencies.

    Explanation

    Sequential data has meaningful ordering; examples include time series, text, and audio.

  81. 81

    Why can randomly splitting sequential data create lookahead bias?

    1. A

      Random splitting necessarily removes every target value from the training set.

    2. B

      Training may include information from times later than examples used for testing or forecasting.

    3. C

      Training on randomly selected points prevents the use of recurrent models.

    4. D

      Random splitting makes all sequential data independent of its timestamps.

    Correct answer
    B

    Training may include information from times later than examples used for testing or forecasting.

    Explanation

    A random split can expose the model to future information while it is being trained to predict earlier points, creating unrealistic forecasts.

  82. 82

    What is a safer train-test split strategy for forecasting a time series?

    1. A

      Randomly distribute observations from every time period between both sets.

    2. B

      Train on the last part of the series and test on the first part.

    3. C

      Train on earlier observations and test on later observations.

    4. D

      Place every other observation in the training set and discard timestamps.

    Correct answer
    C

    Train on earlier observations and test on later observations.

    Explanation

    Splitting by time preserves the forecasting direction: training uses earlier data and testing uses later data.

  83. 83

    If consumption is recorded every 15 minutes, how many observations represent the previous 24 hours?

    1. A

      Twenty-four observations.

    2. B

      Ninety-six observations.

    3. C

      One hundred forty-four observations.

    4. D

      Sixty observations.

    Correct answer
    B

    Ninety-six observations.

    Explanation

    There are four 15-minute intervals per hour, so 24 hours contain 24 times 4, or 96, observations.

  84. 84

    In the described next-step forecasting setup, what is the target for each input sequence?

    1. A

      The last input point copied into a separate class label.

    2. B

      The first data point before the sequence.

    3. C

      The data point immediately after the sequence.

    4. D

      The average of every data point in the entire dataset.

    Correct answer
    C

    The data point immediately after the sequence.

    Explanation

    Each training example uses a sequence of past values as input and the subsequent data point as its target.

  85. 85

    What distinguishes a recurrent neural network from a feedforward network?

    1. A

      A recurrent network passes a hidden state from one timestep to the next.

    2. B

      A recurrent network sends all predictions directly back to the input dataset.

    3. C

      A recurrent network has no learned weights or activation functions.

    4. D

      A recurrent network processes each timestep independently without retaining information.

    Correct answer
    A

    A recurrent network passes a hidden state from one timestep to the next.

    Explanation

    RNNs pass a hidden state forward through time, allowing later outputs to depend on earlier inputs.

  86. 86

    What is typically used as the initial hidden state at the first RNN timestep?

    1. A

      The model's highest predicted class.

    2. B

      The final target label in the sequence.

    3. C

      A random permutation of all input features.

    4. D

      A tensor of zeros.

    Correct answer
    D

    A tensor of zeros.

    Explanation

    Because there is no previous hidden state at the first timestep, it is typically initialized to zero.

  87. 87

    Which RNN architecture reads a sequence but uses only its final output?

    1. A

      Sequence-to-vector.

    2. B

      Sequence-to-sequence.

    3. C

      Vector-to-sequence.

    4. D

      Encoder-decoder.

    Correct answer
    A

    Sequence-to-vector.

    Explanation

    A sequence-to-vector model processes an input sequence and uses its final output to produce a vector-level prediction, such as a text classification.

  88. 88

    Which RNN architecture uses outputs at every timestep while receiving a sequence?

    1. A

      Sequence-to-vector.

    2. B

      Vector-to-sequence.

    3. C

      Sequence-to-sequence.

    4. D

      Encoder-decoder.

    Correct answer
    C

    Sequence-to-sequence.

    Explanation

    Sequence-to-sequence models produce and use outputs at each timestep, as in real-time speech recognition.

  89. 89

    Which architecture can generate a sequence from a single input vector?

    1. A

      Vector-to-sequence.

    2. B

      Sequence-to-vector.

    3. C

      Time-to-class.

    4. D

      Sequence-to-sequence.

    Correct answer
    A

    Vector-to-sequence.

    Explanation

    A vector-to-sequence architecture takes one vector and makes use of outputs at multiple timesteps, such as in text generation.

  90. 90

    Why does an encoder-decoder architecture process the input sequence before beginning output generation?

    1. A

      It must discard all hidden states before each output is generated.

    2. B

      It uses the input sequence only to determine the number of model layers.

    3. C

      It cannot generate any outputs unless the input contains only one timestep.

    4. D

      Some tasks, such as translation, require the entire input to be considered before producing the output sequence.

    Correct answer
    D

    Some tasks, such as translation, require the entire input to be considered before producing the output sequence.

    Explanation

    Unlike sequence-to-sequence processing that produces outputs as inputs arrive, an encoder-decoder can wait until the full input is processed, as translation often requires.

  91. 91

    What is the short-term memory problem of a plain RNN?

    1. A

      Information from early inputs may fade from the hidden state by the time a long sequence is processed.

    2. B

      The model permanently stores every input and cannot make predictions.

    3. C

      The model produces only a single output for all possible tasks.

    4. D

      The model cannot accept inputs that contain more than one feature.

    Correct answer
    A

    Information from early inputs may fade from the hidden state by the time a long sequence is processed.

    Explanation

    Plain RNNs can struggle to retain information from the beginning of long sequences, motivating cells such as LSTM and GRU.

  92. 92

    How does an LSTM represent short-term and long-term memory?

    1. A

      It uses the cell state for short-term memory and the input sequence for long-term memory.

    2. B

      It uses the learning rate as short-term memory and momentum as long-term memory.

    3. C

      It uses a hidden state for short-term memory and a cell state for long-term memory.

    4. D

      It uses two output labels and no hidden state.

    Correct answer
    C

    It uses a hidden state for short-term memory and a cell state for long-term memory.

    Explanation

    The LSTM cell uses hidden state hhh for short-term memory and cell state ccc for long-term memory.

  93. 93

    What do the forget, input, and output gates of an LSTM help control?

    1. A

      Which dataset samples to shuffle, which batch to discard, and which class to label.

    2. B

      Which loss function to minimize, which optimizer to use, and which metric to report.

    3. C

      How many layers to create, how many features to accept, and how many epochs to run.

    4. D

      What long-term information to erase, what information to store, and what current output to produce.

    Correct answer
    D

    What long-term information to erase, what information to store, and what current output to produce.

    Explanation

    The gates regulate what to forget from long-term memory, what to add to it, and what to produce as the current output.

  94. 94

    How does a GRU differ from an LSTM as described?

    1. A

      A GRU is a dense layer that predicts only a single class.

    2. B

      A GRU adds a separate long-term cell state and more gates than an LSTM.

    3. C

      A GRU merges long- and short-term memory into one hidden state and does not use an output gate.

    4. D

      A GRU has no hidden state and cannot process sequences.

    Correct answer
    C

    A GRU merges long- and short-term memory into one hidden state and does not use an output gate.

    Explanation

    The GRU is a simplified LSTM variant that uses one hidden state and lacks the LSTM's output gate.

  95. 95

    When might a GRU be preferred over an LSTM?

    1. A

      When its comparable performance is achieved with lower computational complexity.

    2. B

      When the input is not sequential and contains no ordered data.

    3. C

      When a model must use a separate long-term cell state.

    4. D

      When the task requires an output gate that only LSTMs provide.

    Correct answer
    A

    When its comparable performance is achieved with lower computational complexity.

    Explanation

    GRUs are less complex than LSTMs and may require less computation; their relative performance depends on the use case, so comparing both can be useful.

  96. 96

    Why might the time dimension of a sequence batch need to be expanded before it is passed to an RNN?

    1. A

      Recurrent layers require every sequence to be converted into a class label.

    2. B

      Recurrent layers expect batch size, sequence length, and feature dimensions, even when there is only one feature.

    3. C

      Expanding the tensor adds more observations to each sequence.

    4. D

      The extra dimension stores the model's hidden layers.

    Correct answer
    B

    Recurrent layers expect batch size, sequence length, and feature dimensions, even when there is only one feature.

    Explanation

    RNN, LSTM, and GRU inputs require batch, sequence, and feature dimensions; a single-feature sequence may need an added feature dimension.

  97. 97

    Why might model outputs be squeezed before calculating a regression loss?

    1. A

      To convert continuous predictions into class probabilities.

    2. B

      To make their shape match the target tensor's shape.

    3. C

      To add a feature dimension required by the recurrent layer.

    4. D

      To increase the sequence length to match the batch size.

    Correct answer
    B

    To make their shape match the target tensor's shape.

    Explanation

    Loss functions expect their inputs to have matching shapes; squeezing can remove an extra singleton output dimension.

  98. 98

    What is object-oriented programming in the described context?

    1. A

      A training technique that uses objects instead of tensors.

    2. B

      A method for converting all Python functions into neural network layers.

    3. C

      A way to split a model's predictions into input and target arrays.

    4. D

      A way to define objects with attributes that store data and methods that perform tasks.

    Correct answer
    D

    A way to define objects with attributes that store data and methods that perform tasks.

    Explanation

    Object-oriented programming defines objects with attributes for data and methods for actions or tasks.

  99. 99

    What is the purpose of a class's __init__ method?

    1. A

      It converts an object's methods into target labels.

    2. B

      It runs when an object is created and can initialize that object's attributes.

    3. C

      It runs after every optimizer step to calculate accuracy.

    4. D

      It executes only when a dataset is shuffled.

    Correct answer
    B

    It runs when an object is created and can initialize that object's attributes.

    Explanation

    The initialization method is called when an object is created and can assign values, such as a balance, to its attributes.

  100. 100

    Why define a custom PyTorch dataset class?

    1. A

      It guarantees that every sample has the same label.

    2. B

      It replaces the model's forward method with a data loader.

    3. C

      It can specify how data is loaded, how many samples it contains, and what each indexed sample returns.

    4. D

      It automatically selects the optimizer and tunes the learning rate.

    Correct answer
    C

    It can specify how data is loaded, how many samples it contains, and what each indexed sample returns.

    Explanation

    A custom dataset implements initialization and methods for reporting its length and retrieving an indexed sample.

  101. 101

    In a PyTorch model class, what is the role of the forward method?

    1. A

      It resets the model's weights after each batch.

    2. B

      It describes how inputs pass through the model's layers to produce outputs.

    3. C

      It initializes the optimizer's learning rate and momentum.

    4. D

      It loads the dataset and assigns class labels to its files.

    Correct answer
    B

    It describes how inputs pass through the model's layers to produce outputs.

    Explanation

    The forward method defines the computation performed when inputs are passed through the model.

  102. 102

    What is the advantage of defining a PyTorch model as a class rather than using only a simple sequential container?

    1. A

      A class guarantees higher accuracy than every sequential model.

    2. B

      A class eliminates the need to define model layers.

    3. C

      A class offers more flexibility for customized model behavior as complexity grows.

    4. D

      A class automatically performs data augmentation and evaluation.

    Correct answer
    C

    A class offers more flexibility for customized model behavior as complexity grows.

    Explanation

    Sequential models can be convenient for small models, while class-based models provide more flexibility for customization.

  103. 103

    What is a common purpose of a multi-input model?

    1. A

      To replace model inputs with multiple loss functions.

    2. B

      To force a model to predict only one class from one input feature.

    3. C

      To divide a single image into separate training and test sets.

    4. D

      To combine information from multiple sources, such as an image and accompanying text.

    Correct answer
    D

    To combine information from multiple sources, such as an image and accompanying text.

    Explanation

    Multi-input models can combine sources such as multiple images or different modalities, including image and text.

  104. 104

    How does the described two-input character classifier use its inputs?

    1. A

      It processes the character image and alphabet vector separately, concatenates their representations, then classifies.

    2. B

      It converts the image into a label and discards the alphabet vector before classification.

    3. C

      It concatenates the raw image and target label, then predicts the alphabet vector.

    4. D

      It uses the alphabet vector to resize the image and omits the classifier.

    Correct answer
    A

    It processes the character image and alphabet vector separately, concatenates their representations, then classifies.

    Explanation

    The model processes the image and alphabet information with separate subnetworks, concatenates their representations, and uses a classifier to predict the character.

  105. 105

    What does tensor concatenation do?

    1. A

      It joins tensors along a specified dimension.

    2. B

      It multiplies every tensor element by its class label.

    3. C

      It averages tensors and removes their dimensions.

    4. D

      It converts every tensor value to a one-hot vector.

    Correct answer
    A

    It joins tensors along a specified dimension.

    Explanation

    Tensor concatenation joins tensors along the dimension specified by the operation.

  106. 106

    What is a multi-label classification problem?

    1. A

      A model predicts several numerical values but no classes.

    2. B

      An input may belong to multiple classes at the same time.

    3. C

      A model uses several input sources but has only one output.

    4. D

      An input must belong to exactly one of two classes.

    Correct answer
    B

    An input may belong to multiple classes at the same time.

    Explanation

    In multi-label classification, an example can have several labels simultaneously, such as an image containing both a beach and people.

  107. 107

    Why might a very deep model use additional outputs after intermediate blocks?

    1. A

      They reduce the model to a single linear layer.

    2. B

      They replace the need to provide target labels during training.

    3. C

      They ensure that the model ignores its final output layer.

    4. D

      They encourage earlier layers to learn task-relevant features and can act as regularization.

    Correct answer
    D

    They encourage earlier layers to learn task-relevant features and can act as regularization.

    Explanation

    Intermediate outputs can encourage earlier parts of a deep model to learn useful features and may improve robustness through regularization.

  108. 108

    How is the total loss commonly formed for a model with two output tasks?

    1. A

      Use accuracy as the loss for one task and ignore the other task.

    2. B

      Average the model's output probabilities without comparing targets.

    3. C

      Calculate a loss for only the output with the most classes.

    4. D

      Calculate a loss for each output and combine the losses, often by summing them.

    Correct answer
    D

    Calculate a loss for each output and combine the losses, often by summing them.

    Explanation

    Each output has its own target and loss; the losses can be combined, for example by summing them, to create an optimization objective.

  109. 109

    If character classification is twice as important as alphabet classification, how can this be reflected in a combined loss?

    1. A

      Give the character loss twice the weight of the alphabet loss.

    2. B

      Remove the alphabet loss and double the model's output size.

    3. C

      Give the alphabet loss twice the weight of the character loss.

    4. D

      Divide both losses by the number of training samples and ignore their relative importance.

    Correct answer
    A

    Give the character loss twice the weight of the alphabet loss.

    Explanation

    Loss weights express the relative importance of tasks; a more important character-classification loss can be assigned a larger weight.

  110. 110

    Why can combining an MSE loss for house prices with a much smaller cross-entropy loss be problematic?

    1. A

      Cross-entropy cannot be used with a model that also predicts continuous values.

    2. B

      The optimizer cannot update a model that has two output layers.

    3. C

      MSE always converts the classification output into a regression target.

    4. D

      The much larger MSE may dominate the combined objective, causing the model to neglect the quality-classification task.

    Correct answer
    D

    The much larger MSE may dominate the combined objective, causing the model to neglect the quality-classification task.

    Explanation

    If loss magnitudes are on very different scales, the larger loss can dominate optimization and effectively cause the model to ignore the smaller one.

  111. 111

    How can differently scaled loss components be brought to more comparable ranges?

    1. A

      Replace each loss with the model's parameter count.

    2. B

      Multiply the larger loss by a still larger constant.

    3. C

      Scale each loss, for example by dividing by the maximum value in its batch.

    4. D

      Convert all continuous targets into class indices.

    Correct answer
    C

    Scale each loss, for example by dividing by the maximum value in its batch.

    Explanation

    The material describes scaling losses by dividing by a batch maximum to bring them into a more comparable range before combining or weighting them.

  112. 112

    What is the recommended first check when beginning work on a new deep learning problem?

    1. A

      Run a large hyperparameter search before building the model.

    2. B

      Try to overfit a single training example to verify the problem and implementation are workable.

    3. C

      Train on the complete dataset without checking a forward pass.

    4. D

      Apply the strongest possible regularization and evaluate only the test set.

    Correct answer
    B

    Try to overfit a single training example to verify the problem and implementation are workable.

    Explanation

    Training on one example can expose bugs and check that the problem is solvable; a correctly configured model should quickly fit it closely.

  113. 113

    After confirming that a model can fit one example, what is a sensible next step?

    1. A

      Freeze every layer and evaluate only on the validation set.

    2. B

      Tune exclusively on the test set before completing training.

    3. C

      Scale training to the full training set using a model large enough to overfit initially.

    4. D

      Reduce the model until it cannot fit the training examples.

    Correct answer
    C

    Scale training to the full training set using a model large enough to overfit initially.

    Explanation

    Once the single-example check works, train on the full training set with a sufficiently capable model to establish that the task can be learned.

  114. 114

    What is transfer learning?

    1. A

      Reusing a model trained on one task as a starting point for a second task.

    2. B

      Transferring loss values from a classification task into an accuracy metric.

    3. C

      Moving a dataset from the training set into the validation set.

    4. D

      Copying predictions from a test set into the model's target labels.

    Correct answer
    A

    Reusing a model trained on one task as a starting point for a second task.

    Explanation

    Transfer learning reuses a model trained on an initial task, such as by loading its weights to start training on a new dataset.

  115. 115

    What characterizes fine-tuning in the described transfer-learning setup?

    1. A

      Starting from previously trained weights and training on a related task with a smaller learning rate.

    2. B

      Freezing every layer and avoiding all further training.

    3. C

      Changing the dataset labels without updating the model.

    4. D

      Starting from random weights and using a larger learning rate on an unrelated task.

    Correct answer
    A

    Starting from previously trained weights and training on a related task with a smaller learning rate.

    Explanation

    Fine-tuning reuses pretrained weights for a related task and typically uses a smaller learning rate.

  116. 116

    Which layers are commonly frozen first when fine-tuning a model?

    1. A

      Only layers that have no weights or biases.

    2. B

      Earlier layers, while layers nearer the output are more likely to be fine-tuned.

    3. C

      Every layer, because freezing is required for fine-tuning.

    4. D

      Only the final output layer, while earlier layers are always trained.

    Correct answer
    B

    Earlier layers, while layers nearer the output are more likely to be fine-tuned.

    Explanation

    A rule of thumb is to freeze early layers and fine-tune layers closer to the output, where task-specific changes are more likely to be useful.

  117. 117

    What does setting a parameter's requires_grad attribute to false do in the described freezing workflow?

    1. A

      It makes the parameter determine the model's batch size.

    2. B

      It changes the parameter into a target label.

    3. C

      It prevents that parameter from receiving gradient-based updates.

    4. D

      It forces the parameter to take a random value in every batch.

    Correct answer
    C

    It prevents that parameter from receiving gradient-based updates.

    Explanation

    A parameter with gradient tracking disabled is not trained through gradient-based updates, which is how selected layers can be frozen.

  118. 118

    What is the goal of the model-development strategy of first overfitting and then reducing overfitting?

    1. A

      Verify the task is learnable, then use validation performance to guide improvements in generalization.

    2. B

      Avoid using validation data until after the test set is evaluated.

    3. C

      Ensure the final model memorizes the training set as accurately as possible.

    4. D

      Choose the model with the largest training loss and smallest capacity.

    Correct answer
    A

    Verify the task is learnable, then use validation performance to guide improvements in generalization.

    Explanation

    The strategy first checks that the model can learn the task, then applies measures to improve validation performance and generalization.

  119. 119

    How does grid search explore hyperparameters?

    1. A

      It changes parameters according to class labels in the test set.

    2. B

      It selects one random value and never evaluates alternatives.

    3. C

      It automatically adds new model layers after each epoch.

    4. D

      It evaluates specified parameter values at fixed intervals.

    Correct answer
    D

    It evaluates specified parameter values at fixed intervals.

    Explanation

    Grid search tests predefined values, such as selected learning rates and momentum values.

  120. 120

    How does random search differ from grid search?

    1. A

      It searches only over the number of output classes.

    2. B

      It tests every possible value in a fixed interval.

    3. C

      It samples parameter values from a range rather than testing only a fixed set of values.

    4. D

      It changes model parameters without measuring validation performance.

    Correct answer
    C

    It samples parameter values from a range rather than testing only a fixed set of values.

    Explanation

    Random search selects values randomly within defined ranges and can explore a broader variety of settings without testing every grid point.

  121. 121

    What does small weight initialization help prevent?

    1. A

      Unstable or extreme layer outputs that can slow training.

    2. B

      The use of activation functions in hidden layers.

    3. C

      The model from ever producing a nonzero gradient.

    4. D

      The creation of input features in the dataset.

    Correct answer
    A

    Unstable or extreme layer outputs that can slow training.

    Explanation

    Small weights, together with appropriately scaled inputs, help keep weighted sums stable rather than producing extreme values.

  122. 122

    What variance properties should a suitable layer initialization aim to maintain?

    1. A

      Input and output variances should be close, and gradient variance should remain similar across the layer.

    2. B

      Input variance should be much larger than output variance, regardless of activation.

    3. C

      Output variance should always be zero, and gradient variance should always increase.

    4. D

      Both input and gradient variances should change unpredictably between layers.

    Correct answer
    A

    Input and output variances should be close, and gradient variance should remain similar across the layer.

    Explanation

    The material describes initialization methods that aim to preserve the variance of activations and gradients across layers.

  123. 123

    Why is He initialization used with ReLU and similar activations?

    1. A

      It is designed to provide appropriate variance properties for layers using those activations.

    2. B

      It prevents the model from using bias parameters.

    3. C

      It replaces backpropagation with a fixed parameter update.

    4. D

      It converts ReLU outputs into class probabilities.

    Correct answer
    A

    It is designed to provide appropriate variance properties for layers using those activations.

    Explanation

    He initialization is described as an appropriate initialization method for ReLU and similar activation functions.

  124. 124

    What is the dying-neuron problem associated with standard ReLU?

    1. A

      A neuron produces unbounded gradients for every negative input.

    2. B

      A neuron permanently outputs one for all positive inputs.

    3. C

      A neuron may output zero for negative inputs and receive no useful gradient to resume learning.

    4. D

      A neuron cannot be used in any layer with learned weights.

    Correct answer
    C

    A neuron may output zero for negative inputs and receive no useful gradient to resume learning.

    Explanation

    Because ReLU is zero for negative inputs, a neuron can stop learning if its inputs remain negative.

  125. 125

    Why can ELU help address a drawback of ReLU?

    1. A

      It outputs zero for every negative value and therefore eliminates negative gradients.

    2. B

      It removes the need for layer initialization.

    3. C

      It converts all outputs into a probability distribution.

    4. D

      It has nonzero gradients for negative values and an average output near zero.

    Correct answer
    D

    It has nonzero gradients for negative values and an average output near zero.

    Explanation

    ELU is described as having nonzero gradients for negative inputs and an average output near zero, helping address dying neurons and gradient issues.

  126. 126

    What operations define batch normalization in the described process?

    1. A

      Multiply by the batch mean, add the standard deviation, then remove all learned parameters.

    2. B

      Subtract the batch mean, divide by the standard deviation, then learnable scaling and shifting.

    3. C

      Drop half the inputs, freeze the layer, and replace its gradients with zeros.

    4. D

      Convert the batch to class indices, sort it, and apply a softmax.

    Correct answer
    B

    Subtract the batch mean, divide by the standard deviation, then learnable scaling and shifting.

    Explanation

    Batch normalization first normalizes outputs using their mean and standard deviation, then learns scale and shift parameters.

  127. 127

    Where is a batch-normalization layer placed in the described model construction?

    1. A

      Between the optimizer and the test DataLoader.

    2. B

      Before the input data, with an input size unrelated to preceding layers.

    3. C

      After the final loss function, with one input for every target label.

    4. D

      After a layer whose output size matches the batch-normalization input size, before the activation.

    Correct answer
    D

    After a layer whose output size matches the batch-normalization input size, before the activation.

    Explanation

    The example passes a linear layer's output into batch normalization and then sends the result to the activation function; the normalization input size must match the preceding output size.

  128. 128

    What problem can occur when gradients vanish in earlier layers?

    1. A

      Those layers receive excessively large updates and diverge.

    2. B

      Those layers automatically gain more output classes.

    3. C

      Those layers stop passing input data to the forward pass.

    4. D

      Those layers receive very small updates and learn poorly.

    Correct answer
    D

    Those layers receive very small updates and learn poorly.

    Explanation

    Vanishing gradients become smaller during backpropagation, so earlier layers may receive hardly any parameter updates.

  129. 129

    What problem can occur when gradients explode?

    1. A

      Parameter updates become excessively large and training can diverge.

    2. B

      Parameter updates become too small for early layers to learn.

    3. C

      The model's input tensors lose their feature dimension.

    4. D

      The model's predicted classes become uniformly distributed.

    Correct answer
    A

    Parameter updates become excessively large and training can diverge.

    Explanation

    Exploding gradients grow increasingly large, leading to huge parameter updates and potentially divergent training.

  130. 130

    Why can careful initialization and activation choices be insufficient on their own to prevent gradient instability?

    1. A

      Initialization and activations affect only the test set, not training.

    2. B

      Appropriate activations prevent the model from calculating any gradients.

    3. C

      Initial weights are never used once a forward pass begins.

    4. D

      Unstable gradients can return during training even if the model starts with suitable weights and activations.

    Correct answer
    D

    Unstable gradients can return during training even if the model starts with suitable weights and activations.

    Explanation

    Good initialization and activations can alleviate instability at the start, but batch normalization may also help because problems can recur during training.

  131. 131

    Which combination is presented as a three-part approach to gradient instability?

    1. A

      Dropout, one-hot encoding, and a larger batch size only.

    2. B

      Random data splits, softmax in every layer, and fixed weights.

    3. C

      Appropriate weight initialization, suitable activations, and batch normalization.

    4. D

      A larger test set, more output classes, and lower accuracy.

    Correct answer
    C

    Appropriate weight initialization, suitable activations, and batch normalization.

    Explanation

    The described three-step solution consists of proper weight initialization, good activation choices, and batch normalization.

Question 1 of 131
Question 1 of 131

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent