Semantic-guided Diverse Decoding for Large Language Model

Weijie Shi, Yue Cui, Yaguang Wu, Jingzhi Fang, Shibo Zhang, Mengze Li, Sirui Han, Jia Zhu, Jiajie Xu, Xiaofang Zhou

TL;DR

Existing decoding methods for Large Language Models (LLMs) often produce responses that are lexically different but semantically identical. SemDiD (Semantic-guided Diverse Decoding) shifts the focus from words to ideas by operating directly in the embedding space. Using orthogonal guidance and inter-group repulsion, SemDiD ensures generated candidates are truly distinct. This approach improves Best-of-N coverage by up to 5.2% and accelerates RLHF training convergence by 15%.

The Problem: Lexical vs. Semantic Diversity

When querying an LLM for multiple answers (e.g., "Give me three ways to solve this math problem"), users typically seek semantic diversity—different reasoning paths or perspectives. However, standard techniques like temperature sampling or diverse beam search primarily produce lexical diversity. They might alter a few adjectives or sentence structures, but the underlying logic remains identical.

This "semantic redundancy" creates a major bottleneck in three critical areas:

  1. Best-of-N Sampling: If all 100 samples follow the same flawed logic, increasing $N$ doesn't increase the likelihood of finding the correct answer.
  2. RLHF (Reinforcement Learning from Human Feedback): Models need exposure to a variety of good and bad responses to learn effectively. If all rollouts are nearly identical, the reward signal is weak, leading to slow training or "policy collapse."
  3. Data Synthesis: Generating synthetic training data requires high variety to improve model robustness.

Methods: The SemDiD Framework

SemDiD introduces a decoding framework that runs $k$ groups of beam searches in parallel, shifting the diversity constraint from the token level to the embedding space.

Comparison of the intractable empirical optimum (sample-then-cluster) versus the proposed SemDiD framework.

The framework is guided by three novel mechanisms:

  • Orthogonal Directional Guidance: To prevent groups from converging on the same idea early on, SemDiD uses the Gram-Schmidt process to project each group's decoding trajectory toward a unique, orthogonal direction in the embedding space.
  • Dynamic Inter-Group Repulsion: As the sequences grow, the algorithm applies a "repulsive force" (a penalty based on the dot product of embeddings) between groups. This ensures that even if they start similarly, they diverge as the "semantic identity" of the response develops.
  • Position-Debiased Probability Assessment: The authors discovered that LLMs naturally assign higher probabilities to tokens appearing later in a sequence or immediately after punctuation. SemDiD applies decay factors to neutralize this bias, ensuring that "quality" is measured fairly across sequences of different lengths and structures.

To balance these competing forces, the authors employ a Harmonic Gain Function. Instead of simply adding quality and diversity scores, they use a harmonic mean. This forces the algorithm to prioritize whichever metric is currently lagging, preventing the generation of high-diversity "gibberish" or high-quality "duplicates."

Key Insights

  • The Probability Plateau: Blindly maximizing token probability does not linearly improve answer quality. The authors found that once a certain log-probability threshold is met, quality plateaus. SemDiD treats probability as a "lower bound" (a quality constraint) rather than a target to be maximized at the expense of diversity.
  • Small Models, Big Impact: Surprisingly, the size of the embedding model used for guidance doesn't matter much. A tiny 0.5B parameter embedding model performed nearly as well as a 1.5B model, making the method much more computationally efficient than expected.
  • The "Aha" Moment for RLHF: By forcing the model to explore semantically diverse regions during RLHF rollouts, SemDiD provides a much richer "advantage estimate." This prevents the model from getting stuck in local optima and significantly speeds up the time it takes to reach target accuracy.

Key Results

The authors evaluated SemDiD across a massive battery of benchmarks, including reasoning (ARC-Challenge, BBH, GSM8K), question answering (CoQA, PubMedQA), machine translation (WMT16), and RLHF training (TLDR, GSM8K).

Best-of-N Coverage comparison showing SemDiD (Semantic clustering) outperforming baseline methods, with the 0.5B model matching the 1.5B model's performance.
  • Better Coverage: In Best-of-N tasks, SemDiD improved coverage (the chance of having at least one correct answer in the set) by 1.4% to 5.2% over baselines like nucleus sampling and diverse beam search.
  • Faster RLHF: During reinforcement learning, SemDiD reached peak performance 15% faster than traditional sampling.
  • Accuracy Boost: Beyond just finding one right answer, the overall accuracy of the selected best answer increased by up to 2.1%.
  • Efficiency: Despite the complex math, the optimized implementation (using KV-cache reuse) only adds a 25-35% latency overhead compared to standard group beam search, a small price for significant performance gains.

Limitations and Future Work

  • Computational Overhead: While optimized, SemDiD is still more expensive than simple temperature sampling. It requires running multiple beam groups and an auxiliary embedding model.
  • Hyperparameter Sensitivity: The balance between directional guidance and repulsion is controlled by a transition step ($T_{trans}$). While the authors suggest a default of 10 tokens, this might need tuning for tasks with very short or very long responses.
  • Future Directions: The authors suggest exploring how SemDiD could be used in multi-agent debate or automated red-teaming, where generating semantically distinct "attack vectors" or "arguments" is critical.

Summary updated

BibTeX
@inproceedings{shi2025semantic,
  author = {Weijie Shi and Yue Cui and Yaguang Wu and Jingzhi Fang and Shibo Zhang and Mengze Li and Sirui Han and Jia Zhu and Jiajie Xu and Xiaofang Zhou},
  title = {{Semantic-guided Diverse Decoding for Large Language Model}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=Hmd8CqMo3E},
}
Figure