Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 19

Understanding Hessians and Approximations in Optimization

Recommended resources

Welcome back. In the previous lesson, we concluded our tour of first-order derivatives by tracing a full backpropagation pass, framing it as a sequence of efficient Jacobian-vector products. This gave us the gradient of the loss with respect to every parameter in a network, which is the core requirement for optimizers like SGD and Adam.

However, the gradient only provides a linear, local approximation of the loss landscape. It tells us the direction of steepest descent, but not how the slope changes as we move. To capture this curvature, we need to look at second-order derivatives. This lesson is dedicated to the Hessian matrix, the second-order analogue of the gradient. We will define the Hessian and see how it enables the powerful Newton's method for optimization. Since computing the full Hessian is infeasible for deep networks, our main goal will be to derive and understand the rationale behind two key approximations that are central to modern deep learning research: the Gauss-Newton matrix and the Fisher Information Matrix.

1. The Hessian and Second-Order Optimization

For a scalar-valued function like a loss that depends on a parameter vector , the gradient is a vector of first partial derivatives. The Hessian matrix, denoted , is the matrix of all second partial derivatives:

Just as the gradient defines the best linear approximation to the loss function at a point, the Hessian is the key component of the best quadratic approximation. This is formalized by the second-order Taylor series expansion around a point :

This quadratic model of the loss landscape is much richer than the linear one. It doesn't just tell us which way is "down"; it describes the shape of the valley (or hill, or saddle) we are in.

Newton's Method

If we can build a quadratic approximation of our loss function, why not just jump to its minimum? This is precisely the idea behind Newton's method. By setting the gradient of the Taylor approximation above to zero, we can solve for the optimal step , which yields an elegant update rule.

Second-Order Methods in Machine Learning

This article by Maxime Robeyns provides a thorough derivation of second-order methods starting from Taylor approximations.

Please read the section "Taylor Approximations". Start from the first-order approximation, then focus on the part where the second-order term is introduced. Follow the derivation that sets the derivative of the quadratic approximation to zero to arrive at the Newton update.

The resulting update rule is:

Here, the inverse Hessian acts as a preconditioner. It automatically adapts the step size for each parameter direction, taking larger steps in flat directions (low curvature) and smaller steps in sharp directions (high curvature), effectively "warping" the landscape to look more like a perfect bowl.

However, Newton's method is rarely used in its pure form for deep learning due to two major challenges:

  1. Computational Cost: For a network with parameters (often in the millions or billions), the Hessian is an matrix. Storing it requires memory, and inverting it costs computation, both of which are prohibitive.
  2. Non-Convexity: The derivation assumes we are minimizing a convex quadratic. In deep learning, the loss landscape is highly non-convex. The Hessian may not be positive definite, meaning it can have negative or zero eigenvalues. At such points (e.g., saddle points), the Newton step can point uphill or be undefined.

To stabilize the update, a common technique is damping, which involves adding a scaled identity matrix to the Hessian: . This ensures the matrix is invertible and positive definite, but it doesn't solve the fundamental computational problem. This is where approximations become essential.


2. The Gauss-Newton Approximation

The first major approximation we'll study is the Gauss-Newton matrix (also called the Generalized Gauss-Newton or GGN matrix). The key insight is that for many common loss functions, the Hessian can be decomposed into two terms, one of which is often small or difficult to compute and can be dropped.

Let our model be a composition of the network producing logits, and a loss function . The total loss is . The Hessian of this composite function can be written as:

Here, is the Jacobian of the network output with respect to , is the Hessian of the loss with respect to the network's output, and is the Hessian of the -th network output with respect to .

The Gauss-Newton approximation () is formed by dropping the second term:

Let's explore the derivation and rationale for this approximation.

Second-Order Methods in Machine Learning

The same article provides a clear definition of the Gauss-Newton Hessian and its benefits.

Please read the section "The Gauss-Newton Hessian". Focus on the Hessian decomposition and GGN definition. Then, pay close attention to the two main advantages it lists.

As the text highlights, the GGN matrix has two significant advantages:

  1. Guaranteed Positive Semi-Definiteness: As long as the loss function is convex (which is true for standard choices like MSE and cross-entropy), its Hessian is positive semi-definite. This property is transferred to , ensuring that the optimization step moves in a descent direction.
  2. Avoids Network Second Derivatives: The GGN matrix depends only on the Jacobian of the network and the Hessian of the loss function . It completely bypasses the need to compute the network's own Hessian , which is the most computationally demanding and problematic part. This makes the GGN applicable to networks with non-twice-differentiable activation functions like ReLU.

Another powerful way to interpret the GGN is that it's the exact Hessian of the loss function applied to a first-order Taylor approximation (linearization) of the network .

Gauss Newton - Non Linear Least Squares

This video from Meerkat Statistics presents the Gauss-Newton method from two useful perspectives.

First, watch the derivation based on approximating the Hessian, which mirrors the derivation we just saw. Then, watch the alternative derivation based on linearizing the function. This second viewpoint is often very insightful.


3. The Fisher Information Matrix (FIM)

Now we switch to a probabilistic lens. We can view the output of our network as defining the parameters of a probability distribution . For classification, the softmax outputs parameterize a Categorical distribution. For regression, the network output might be the mean of a Gaussian. The training process of minimizing the loss (e.g., cross-entropy) is equivalent to maximizing the log-likelihood .

The Fisher Information Matrix () measures the amount of information that the data carries about the parameters . Intuitively, it quantifies how much the log-likelihood function curves at the location of the true parameters. A sharply curved log-likelihood (high Fisher information) means the parameters are well-determined by the data, while a flat log-likelihood (low Fisher information) means they are not.

The following video provides an excellent visual and intuitive build-up to the concept.

The Fisher Information

This video from the Mutual Information channel masterfully explains the intuition behind Fisher Information.

First, watch the segment explaining the core 1D idea, which defines Fisher Information as the variance of the score function (the gradient of the log-likelihood). Next, see the crucial connection to second derivatives. Finally, watch the generalization to higher dimensions, which defines the FIM as the covariance of the gradient vector and connects it to the expected Hessian.

As the video explains, the Fisher Information Matrix has two equivalent definitions:

  1. As the covariance of the score function:

    The score, , tells us how to change to increase the log-likelihood. The FIM measures how much this direction varies on average for different data samples drawn from the model's own distribution.

  2. As the negative expected Hessian of the log-likelihood:

    This second definition directly connects the Fisher Information to the curvature of the log-likelihood landscape.

The Connection Between GGN and FIM

At first glance, the GGN (from optimization theory) and the FIM (from information geometry) seem to come from different worlds. The remarkable result is that for most standard deep learning setups, they are identical.

When the loss function is the negative log-likelihood of a distribution from the exponential family (which includes the Gaussian and Categorical distributions underlying MSE and cross-entropy loss), the Gauss-Newton matrix equals the Fisher Information Matrix.

Second-Order Methods in Machine Learning

The article we've been referencing demonstrates this equivalence.

Please read the derivation at the beginning of the "Kronecker-Factored Approximate Curvature" section. Focus on the chain of equalities from this derivation that shows \mathbf{G} = \mathbf{F}.

This equivalence is profound. It means that approximating the Hessian by linearizing the network (the GGN view) is the same as measuring the curvature of the manifold of probability distributions defined by the network (the FIM view).

This connection gives rise to Natural Gradient Descent, an optimization algorithm that uses the inverse Fisher matrix as a preconditioner:

This method is considered "natural" because it is invariant to the specific parameterization of the network. It takes steps of constant size in the space of distributions, not parameters, leading to more stable and often faster convergence.

Finally, it's crucial to distinguish the proper Fisher from the empirical Fisher. The proper Fisher, which we've discussed, involves an expectation over the model's distribution . The empirical Fisher instead takes the expectation over the data distribution (i.e., using the ground-truth labels). Optimizers like Adam use a diagonal version of the empirical Fisher. While the empirical Fisher is often easier to compute, only the proper Fisher enjoys all the theoretical guarantees of natural gradient descent.


Conclusion

In this lesson, we moved beyond first-order gradients to explore the role of second-order information in optimization. We saw that the Hessian matrix provides a full picture of local curvature but is computationally intractable for large models. This motivated the development of powerful approximations.

Key Takeaways:

  • The Hessian matrix contains all second-order partial derivatives of the loss function and describes the local curvature of the loss landscape.
  • Newton's method uses the inverse Hessian to pre-condition the gradient, leading to faster convergence but suffering from high computational cost and instability in non-convex regions.
  • The Gauss-Newton (GGN) matrix is a practical approximation of the Hessian that avoids computing second derivatives of the network itself. It is guaranteed to be positive semi-definite for common convex loss functions.
  • The Fisher Information Matrix (FIM) arises from information geometry and measures the sensitivity of the model's output distribution to changes in its parameters.
  • For standard deep learning loss functions (MSE, cross-entropy), the GGN and FIM are identical, providing a deep link between optimization and information geometry.
  • These approximations form the basis for advanced optimizers like Natural Gradient Descent, which uses to achieve parameterization-invariant updates.

In our next lesson, we will delve deeper into the property of convexity. We'll see how the Hessian, particularly its eigenvalues, can be used to formally test for convexity, a critical concept for understanding why some optimization problems are fundamentally easier to solve than others.