The Hessian Penalty: A Weak Prior for Unsupervised Disentanglement

William S. Peebles, John Peebles, Jun-Yan Zhu, Alexei A. Efros, Antonio Torralba

Abstract

Disentanglement in generative models aims to isolate independent factors of variation within a latent space without explicit supervision. We present the Hessian Penalty, a simple regularization term that encourages the Hessian matrix of a generator to be diagonal. By forcing the network to make changes to one input component independent of others, we achieve state-of-the-art unsupervised disentanglement and "latent space shrinkage." Our approach is computationally efficient, model-agnostic, and can be implemented with minimal code overhead.

Introduction

In deep generative models such as Generative Adversarial Networks (GANs), the latent space (the input noise vector $z$) is often highly entangled. Modifying a single dimension in the input might simultaneously alter an object's color, size, and rotation. Disentanglement is the process of forcing the model to map specific, independent concepts to specific input dimensions. Historically, this has required complex architectures like VAEs, auxiliary networks, or hand-picked priors.

This work introduces a "weak prior"—a broad, generic rule applicable to any architecture—to encourage disentanglement without needing labels or complex setups. The core principle is rooted in multivariable calculus: if a function is disentangled, the way the output changes when perturbing input $z_i$ should not depend on the value of input $z_j$. Mathematically, this implies that the mixed partial derivatives (the off-diagonal entries of the Hessian matrix) should be zero.

Methods

The Hessian Penalty

We propose a loss term that minimizes the sum of the squared off-diagonal elements of the Hessian matrix: $$ \mathcal{L}_H(G) = \sum_{i} \sum_{j \neq i} H_{ij}^2 $$

Computational Efficiency

Computing a full Hessian matrix is computationally expensive, scaling at $O(|z|^2)$. To make this practical for training high-resolution models, we employ two techniques:

  1. Hutchinson’s Estimator: A stochastic approximation that estimates the penalty using the variance of second directional derivatives.
  2. Finite Differences: Instead of costly double-backpropagation, we use a central difference approximation: $G(z+v) - 2G(z) + G(z-v)$.

The resulting algorithm can be implemented in approximately seven lines of PyTorch code and adds minimal training overhead.

Experimental Results

Disentanglement and Fine-Tuning

The Hessian Penalty was evaluated across diverse datasets, including Edges+Shoes and CLEVR. A key finding is that the penalty can be applied to pre-trained models. Fine-tuning a ProGAN on the Edges+Shoes dataset for a few thousand iterations significantly "cleans up" the latent space, separating edge maps from texture and shape.

Disentanglement on the Edges+Shoes dataset comparing baseline ProGAN with the Hessian Penalty (left) and demonstrating independent control over two latent components (right).

Latent Space Shrinkage

A striking emergent property of the Hessian Penalty is "latent space shrinkage." When a model is provided with more latent dimensions than the data has factors of variation, the penalty automatically "turns off" unnecessary dimensions by collapsing their variance to near zero. This suggests the penalty acts as a form of automatic model selection.

Top-ranked active latent components (left) capturing position, shape, and color, alongside "deactivated" components (right) demonstrating latent space shrinkage.

Quantitative Performance

  • Smoothness: Models trained with the Hessian Penalty achieved significantly lower Perceptual Path Length (PPL). On Edges+Shoes, the PPL dropped from 1809.7 (baseline) to 554.1.
  • Disentanglement Metrics: On synthetic CLEVR datasets, the Hessian Penalty consistently outperformed or matched InfoGAN in separating known factors like object position and color.

Discussion and Conclusion

While the Hessian Penalty is a powerful tool, it is a "weak prior" and may not achieve perfect disentanglement on highly complex datasets where factors are naturally correlated. There is also a slight trade-off between disentanglement and raw image quality (FID) during early training stages.

However, the simplicity and model-agnostic nature of the Hessian Penalty make it a compelling solution for unsupervised disentanglement. It demonstrates that fundamental principles from calculus can effectively solve complex problems in generative modeling with minimal implementation complexity.

Summary updated

BibTeX
@inproceedings{peebles2020hessian,
  author = {William S. Peebles and John Peebles and Jun-Yan Zhu and Alexei A. Efros and Antonio Torralba},
  title = {{The Hessian Penalty: A Weak Prior for Unsupervised Disentanglement}},
  booktitle = {European Conference on Computer Vision},
  year = {2020},
  doi = {10.1007/978-3-030-58539-6\_35},
}
Figure