Weight decay and the effective number of parameters
10 questions on the sum-of-squares penalty, the Gaussian prior view, why weights decay, which weights shrink most and what effective parameters are.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
The penalty is half the strength lambda times the square of a weight. With lambda equal to 0.1 and a weight of 4, how much does the penalty contribute to the gradient with respect to that weight?
- 0.4
- 0.8
- 1.6
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
A network with millions of weights can easily bend itself to fit every wrinkle in a small training set, including the wrinkles that are just noise. One remedy is to limit the number of weights. A gentler remedy is to leave all of them in place but make large values costly, so that a weight is allowed to be big only when the data really demands it. That is weight decay, the simplest and most widely used form of regularisation. It adds a penalty to the training error, and the strength of that penalty becomes the dial that controls how complex the model effectively is.
This quiz takes the idea apart. You will see what the penalty is made of and why it has the name it does, how it can be read as a statement of prior belief about the weights, and why its gradient is so easy to compute that it costs almost nothing to add. You will then look at its geometry, which is the most illuminating part. When the penalty pulls the best weights towards zero, it does not pull all of them equally: some are shifted a lot and others hardly at all, and the difference tells you something deep about which weights the data really needs.
This leads to the idea of the effective number of parameters, the count of weights that stay active after regularisation. It starts at the full number when the penalty is absent and falls to nothing as the penalty grows without limit. The questions use small numbers to make this concrete, and they ask what has been traded: the choice of how many parameters to use becomes the choice of how strong a penalty to apply.
Typical misconceptions deserve attention. Weight decay is not the same as deleting weights, it does not shrink every weight by the same amount, and it does not remove the need to choose something. It also expresses a belief about the weights, not about the function that the network computes, which is a limitation when the knowledge you have concerns the function. Weight decay is also a good example of how a tiny change to the objective can reshape everything about training. A single extra term, one line of code, alters the surface that gradient descent explores, changes which solutions are reachable and affects how well the final model copes with new data. That makes it a fine test case for the habit of asking, whenever a technique helps, what it does to the error surface and what assumption it silently encodes.
The quiz suits learners who have met overfitting and want to understand the standard cure, and practitioners who set a weight decay value by habit. It needs only simple arithmetic and pictures. There are 10 questions, each with an explanation, and it takes about four minutes.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. After each answer an explanation shows why the correct option is right and why the tempting alternatives are not.
›What is weight decay?
It is a regulariser that adds to the training error a term proportional to the sum of the squares of all the weights. Because large weights make that term large, training prefers solutions in which weights are small unless the data insist otherwise. The proportionality constant sets the strength of the effect, and it is one of the main hyperparameters of many training recipes.
›Why is it called decay?
In training procedures that update the weights step by step, the penalty adds a pull towards zero to every update, so that a weight which receives no support from the data gradually shrinks. The weights decay towards zero unless the error gradient keeps them away. The name describes that behaviour, as opposed to the form of the penalty itself.
›How does weight decay relate to a prior distribution?
The penalty is, up to constants, the negative logarithm of a Gaussian distribution centred on zero placed over the weights. Using it is therefore like stating a prior belief that weights are probably small and equally likely to be positive or negative. This gives the technique a probabilistic reading that links it to Bayesian methods.
›Is it easy to use with gradient descent?
Yes, and that is a large part of its appeal. The derivative of the penalty is simply a multiple of the weight itself, so the extra computation is trivial. The factor of one half that is usually written in front of the penalty exists precisely so that it cancels when the derivative is taken.
›Which weights shrink the most?
Those on which the error depends least. If a change in a weight barely affects the fit to the data, the penalty's pull is not resisted, and the weight is driven close to zero. If the error is highly sensitive to the weight, the data push back, and the weight moves only a little. In this sense the penalty suppresses parameters that contribute little to accuracy.
›What is the effective number of parameters?
It is the number of parameters that remain active after regularisation, in the sense that the output is still sensitive to them. With no penalty, all of them are active. As the penalty grows, more of them are effectively switched off, and with an enormous penalty none remain. It formalises the idea that regularisation controls complexity without removing any weights.
›Does weight decay solve the problem of choosing model size?
It changes the problem. Instead of choosing the number of parameters, you must choose the strength of the penalty. That is usually easier, since it is a single continuous number which can be tuned by comparing results on held-out data, but it does not go away.