Skip to content

Chapter 4 checkpoint

Ten questions to check the complete neural-network workflow.

Choose one answer per question. Read the feedback for every option, then revisit the relevant episode if the reason is unclear.

Checkpoint

1 · Predictions and targets

Predictions have shape (8, 1) and regression targets have shape (8,). What should you do before subtracting them?

  1. Make their shapes identical, preserving the sample axis.

    Correct. Correct: otherwise broadcasting can produce an 8-by-8 matrix of pairwise differences.

  2. Multiply both by the batch size.

    Not quite. This changes values but does not correct the shape mismatch.

  3. Assume subtraction automatically pairs the rows.

    Not quite. Broadcasting follows shape rules, not the scientific meaning of samples.

Checkpoint

2 · Backward and step

What does loss.backward() do?

  1. Calculate gradients of the loss with respect to tracked parameters.

    Correct. Correct: an optimiser step then uses these gradients to update the parameters.

  2. Choose the next learning rate from the validation set.

    Not quite. That is a separate tuning or scheduling decision.

  3. Update all weights to the optimum.

    Not quite. Backward calculates derivatives; it neither updates parameters nor solves the optimisation problem.

Checkpoint

3 · Gradient storage

Why does an ordinary mini-batch loop clear gradients before a new update?

  1. New gradients otherwise accumulate with previous gradients.

    Correct. Correct: accumulation is useful when deliberate, but differs from a fresh gradient per batch.

  2. The training data must be deleted after every batch.

    Not quite. Clearing gradients does not delete the input dataset.

  3. Clearing gradients resets the learned weights.

    Not quite. The weights are retained; gradient storage is cleared.

Checkpoint

4 · Nonlinearity

Two affine layers are stacked without an activation. What kind of function can their composition represent?

  1. Another affine function.

    Correct. Correct: the matrix products and biases can be combined into one affine transformation.

  2. Every nonlinear function if enough parameters are added.

    Not quite. Width alone does not make a composition of affine maps nonlinear.

  3. Only a constant function.

    Not quite. The output can still vary linearly with the input.

Checkpoint

5 · Binary loss

What should be supplied to BCEWithLogitsLoss for a single binary target?

  1. Raw logits and floating-point zero/one targets with matching shapes.

    Correct. Correct: the loss includes the probability transformation in a stable calculation.

  2. Sigmoid probabilities that have already been rounded to zero or one.

    Not quite. Hard decisions discard information and violate the raw-logit interface.

  3. Integer class indices for a four-class problem and one output.

    Not quite. A mutually exclusive four-class problem usually needs four logits and CrossEntropyLoss.

Checkpoint

6 · Batch averages

Five batches contain 20 samples each and a final batch contains 3. How should you calculate the epoch mean loss from batch means?

  1. Weight each batch mean by its number of samples, then divide by 103.

    Correct. Correct: every observation receives equal weight.

  2. Average all six batch means equally.

    Not quite. This overweights the final three samples.

  3. Keep only the final batch’s loss.

    Not quite. That does not summarise the complete training epoch.

Checkpoint

7 · Evaluation mode

Which pair is appropriate for validation of a network containing dropout?

  1. model.eval() together with torch.no_grad().

    Correct. Correct: one changes module behaviour, the other disables gradient tracking.

  2. Only torch.no_grad(), because it disables dropout.

    Not quite. No-grad does not change dropout’s training behaviour.

  3. model.train() followed by an optimiser step on the validation loss.

    Not quite. That fits the validation data and invalidates its held-out role.

Checkpoint

8 · Early stopping

The selected validation checkpoint is from epoch 30, while patience expires at epoch 42. Which model should you retain?

  1. The independent saved copy of epoch-30 weights.

    Correct. Correct: restore the checkpoint selected by the stated validation rule.

  2. Epoch 42 because it trained longest.

    Not quite. That ignores the selection rule and may retain an overfitted model.

  3. Whichever of the two scores better on the final test set.

    Not quite. This would use the test set to choose an epoch.

Checkpoint

9 · Reproducibility

Which statement about a fixed seed is justified?

  1. It helps repeat a run in the same environment, but does not establish robustness across seeds or environments.

    Correct. Correct: save the procedure and software versions, and assess variability separately.

  2. It guarantees identical results on every future device and library version.

    Not quite. Numerical kernels and implementations can change across environments.

  3. It makes a single test split an exact estimate of future performance.

    Not quite. Fixing randomness does not eliminate sampling uncertainty or distribution shift.

Checkpoint

10 · Choosing the model

A network and ridge regression are close on validation RMSE. What is a defensible next step?

  1. Apply a declared selection rule that considers performance and complexity, then evaluate the fixed procedure once on test data.

    Correct. Correct: a simpler model can be preferable, and the test set estimates the chosen procedure.

  2. Run many network seeds on the test set and report the best one.

    Not quite. This selects on test noise and gives an optimistic estimate.

  3. Choose the network because more parameters guarantee better generalisation.

    Not quite. Capacity is not evidence of usefulness on new observations.