A Contrastive Framework for Neural Text Generation

Yixuan Su, Tian Lan, Yan Wang, Dani Yogatama, Lingpeng Kong, Nigel Collier

Introduction

Despite the remarkable capabilities of Transformer-based models like GPT-2, they frequently suffer from "model degeneration"—a phenomenon where generated text becomes repetitive, dull, or semantically inconsistent. While stochastic decoding methods like nucleus sampling can mitigate repetition, they often sacrifice coherence. This paper introduces SimCTG (Simple Contrastive Framework for Neural Text Generation), a novel approach that addresses degeneration by fostering a more "isotropic" (spread out) representation space.

The authors identify the root cause of degeneration as the anisotropic nature of the model's representation space. In standard models trained with Maximum Likelihood Estimation (MLE), token representations tend to cluster into a narrow cone. This high similarity—often exceeding 0.95—makes it difficult for the model to differentiate between distinct concepts during generation, leading to repetitive loops.

Token similarity matrices for (a) standard MLE and (b) SimCTG.

As shown in the visualization above, standard MLE results in a nearly uniform high-similarity matrix. In contrast, SimCTG produces a sparse, diagonal-heavy matrix, indicating that the model has learned to represent tokens as distinct entities.

Methodology: SimCTG

The SimCTG framework attacks degeneration through two primary components:

  1. Contrastive Training: A contrastive loss term ($L_{CL}$) is added to the standard MLE objective. This margin-based loss "pushes" the representations of different tokens in a sequence away from each other, forcing the model to learn a more discriminative and isotropic space.
  2. Contrastive Search: This new deterministic decoding strategy replaces traditional greedy or beam search. At each step, it selects a token by balancing model confidence (probability) with a "degeneration penalty"—the maximum cosine similarity between the candidate token and all previously generated tokens.

Experimental Results

The framework was evaluated on major benchmarks including Wikitext-103 (English), LCCC (Chinese), and DailyDialog (English). SimCTG consistently outperformed baselines like standard MLE and Unlikelihood Training across metrics such as Perplexity, MAUVE, and Diversity.

A key highlight of the study is the human evaluation performance. On the Wikitext-103 dataset, the SimCTG-large model achieved coherence and fluency scores that closely approach human-level quality.

Human evaluation results on Wikitext-103 comparing different models and decoding methods.

Furthermore, the approach is highly efficient; the contrastive training objective adds only approximately 1.48% extra computational overhead compared to standard MLE training, and contrastive search remains faster than beam search for larger beam widths.

Conclusion

SimCTG provides a robust solution to the degeneration problem by aligning the model's internal representation space with the distinctiveness of natural language. By combining contrastive training with a similarity-penalizing search algorithm, the framework achieves state-of-the-art results that significantly narrow the gap between machine-generated and human-written text. Future work may involve refining the contrastive loss to better handle true synonyms and scaling the framework to even larger language models.

Summary updated

BibTeX
@inproceedings{su2022contrastive,
  author = {Yixuan Su and Tian Lan and Yan Wang and Dani Yogatama and Lingpeng Kong and Nigel Collier},
  title = {{A Contrastive Framework for Neural Text Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=dXfo7Ed9Gog},
}
Figure