Gradient-Guided Importance Sampling for Learning Binary Energy-Based Models

Meng Liu, Haoran Liu, Shuiwang Ji

The Bottleneck in Discrete Energy-Based Models

Energy-Based Models (EBMs) are powerful tools that represent probability distributions through an unnormalized "energy" function. However, training them on discrete data—such as binary strings or graphs—is notoriously difficult.

For continuous data, the standard approach uses gradients to "nudge" samples toward low-energy areas. In discrete spaces, however, you cannot simply nudge a bit; you must flip it. The classic solution to this is Ratio Matching (RM), which learns by comparing the energy of a data point to all its immediate "neighbors" (points where exactly one bit is flipped).

The catch? If your data has $d$ dimensions, you have $d$ neighbors. For high-dimensional data (like a 2048-bit string), calculating the energy for every single neighbor during every training step is prohibitively expensive in terms of both computation time and GPU memory.

Enter RMwGGIS: Smart Sampling via Gradients

To overcome this bottleneck, the authors introduce Ratio Matching with Gradient-Guided Importance Sampling (RMwGGIS). Instead of evaluating all $d$ neighbors, RMwGGIS uses importance sampling to pick a small subset of $s$ neighbors, where $s \ll d$.

Algorithm 1: Ratio Matching with Gradient-Guided Importance Sampling

The core innovation lies in how the algorithm chooses which neighbors to sample:

  1. The Gradient Trick: Even though the data is discrete (0s and 1s), the neural network representing the energy function $E_\theta(x)$ is continuous and differentiable.
  2. Taylor Approximation: The authors use a first-order Taylor expansion to estimate the energy change of flipping a bit without actually flipping it. This estimate is derived directly from the gradient of the energy function with respect to the input. One backward pass provides a nearly free preview of the entire neighborhood, allowing the model to skip $d$ forward passes.
  3. Optimal Proposal: These gradient-based estimates are used to construct a "proposal distribution" that heavily favors neighbors likely to have low energy (the most "important" ones to evaluate).
  4. Advanced Version (Hard Negative Mining): An "advanced" heuristic version removes importance weights entirely. This forces the model to focus specifically on the "most offending" neighbors—those the model currently assigns too much probability to—acting as a form of hard negative mining.

Key Results and Performance

The authors evaluated RMwGGIS on synthetic discrete data (2D continuous distributions converted into discrete vectors using Gray codes), graph generation tasks, and Ising models.

The results demonstrate massive improvements in both efficiency and modeling quality:

  • Efficiency: On 2048-dimensional data, RMwGGIS achieved a 6.2x speedup and a 90.1% reduction in memory usage compared to standard Ratio Matching.
  • Scalability and Quality: While standard Ratio Matching failed to capture the structure of 256-dimensional synthetic data, RMwGGIS accurately recovered complex shapes. In density modeling tasks, RMwGGIS consistently outperformed standard Ratio Matching in terms of Maximum Mean Discrepancy (MMD).
Visual comparison of RMwGGIS variants on synthetic 2D datasets
  • Ising Models: RMwGGIS proved significantly faster and more accurate than both standard RM and recent MCMC-based baselines (like Gibbs-With-Gradient) on a 625-dimensional 2D cyclic lattice.

Insights and Future Directions

Interestingly, the stochasticity introduced by sampling only $s$ neighbors acts as a feature rather than a bug. Much like how Stochastic Gradient Descent (SGD) often finds better minima than full-batch gradient descent, this noise helps the EBM escape local optima.

While highly effective, the method does have limitations. The current derivation is specifically tailored for binary discrete data; extending it to categorical data with many states per dimension remains an open challenge. Furthermore, the authors note that Ratio Matching is conceptually flawed for binary images (like MNIST), where flipping a single pixel rarely changes the semantic "nature" of the image enough to serve as a meaningful negative sample. Finally, while the "advanced" heuristic version performs best in practice, further theoretical work is needed to bridge the gap between its empirical success and the theoretical unbiasedness of the basic version.

Summary updated

BibTeX
@inproceedings{liu2023gradient,
  author = {Meng Liu and Haoran Liu and Shuiwang Ji},
  title = {{Gradient-Guided Importance Sampling for Learning Binary Energy-Based Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=9DZKk85Z4zA},
}
Figure