TL;DR
Language models typically use a fixed "temperature" during decoding, forcing a trade-off between factual precision and creative flair. This paper introduces Adaptive Decoding, a learnable module that dynamically adjusts the sampling temperature for every token or sequence, and Latent Preference Optimization (LPO), a novel method to train these discrete choices using preference data.
What Problem Does This Paper Address?
When an LLM generates text, the "temperature" parameter scales the probability distribution of the next possible tokens. A low temperature makes the model "sharper" and more deterministic (good for math or facts), while a high temperature makes it more diverse and "creative" (good for storytelling).
The problem is that modern LLMs are generalists. A single prompt might require a mix of both—for example, writing a creative story that must strictly follow specific formatting constraints. Currently, users have to manually tune a fixed temperature for an entire task, which is suboptimal and cannot adapt to different needs within a single response.
Methods
The authors propose two main components:
- The ADAPTIVEDECODER Module: This is a small, 3-layer MLP added to the final layers of a frozen LLM. It takes the model's internal hidden state and predicts a probability distribution over a set of discrete temperature options (e.g., $\{0.0, 0.2, 0.4, 0.6, 0.8, 1.0\}$).
- Sequence-level: Predicts one temperature for the entire response based on the prompt.
- Token-level: Predicts a new temperature for every single token generated.
- Latent Preference Optimization (LPO): Training a module to pick a temperature is tricky because the "correct" temperature isn't in the training data. LPO solves this by:
- Sampling multiple responses using different temperatures.
- Ranking these responses using a Reward Model (RM) or ground-truth labels.
- Using a DPO-style loss to train the module to assign higher probability to the temperatures that resulted in the "chosen" (better) responses.
Datasets
The researchers evaluated their method on a diverse mix of tasks:
- GSM8K: Grade school math word problems (requires high factuality).
- Stories: A creative writing task where the model generates short stories based on titles.
- UltraFeedback: A large-scale dataset of general human-instruction pairs.
- UltraMathStories: A custom mixture of the three datasets above to test general adaptation.
- ConstrainedStories: A new "hard mode" creative task where the model must write a story, but every sentence must start with a specific substring (e.g., "Ab").
Key Insights and Ideas
- Implicit Task Recognition: Without being explicitly told what the task is, the ADAPTIVEDECODER learns to "read the room." It automatically selects near-zero temperatures for math problems and high temperatures for creative writing.
- The "Constraint" Sweet Spot: In the ConstrainedStories task, the token-level model learned a fascinating behavior: it uses a very low temperature for the first token of a sentence (to ensure it hits the "Ab" constraint) and then immediately pivots to a high temperature for the rest of the sentence to keep the story interesting.
- LPO as a General Framework: While this paper focuses on temperature, LPO is a general-purpose tool. It can be used to train any discrete latent variable in a model—such as choosing between different decoding strategies (top-p vs. top-k) or even selecting between different specialized "expert" layers.
Key Results
- Outperforming Fixed Baselines: On the mixed UltraMathStories benchmark, Adaptive Decoding outperformed every fixed temperature setting (from 0.0 to 1.0).
- Repetition Reduction: The model learned to increase temperature specifically when it detected it was about to enter a repetitive loop, reducing 3-gram repetitions by 42% compared to greedy decoding.
- Win Rates: In head-to-head comparisons on UltraFeedback, the adaptive model achieved win rates of over 54% against the best-tuned fixed temperature models.
- Majority Voting: For math (GSM8K), the model improved the performance of "self-consistency" (majority voting) by learning exactly how much randomness to inject into the reasoning chains to get the most accurate consensus.
Limitations and Future Work
- Discrete Choices: The model currently chooses from a fixed set of temperatures. Future iterations could explore predicting a continuous temperature value.
- Computational Overhead: Training via LPO requires generating multiple samples per prompt, which increases the initial training cost (though inference remains fast).
- Frozen Backbone: This study kept the base LLM frozen to isolate the effect of the new layer. The authors suggest that joint training (fine-tuning the LLM and the ADAPTIVEDECODER together) could lead to even tighter integration and better performance.
Summary updated