The Hessian of a neural network: cost and cheap approximations
10 questions on the cost of second derivatives, Hessian-vector products, diagonal and outer-product approximations and when each is valid.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
A team with 10 million weights needs only the product of the Hessian with one particular vector. Must they build the full Hessian?
- No: an extension of backpropagation gives the product at a cost proportional to the number of weights
- Yes, because there is no other way to obtain the product
- No, but only because the product is always zero
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
If gradient descent is like walking downhill with your eyes on the slope under your feet, second-order methods are like walking with a map of how the ground curves. They can take far better steps, because they know whether the valley ahead is narrow or wide. The map is the Hessian, the table of second derivatives of the error with respect to every pair of weights. There is only one problem with this map: for a large network, it is gigantic.
This quiz is about that tension. You will see what the Hessian is used for, from optimisation methods that need it to Bayesian treatments of networks and even to schemes that shrink the precision of weights to save memory. You will then confront its size. A model with a million weights has a table of a million times a million entries, and a model with a billion weights has one that no computer could store. So the interesting question is how much of the information can be obtained at a price that is bearable. The quiz explores the answers: a trick that gives the Hessian multiplied by a vector for the price of a couple of gradient calculations, an approximation that keeps only the diagonal, and a more refined approximation built from products of first derivatives.
The questions ask you to reason with numbers, for instance how the cost of inverting the table grows when the model becomes ten times larger. They also ask about the conditions under which each approximation can be trusted. A cheap approximation is only worth having if you know when it fails, and the quiz is as much about warnings as about methods.
Common misunderstandings include assuming that a diagonal table is a harmless simplification, when real networks have strong couplings between weights, and treating the outer product approximation as universal. It is justified for a network that has been trained appropriately and for a particular kind of error function. Some people also believe the Hessian is always needed in full, whereas for many tasks its product with a single vector is enough. There is a practical moral to the story. Much of the history of numerical optimisation is a search for the best compromise between what is known about a problem and what that knowledge costs. In deep learning the balance has tipped towards methods that use only first derivatives, which are cheap and scale well, while curvature information survives in disguised and approximate forms. Understanding the exact version, and the reasons why it is approximated, makes it much easier to read about newer optimisers that claim to capture some of its benefits at a fraction of the price.
The quiz suits readers who have met the idea of curvature and want to understand why it is rarely used directly in deep learning. It requires no calculus. 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 you get an explanation that includes the reasoning behind the numbers.
›Do I need to know what the Hessian is beforehand?
It helps, and the quiz on the local quadratic picture introduces it. The questions here remind you that it is the table of second derivatives and focus on its cost and on ways of approximating it, which need no more than basic arithmetic.
›Why would anyone want the Hessian of a network?
Because it describes the curvature of the error surface, which some optimisation algorithms use to choose better steps. It also appears in certain Bayesian treatments of networks, where it helps to describe uncertainty about the weights. And it has been used to decide how coarsely the weights of very large models can be stored, which reduces their memory footprint.
›How expensive is the full Hessian?
With W weights, the table has W by W entries. Computing it takes work that grows with the square of W for each data point, and so does storing it. Inverting it, which many methods need, costs work growing with the cube of W. For models with millions or billions of weights, these costs are out of reach, which is the reason approximations are sought.
›What is a Hessian-vector product?
It is the Hessian multiplied by a given vector, which is all that some methods need. A clever extension of backpropagation produces it without ever building the full table, at a cost proportional to the number of weights. That is only a small multiple of the cost of an ordinary gradient, which makes it practical for large networks. Many curvature-based methods can be arranged so that they need nothing but such products, and that arrangement is how some of them avoid the cost of the full table entirely.
›What is the diagonal approximation?
It keeps only the entries of the Hessian that relate each weight to itself and treats all the others as zero. Storage and inversion then cost work proportional to the number of weights. The weakness is that, in practice, the off-diagonal terms are usually significant, so the approximation can be misleading and must be used with care.
›What is the outer product, or Levenberg–Marquardt, approximation?
For a sum-of-squares error, the Hessian splits into two terms. The approximation drops the one involving second derivatives of the network and keeps the one built from first derivatives, which are cheap to obtain with ordinary backpropagation. The result is a sum of outer products of gradient vectors. It is reasonable when the network has been trained appropriately, and less so otherwise.