§11.4.1 Manual hyperparameter tuning
To tune by hand you must understand the link between hyperparameters, training error, generalization error, and compute. The primary goal is to match the model’s effective capacity to the task. Effective capacity is limited by three things: the model’s representational capacity, the optimizer’s ability to actually minimize the training cost, and the degree of regularization. A huge model helps nothing if optimization can’t find good functions or if weight decay forbids them.
Generalization error is U-shaped in most capacity-controlling hyperparameters (recall fig 5.3): too little capacity underfits (high training error), too much overfits (large train/test gap), and the sweet spot sits between. But not every hyperparameter can traverse the whole U — weight decay ≥ 0 can only subtract capacity, so if the model underfits at zero weight decay, that knob can’t rescue it.
The learning rate is the single most important hyperparameter — if you can tune only one, tune it. Its training-error curve is U-shaped, but for a subtler reason than capacity: too large and gradient descent diverges; too small and training stalls (or gets permanently stuck):
Most hyperparameters can be set by reasoning about whether they increase or decrease capacity. Click any row for the caveat:
| Adds capacity when… | Reason | |
|---|---|---|
| Number of hidden units | increased | more units → higher representational capacity |
| Learning rate | tuned optimally | an improper rate (too high or too low) gives low effective capacity via optimization failure |
| Convolution kernel width | increased | a wider kernel adds parameters |
| Implicit zero-padding | increased | padding before convolution keeps the representation size large |
| Weight-decay coefficient | decreased | smaller decay frees parameters to become larger |
| Dropout rate | decreased | dropping units less often lets them co-adapt to fit the training set |
The usual recipe for best results: a large model, regularized well (e.g. with dropout). Brute force: keep increasing capacity and training-set size until the task is solved (given the compute).
§11.4.2 Automatic hyperparameter optimization
The ideal learner takes a dataset and returns a function with no hand-tuning. Since a human tuning hyperparameters is really optimizing validation error, we can wrap the learner in a hyperparameter optimization algorithm that hides the knobs. These wrappers have their own secondary hyperparameters (e.g. the search range per hyperparameter), but those are usually far easier to set — often the same values work across many tasks.
§11.4.3 Grid search
With three or fewer hyperparameters, the common approach is
grid search grid search A hyperparameter search that trains a model for every combination in the Cartesian product of a small value set per hyperparameter (usually log-scaled, repeated/zoomed). Cost grows exponentially, O(nᵐ), with the number of hyperparameters.
defined in ch. 11 — open in glossary
: pick a small finite value set per
hyperparameter and train a model for every combination in their Cartesian
product, keeping the best on the validation set. Choose values on a logarithmic
scale (e.g. learning rate in {.1, .01, 10⁻³, 10⁻⁴, 10⁻⁵}), and repeat the
search — if the best value is at a boundary, shift the grid; if it’s in the
middle, zoom in. The fatal drawback: with hyperparameters each taking
values, the cost is — exponential. Even loose parallelism can’t
rescue a large search.
§11.4.4 Random search
Random search random search A hyperparameter search that samples each hyperparameter from a marginal distribution (e.g. log-uniform) instead of a fixed grid. Exponentially more efficient than grid search when only a few hyperparameters matter, because no two trials are wasted on equivalent settings. defined in ch. 11 — open in glossary is as simple to program, more convenient, and converges faster (Bergstra & Bengio 2012). Define a marginal distribution per hyperparameter and sample joint configurations — for a positive real-valued hyperparameter, a log-uniform log-uniform distribution A distribution for sampling a positive hyperparameter uniformly on a logarithmic scale: sample log₁₀(v) ~ u(a,b), then v = 10^(that). Used in random search for learning rates, hidden-unit counts, etc. defined in ch. 11 — open in glossary distribution:
Log-uniform sampling (eqs 11.2–11.3)
| a sample from the uniform distribution on the interval (a, b) | sampler | |
| sample the EXPONENT uniformly, so the learning rate is uniform on a log scale (10⁻¹ … 10⁻⁵) | log space | |
| exponentiate to recover the actual value — do NOT bin/discretize, which would waste the extra resolution for free | value |
Why does this win? When only a few hyperparameters matter, grid search wastes computation that is exponential in the number of irrelevant hyperparameters — it re-tests the same value of an influential axis for every combination of the useless ones. Random search tests a distinct value of each influential hyperparameter on nearly every trial. Toggle the two below and watch the number of distinct important-axis values explode under random search for the same budget:
Grid search spends all 16 trials on only 4 distinct values of the important axis — every column repeats the same x for each irrelevant y, wasting effort when a hyperparameter doesn't matter.
Like grid search, random search benefits from being repeated, refining the sampling ranges based on the first run’s results. Next: model-based optimization, debugging strategies, and the full Street View case study — model-based optimization, debugging & the Street View example.
Check yourself — manual tuning, grid search, and random search
1.The goal of manual hyperparameter tuning is to match the model's EFFECTIVE capacity to the task. What three factors constrain effective capacity?
2.How does generalization error typically behave as a function of a capacity-controlling hyperparameter?
3.If you can tune only one hyperparameter, which should it be, and why?
4.According to Table 11.1, which change INCREASES model capacity?
5.What is grid search, and what is its main drawback?
6.Why does random search often beat grid search for the same budget? (See the GridRandomLab.)