Lawfare Academy

AI 301 — Machine Learning, Neural Networks and Language · Weeks 9–11

Neural networks, backpropagation and generalization

Full teaching sequence and cumulative subject work

Study the complete on-site source sections below, then work the original example, changed-condition problem and transfer laboratory. Study Dive into Deep Learning Multilayer Perceptrons, Forward/Backward Propagation, Numerical Stability, Dropout and the Builders’ Guide; complete the associated derivations and implementation exercises.

Train a logistic model and expose a changed mechanism — primary material, constructed-response tasks, complete worked model and changed-case examination →

Backpropagation as a local chain rule

A neural network composes functions. Backpropagation applies the chain rule to local derivatives and accumulates contributions along paths. For h=ReLU(wx+b) and output v·h, a negative preactivation makes the derivative through that ReLU path zero. It does not prove the entire network has zero gradient or that no other input can activate that unit.

Distinguish representation from learning. Supplying weights that realize a function demonstrates expressiveness; it does not establish that an optimizer will discover those weights from limited data. Training evidence requires a specified loss, data, initialization, updates and independent evaluation.

Worked problem

Let x=2,w=1,b=−1,v=3,y=0, output=v·ReLU(wx+b), and loss=.5(output−y)². Compute output and gradients with respect to v and w.

Trace the complete reasoning
  1. Preactivation is 1, so h=1 and output=3. The loss is 4.5; dL/doutput=3.

  2. doutput/dv=h=1, so dL/dv=3.

  3. The active ReLU derivative is 1. doutput/dw=v×1×x=6, hence dL/dw=18. Similarly dL/db=9.

  4. If w becomes 0 with the other parameters unchanged, preactivation is −1 and this path’s gradients with respect to w,b and v are zero for this example. The statement is local to this input and path.

Independent transfer problem

Two hidden units contribute to the output; one is inactive and the other active. Does the inactive unit prove the model cannot learn from this example?

Compare the transfer solution

No. The active unit can transmit nonzero gradients, and any output bias can also update. Compute each path’s derivative and sum contributions for shared parameters. Avoid replacing a local zero derivative with a global training claim. Inspect gradient values and loss changes numerically on a small example.

Learning objectives

  • Explain and trace the mechanisms in neural networks, backpropagation and generalization.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

Study the mechanism

A neural network composes parameterized transformations with nonlinearities. A layer forms weighted combinations; an activation allows the composition to represent more than a single linear map. Stacking linear transformations without nonlinearities remains linear, regardless of how many layers are used. Architecture determines representation capacity, but training data and optimization determine what is actually learned.

Backpropagation applies the chain rule through the computation graph to obtain gradients. A zero gradient through an inactive ReLU can prevent a unit from changing for that example. Initialization, scaling and numerical stability influence whether learning proceeds. Use small synthetic examples where expected behavior is known before training a large network whose failures are difficult to diagnose.

Generalization still requires held-out evaluation. More parameters can memorize noise. Weight decay, dropout, data augmentation and early stopping address different mechanisms and are not interchangeable guarantees. Early stopping uses validation behavior to choose a training duration, so the validation set is part of development. A large model with impressive demonstrations may still fail on the task's difficult cases. Measure latency, memory and training cost alongside predictive quality.

Worked example

def relu(x):
    return max(0.0, x)

# A tiny two-unit hidden layer, chosen weights rather than trained.
def network(x1, x2):
    h1 = relu(x1 - x2)
    h2 = relu(x2 - x1)
    return h1 + h2

assert network(5, 2) == 3
assert network(2, 5) == 3

The hidden units capture positive and negative differences separately. Their sum equals the absolute difference of the two inputs. A single linear function cannot represent absolute difference over the whole plane. The example demonstrates representational structure, not that gradient descent will necessarily discover these exact weights from arbitrary training data.

Check your understanding

Why do stacked linear layers without activations remain limited?

  1. Their composition is still one linear transformation
  2. They automatically become a probability model
  3. Adding layers always prevents overfitting
Answer and reasoning for every option

Correct: Their composition is still one linear transformation Matrix products compose into another linear map.

Reconsider: They automatically become a probability model Probability interpretation requires an appropriate output and objective.

Reconsider: Adding layers always prevents overfitting More layers alone do not guarantee generalization.

Transfer laboratory: A dead ReLU and gradient flow

For h=ReLU(wx+b), let x=1, w=−2 and b=0. What is h and its local gradient with respect to w away from the kink? Explain the training implication.

Work through the full solution

The preactivation is −2, so h=0. On this negative region ReLU has derivative zero, making dh/dw=0 for this example. The unit receives no gradient signal through this path. Different inputs or parameter changes elsewhere can alter the region; do not claim that every zero activation makes the entire network permanently untrainable.

Evidence of understanding

Compute zero output and gradient while limiting the conclusion to the stated path and example.

Complete on-site teaching readings

These are full attributed source sections, not previews. Read them alongside the original Academy explanation and code.

  1. 5.1. Multilayer Perceptrons Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  2. 5.3. Forward Propagation, Backward Propagation, and Computational Graphs Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  3. 5.4. Numerical Stability and Initialization Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  4. 5.6. Dropout Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  5. 12.3. Gradient Descent Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  6. 12.4. Stochastic Gradient Descent Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  7. 12.10. Adam Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  8. 1.17. Neural network models (supervised) · The scikit-learn developers

Open in My Learning to record progress →