Lesson 18: Regularisation, Debugging and Responsible Deployment
Regularisation is the family of techniques that stop a network from memorising its training data and push it towards learning the shared pattern instead. The simplest is weight decay: a small penalty added to the loss for large weights, which keeps the network's numbers modest and prevents it from bending sharply to fit individual examples. A network with small weights must find a smoother explanation, and smooth explanations usually generalise better.
Dropout is a stranger idea that works remarkably well. During training, each neuron is randomly switched off with some probability — say, one in five — on each step, so the network can never rely on any single neuron. Every neuron must learn something useful on its own, and the network becomes a kind of committee in which no member is indispensable. At test time all neurons are switched back on, and the network behaves like an average of the many versions that were trained. Dropout is turned off for evaluation, which is why a model's training loss can look worse than its validation loss when dropout is in use.
Debugging Before Deployment
Before a model is deployed — put into use where real people depend on it — it deserves the debugging discipline of Lesson 8, applied to the whole system. Check that the data it will see matches the data it trained on: a model trained on clear photos will struggle with blurry ones from a cheap camera. Check its errors by group, not just overall: a model that is accurate on average can still fail badly for one group of users, and an average hides that. And check what happens at the edges: empty inputs, unexpected formats, images far larger or smaller than the training set. The failures you find in testing are gifts; the ones you find after deployment are incidents.
Deployment also means deciding what happens when the model is unsure. A model that says "I don't know" and hands the case to a person is often far more useful than one that guesses confidently. Setting a threshold — below which the model abstains — is a design decision, not an afterthought, and it should be chosen with the cost of mistakes in mind, as in Lesson 17.
Responsibility Does Not End at Launch
Once deployed, a model needs watching. The world changes: the pictures, words or measurements it receives drift away from its training data, and its performance can decay silently. Plan to re-measure it regularly on fresh data, keep a record of which version is running, and keep a way to roll back to the previous version if the new one misbehaves. A deployed model is not a finished product; it is a system that needs care, and the people affected by its decisions deserve to know it exists, what it does, and how to challenge it.
Dropout in Practice
Dropout has a few practical details worth knowing. The dropout rate — the fraction of neurons switched off — is usually between 0.1 and 0.5, and it is applied to the larger layers where overfitting is worst, not to every layer. It is also important to remember that dropout is only active during training: when you evaluate the model, or use it to make predictions, all neurons are on. Forgetting this distinction is a common source of confusion, because a model evaluated with dropout still on will score worse than it should, and the gap can look like a mysterious failure.
There is a related habit that belongs here: when you add a regularisation technique, change one thing at a time and measure the effect on the validation set. Adding dropout, weight decay and early stopping all at once may improve the model, but you will not know which of them did the work, and you will not know what to keep in the next project. Regularisation is a set of tools, and like any tools, they are best learned one at a time, with the validation set as the judge.
Key Terms
- Regularisation
- Techniques that discourage memorisation and push a model towards the shared pattern.
- Weight decay
- A penalty on large weights, added to the loss, that keeps a network's numbers modest.
- Dropout
- Randomly switching neurons off during training so the network cannot rely on any single one.
- Deployment
- Putting a trained model into real use, where people depend on its outputs.
- Model drift
- When the data a deployed model receives slowly changes away from its training data.
- Abstention
- A model declining to answer when it is unsure, instead of guessing.
- Rollback
- Returning to a previous model version after a new one misbehaves.
Discussion Questions
- Dropout randomly disables neurons during training. Why does making training harder produce a better model?
- A model is accurate on average but fails for one group of users. Why is the average the wrong number to report?
- When should a model say 'I don't know' instead of guessing? Who should decide the threshold?
Practice Questions
- What does weight decay do?
- What is dropout?
- Why might training loss look worse than validation loss when dropout is used?
- What is model drift?
- Give two checks to run before deploying a model.
Show answers
- It adds a penalty for large weights to the loss, keeping the network's numbers modest so it must find a smoother explanation. Smoother explanations usually generalise better.
- Randomly switching neurons off during training, so the network cannot rely on any single neuron. At test time all neurons are on, and dropout is turned off for evaluation.
- Because dropout is active during training — making the task harder — but turned off during evaluation. The validation pass runs the full, undamaged network.
- When the data a deployed model receives slowly changes away from its training data, so its performance can decay over time. That is why deployed models need regular re-measurement.
- Any two of: check the live data matches the training data; check errors by group, not just on average; test edge cases like empty or unexpected inputs; or set a threshold for when the model should abstain.