Optimizing Temperature for Language Models with Multi-Sample Inference
Weihua Du, Yiming Yang, Sean Welleck
TL;DR
This work addresses how to optimally set temperature for multi-sample inference in large language models without task-specific validation data. It introduces Entropy Turning Point (EntP) and TURN, an entropy-based method that selects near-optimal temperatures by analyzing token-level entropy across temperatures and applying an aggregation-aware adjustment. A stochastic process model reinforces the interpretation that entropy spikes signal quality collapse near the turning point, and token-level entropy serves as a distance proxy between training and task. Across math problem solving and code generation tasks, TURN consistently matches or exceeds fixed-temperature baselines, improves efficiency, and provides interpretable guidance on how training-task similarity shapes temperature needs.
Abstract
Multi-sample aggregation strategies, such as majority voting and best-of-N sampling, are widely used in contemporary large language models (LLMs) to enhance predictive accuracy across various tasks. A key challenge in this process is temperature selection, which significantly impacts model performance. Existing approaches either rely on a fixed default temperature or require labeled validation data for tuning, which are often scarce and difficult to obtain. This paper addresses the challenge of automatically identifying the (near)-optimal temperature for different LLMs using multi-sample aggregation strategies, without relying on task-specific validation data. We provide a comprehensive analysis of temperature's role in performance optimization, considering variations in model architectures, datasets, task types, model sizes, and predictive accuracy. Furthermore, we propose a novel entropy-based metric for automated temperature optimization, which consistently outperforms fixed-temperature baselines. Additionally, we incorporate a stochastic process model to enhance interpretability, offering deeper insights into the relationship between temperature and model performance.
