Lawfare Group → Knowledge Institute → Lawfare Academy
← AI 301 — Machine Learning, Neural Networks and Language
Weeks 9–11
Neural networks, backpropagation and generalization
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.
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 reasoning 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.
Extended teaching and laboratory
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.
Step-by-step reasoning 1. Preactivation is 1, so h=1 and output=3. The loss is 4.5; dL/doutput=3.
- doutput/dv=h=1, so dL/dv=3.
- The active ReLU derivative is 1. doutput/dw=v×1×x=6, hence dL/dw=18. Similarly dL/db=9.
- 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.
Apply the idea
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.
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?
Read the worked reasoning
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.
Check understanding
Why do stacked linear layers without activations remain limited?
- Their composition is still one linear transformation
Feedback
Matrix products compose into another linear map.
- They automatically become a probability model
Feedback
Probability interpretation requires an appropriate output and objective.
- Adding layers always prevents overfitting
Feedback
More layers alone do not guarantee generalization.
Further reading
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.
- 5.1. Multilayer Perceptrons Open the notebook in SageMaker Studio Lab
- 5.3. Forward Propagation, Backward Propagation, and Computational Graphs Open the notebook in SageMaker Studio Lab
- 5.4. Numerical Stability and Initialization Open the notebook in SageMaker Studio Lab
- 5.6. Dropout Open the notebook in SageMaker Studio Lab
- 12.3. Gradient Descent Open the notebook in SageMaker Studio Lab
- 12.4. Stochastic Gradient Descent Open the notebook in SageMaker Studio Lab
- 12.10. Adam Open the notebook in SageMaker Studio Lab
- 1.17. Neural network models (supervised)