Abstract
Energy-Based Models (EBMs) provide a framework for capturing global dependencies in sequence generation, yet training them on discrete text remains a significant challenge. Traditional MCMC-based training often fails due to the non-differentiable nature of text, while standard Noise Contrastive Estimation (NCE) can leave spurious modes in the energy landscape. We propose a novel adversarial training strategy that utilizes iterative discrete adversarial attacks to generate hard negative samples. On a structured arithmetic generation task, our approach significantly outperforms standard language models and resampling-based EBM baselines, achieving high global correctness by effectively smoothing the energy landscape.
Introduction
Autoregressive language models are inherently locally normalized, predicting the next token based on immediate context. While successful in many domains, this local focus often results in sequences that lack global consistency. Energy-Based Models (EBMs) offer a solution by assigning a scalar energy value to an entire sequence, allowing for global evaluation. However, the discrete nature of text makes it difficult to apply the gradient-based sampling methods typically used to train EBMs. This work addresses the "spurious mode" problem—where a model assigns low energy to incorrect sequences it has not encountered during training—by introducing an adversarial training regime.
Methodology
The proposed framework combines a base language model ($P_{LM}$) with a global energy function ($E_\theta$). To train $E_\theta$, we replace traditional MCMC with a discrete adversarial attack algorithm.
Iterative Adversarial Attacks
The core of our training strategy involves finding "bad" sequences that the current model mistakenly favors. Starting from a sequence sampled from $P_{LM}$, we iteratively apply perturbations:
- Gradient-Guided Search: We compute the gradient of the energy function with respect to token embeddings.
- Discrete Substitution: We identify the token with the highest gradient magnitude and replace it with a token from a predefined synonym set that minimizes the sequence energy.
- Refinement: This process is repeated for $S$ steps, effectively "climbing" into the model's errors to find hard negative samples.
Experimental Results
We evaluate our method on a synthetic arithmetic sequence generation task (e.g., 4 6 8 + 2 3 9 = 7 0 7). This task provides an objective "Correctness" metric, measuring the percentage of correctly predicted digits in the sum.
Performance Comparison
Our adversarial EBM is compared against a standard LM baseline and a Residual-EBM trained with importance sampling.
As illustrated in the results, the adversarial training strategy allows the model to reach a correctness score of approximately 0.85. In contrast, both the LM baseline and the Residual-EBM plateau at roughly 0.20. This gap highlights the effectiveness of adversarial perturbations in identifying and correcting global inconsistencies that simple resampling methods miss.
Conclusion
This paper demonstrates that discrete adversarial attacks can serve as an effective proxy for MCMC in training EBMs for text. By forcing the model to explore and penalize its own spurious modes, we achieve a more robust energy landscape capable of enforcing global structure. Future work will focus on scaling this approach to natural language and improving the efficiency of the iterative attack process.
Summary updated