NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Sparse Text Generation

Pedro Henrique Martins, Zita Marinho, André F. T. Martins

Introduction

Modern language models, such as GPT-2, typically rely on the softmax function during training. Softmax assigns a non-zero probability to every token in the vocabulary, creating a "long tail" of low-probability words. During inference, sampling from this tail often results in degenerate, nonsensical, or repetitive text. To mitigate this, practitioners often use ad-hoc truncation methods like top-$k$ or nucleus sampling. However, these methods introduce a fundamental train-test mismatch: the model is trained on a dense distribution but evaluated on a sparse one.

The $\alpha$-entmax Solution

This paper proposes replacing the standard softmax with the $\alpha$-entmax transformation. Unlike softmax, entmax can assign exact zero probabilities to unlikely tokens, creating a "natively sparse" model.

The entmax transformation is parameterized by $\alpha$. When $\alpha=1$, it recovers the standard softmax; as $\alpha$ increases, the resulting distribution becomes sparser. By using entmax during both training and inference, the model learns to explicitly ignore irrelevant tokens, aligning the training objective with the generation process.

Experimental Evaluation

The authors evaluated entmax against standard baselines across several benchmarks, including WikiText-2, WikiText-103, and BookCorpus. Because standard perplexity is undefined when a model assigns zero probability to a ground-truth word, the authors introduced new metrics:

  • $\epsilon$-perplexity: A smoothed version of perplexity.
  • Sparsemax score (sp): A bounded metric based on Gini entropy.
  • Jensen-Shannon Divergence (JS): A symmetric measure of distributional difference.
Performance metrics across WikiText and BookCorpus datasets.

Key Insights

The Sparsity Mismatch

A critical finding is that sparsity must be "baked in" during training. Models trained with standard Negative Log-Likelihood (NLL) perform significantly worse when forced to use sparse sampling at inference time compared to models trained natively with entmax loss. This suggests that the model must learn which parts of the vocabulary to zero out during the optimization phase.

Adaptive Focus and Diversity

Entmax demonstrates a highly adaptive "focus." Unlike nucleus sampling, which uses a fixed probability mass, entmax adjusts the number of considered tokens based on context. On WikiText-103, the support size varied from 1 to over 28,000 tokens, showing greater sensitivity to model uncertainty than fixed-threshold methods.

Furthermore, entmax-generated text exhibits n-gram diversity that closely mirrors human-written text. While other sampling methods often fall into repetitive loops or produce overly generic output, entmax maintains a high level of distinctiveness across different n-gram lengths.

Distinct-n diversity across different sampling methods compared to human text.

Results

Quantitative results show that entmax consistently reduces repetition (REP and WREP) across all datasets. In human evaluations for story completion and dialogue, entmax was rated as more engaging and coherent than nucleus sampling. While it showed a lower F1 score in dialogue tasks—likely due to the open-ended nature of the task where multiple valid responses exist—its qualitative superiority in consistency and engagement was clear.

Conclusion

By bridging the gap between training and inference through natively sparse transformations, $\alpha$-entmax offers a principled alternative to ad-hoc sampling methods. It produces text that is more diverse, less repetitive, and more aligned with human linguistic patterns, while providing a theoretically sound framework for sparse language modeling.

Summary updated

BibTeX
@inproceedings{martins2020sparse,
  author = {Pedro Henrique Martins and Zita Marinho and André F. T. Martins},
  title = {{Sparse Text Generation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.emnlp-main.348},
}
Figure