Abstract
Large Language Models (LLMs) typically rely on a fixed temperature parameter during the decoding process, which often fails to capture the fluctuating confidence levels inherent in natural language generation. This paper introduces Entropy-based Dynamic Temperature (EDT), a novel, lightweight decoding strategy that dynamically adjusts the sampling temperature at each token-level step based on the Shannon entropy of the predicted probability distribution. By increasing the temperature during high-uncertainty states and sharpening the distribution during high-confidence states, EDT optimizes the trade-off between text quality and diversity. Evaluated on LLaMA2-13B across four diverse benchmarks—XLSum, QuAC, MS MARCO, and WMT19—EDT consistently outperforms fixed-temperature baselines and achieves performance parity with computationally intensive dynamic methods like KLD, while reducing GPU memory overhead by approximately 50%.
Introduction
The generation of coherent and diverse text in LLMs is traditionally managed through temperature sampling. A low temperature (< 0.5) concentrates probability mass on the most likely tokens, ensuring high coherence but often leading to repetitive or generic outputs. Conversely, a high temperature (> 0.7) flattens the distribution, encouraging creativity at the risk of hallucinations and grammatical errors.
Current standard practices utilize a static temperature throughout the entire generation process. However, linguistic uncertainty is not uniform; some tokens are grammatically deterministic, while others are semantically open-ended. A "one-size-fits-all" temperature approach inevitably compromises either the factual integrity or the creative variety of the generated text. To address this, we propose EDT, a method that allows the model to self-regulate its "confidence dial" in real-time.
Methodology: Entropy-based Dynamic Temperature
EDT operates on the principle that an LLM's internal state—specifically the entropy of its output distribution—is a reliable proxy for its confidence. The process follows a streamlined pipeline integrated into the standard transformer decoding loop.
The core of EDT involves three primary steps:
- Uncertainty Quantification: At each decoding step, the system calculates the Shannon Entropy of the predicted vocabulary distribution. High entropy indicates the model perceives multiple viable candidates (high uncertainty), whereas low entropy indicates a strong preference for a single token (high confidence).
- Dynamic Adjustment: The temperature $T$ is adjusted using a power-law relationship: $T = T_0 \cdot \mathcal{N}^{\frac{\theta}{Entropy}}$. This formula ensures that when the model is uncertain, the temperature rises to explore diverse paths, and when certain, the temperature drops to prune low-probability "noise" tokens.
- Computational Efficiency: Unlike previous dynamic methods such as Kullback-Leibler Divergence (KLD) sampling, which requires maintaining two parallel model states, EDT relies solely on the primary model's output. This makes it a "zero-cost" upgrade in terms of inference speed and memory footprint.
Experimental Evaluation
The effectiveness of EDT was tested using a LLaMA2-13B model fine-tuned via Low-Rank Adaptation (LoRA). The evaluation spanned four distinct tasks to ensure robustness:
- XLSum: Abstractive summarization requiring a balance of factual density and linguistic variety.
- QuAC & MS MARCO: Contextual and search-based question answering where precision is paramount.
- WMT19: English-to-Chinese translation, testing the model's ability to maintain structural integrity.
Results and Discussion
The primary metric for evaluation was the trade-off between quality (measured by ROUGE-L or BLEU) and diversity (measured by Self-BLEU). The researchers utilized the Euclidean Distance from the ultimate Aim (EDA) to quantify how close each method came to the theoretical "perfect" generation (high quality and high diversity).
Quality-Diversity Pareto Front
As shown in the experimental results, EDT consistently establishes a superior Pareto front. In the XLSum summarization task, EDT achieved a ROUGE-L score of 24.69 compared to just 15.00 for fixed-temperature baselines, while maintaining similar diversity levels. This suggests that by lowering temperature during confident factual segments, EDT prevents the model from drifting into "hallucinatory" low-probability tokens.
Token-Level Granularity
A key finding of the study is the necessity of token-level adjustment. Experiments comparing instance-level (one temperature per sentence) versus token-level (one temperature per word) showed that the latter is significantly more effective. Because model confidence can shift radically between a noun and its following preposition, the high-frequency adjustment of EDT is critical for maintaining coherence.
Efficiency and Deployment
From a systems perspective, EDT is highly attractive for production environments. It maintains the same inference latency as standard sampling while avoiding the 50% increase in GPU memory required by dual-model strategies like KLD. This makes it a drop-in replacement for existing LLM pipelines.
Conclusion
EDT provides a simple yet powerful mechanism for LLMs to navigate the exploration-exploitation trade-off. By leveraging the model's own entropy as a feedback signal, EDT ensures that the model is "adventurous" only when the context allows and "disciplined" when the facts demand it. Future research will focus on automating hyperparameter selection through learnable "temperature-head" networks, potentially removing the need for manual tuning across different datasets.
Summary updated