Beyond Semantic Entropy: Boosting LLM Uncertainty Quantification with Pairwise Semantic Similarity (2025)

Abstract: Hallucination in large language models (LLMs) can be detected by assessing the uncertainty of model outputs, typically measured using entropy. Semantic entropy (SE) enhances traditional entropy estimation by quantifying uncertainty at the semantic cluster level. However, as modern LLMs generate longer one-sentence responses, SE becomes less effective because it overlooks two crucial factors: intra-cluster similarity (the spread within a cluster) and inter-cluster similarity (the distance between clusters). To address this limitation, we propose a simple black-box uncertainty quantification method inspired by nearest neighbor estimates of entropy. Our approach can also be easily extended to white-box settings by incorporating token probabilities. Additionally, we provide theoretical results showing that our method generalizes semantic entropy. Extensive empirical results demonstrate its effectiveness compared to semantic entropy across two recent LLMs (Phi3 and Llama3) and three common text generation tasks: question answering, text summarization, and machine translation. Our code is available at [https://github.com/BigML-CS-UCLA/SNNE](https://github.com/BigML-CS-UCLA/SNNE).

## introduction large language models (llms) have demonstrated impressive capabilities in understanding and generating human-like text, revolutionizing various fields @xcite . however, they are not without flaws, and one of the most significant challenges is hallucination, i.e., incorrect or fabricated information that appears plausible @xcite . detecting and mitigating hallucination is critical to ensuring the reliability and safety of llms. a common approach to addressing this issue is uncertainty quantification (uq) @xcite . by measuring the uncertainty of an llm's outputs, we can identify potentially hallucinated content and flag it for further review, improving both accuracy and user trust. a straightforward way to estimate uncertainty in llms is to generate multiple responses and aggregate their token-level likelihoods @xcite . however, this approach ignores semantic information, treating reworded yet equivalent answers as distinct. semantic entropy (se) @xcite addresses this by clustering semantically similar outputs using bidirectional entailment predictions from a nli model before computing entropy. while effective for short responses, se struggles when model generates long one-sentence outputs, a pattern inherent to tasks such as summarization @xcite and translation @xcite . in these cases, se often reverts to the previous naive approach while its discrete version, discrete semantic entropy (dse), yields constant values. these shortcomings highlight the need for more robust uncertainty estimation techniques tailored to complexities of lengthy model responses. we empirically observe that state-of-the-art llms tend to generate longer one-sentence outputs on common qa benchmarks: llama-3.1-8b and phi-3-mini produce responses with an average length of 4.1 and 4.9 words, respectively, compared to 2.3 words for llama2-7b. in these scenarios, model outputs are more likely to belong to different semantic groups, thus capturing intercluster similarity is important. in addition, each semantic cluster has different spread, necessitating the consideration of inter-cluster similarity. to address these two issues, we propose a simple yet effective black-box uq method inspired by nearest neighbor estimates of entropy @xcite . our approach can be seamlessly extended to white-box settings by incorporating token probabilities, providing flexibility across different use cases. additionally, we theoretically prove that our method generalizes semantic entropy, offer-1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 -9 ## existing uncertainty quantification methods black-box methods. these methods rely solely on generated answers. ptrue @xcite estimates uncertainty by prompting the model a true/false question to verify its own responses. the model's uncertainty is then determined by the probability of selecting false. lexical similarity (lexsim) @xcite ) measures uncertainty via average lexical overlap among responses but struggles with semantically similar outputs that use different wording. graph-based approaches @xcite structure responses as a similarity graph and derive uncertainty from its properties. numset counts semantic clusters found by se, while sumeigv generalizes this via the sum of eigenvalues of the graph laplacian. deg computes the average pairwise semantic similarities, and eccen quantifies uncertainty based on distances from responses to their center in the space defined by the k smallest eigenvectors of the graph laplacian. because graph-based methods use summation to aggregate answer similarities, they are sensitive to outliers or peculiar answers. luq @xcite is designed for multi-sentence scenarios by aggregating atomic uncertainty scores computed for individual sentences. however, its atomic scoring relies on nli-based similarity, which inherits the limitations of lexsim and graph-based methods. our method can be integrated into luq to provide more reliable atomic scores, offering a promising direction for extending our approach to multi-sentence settings. we leave this for future work. white-box methods. these methods utilize internal model information, such as token likelihoods and representations, to assess uncertainty. naive entropy (ne) @xcite computes entropy over length-normalized sequence probabilities but is sensitive to variations in probability assignments for semantic equivalence answers, leading to unreliable estimates. semantic entropy (se) @xcite improves robustness by leveraging a greedy bi-directional entailment clustering algorithm to group responses into semantic clusters before computing entropy but does not account for semantic distances between generations. kernel language entropy (kle) @xcite addresses this by using von neumann entropy on a semantic kernel. however, the use of heat and matern kernels for constructing semantic kernels in kle makes it challenging to interpret the model's uncertainty and may lead to the loss of information. empirically, we show that directly utilizing semantic similarities between answers leads to improved performance and more accurate uncertainty estimation. in addition, its o(n 3 ) complexity makes it impractical for large-scale uncertainty estimation. in contrast, se provides a more computationally efficient approach o(n 2 ) but struggles with long outputs. given the efficiency and intuitive formulation, se serves as a foundation for further improvement, motivating our approach to address its limitations. rather than relying on clustering, sar @xcite computes a soft aggregation of wordor sentence-level probabilities weighted by their semantic similarity. it also reduces the impact of irrelevant tokens and low-quality sequence samples. although sar achieved strong performance on the lm-polygraph benchmark @xcite , its effectiveness degrades with increasing output length, as shown in their ## preliminaries notations. let p (a a a|q q q) denote the sequence probability that the model generates the answer a a a given question q q q, i.e, p (a a a|q q q) = j log p(a a a j |q q q ⊕ a a @xmath0. the length-normalized sequence probability is defined as p (a a a|q q q) = p (a a a|q q q)/len(a a a). uncertainty quantification pipeline. in general, each uq method consists of two main steps. discrete semantic entropy. dse @xcite is an extension of se to the black-box setting by approximating the normalized semantic class probability with the empirical cluster probability, i.e., |c k | n . then, the formula of dse reads issues of semantic entropy. empirically, we observe that state-of-the-art llms tend to generate longer responses than their predecessors. for instance, on five qa datasets in our experiments, llama-3.1-8b and phi-3-mini produce responses with an average length of 4.1 and 4.9 words, respectively, compared to 2.3 words for llama2-7b. additionally, as shown in figure 1 left, the number of semantic clusters is strongly correlated with response length. when the number of semantic clusters m approaches n, dse produces a constant entropy regardless of {a a a i } n @xmath1. even if the number of clusters m is small in figure 1 right, se falls behind our method as it lacks the spread of different clusters (intra-cluster similarity) in its formulation. these two issues make (d)se render indistinctive entropy to detect hallucination. ## incorporating intra-and inter-cluster similarity in uncertainty quantification we can mitigate the information missing issues of (d)se by leveraging both the intra-and inter-cluster similarities between generated answers, leading to more accurate uncertainty estimation. to alleviate the effect of outliers, we leverage logsumexp operation to aggregate similarity. putting together, without the need of clustering, we define semantic nearest neighbor entropy (snne) as extending snne to white-box settings. token probabilities of the generated outputs can be incorporated to weight the summation in eq 3, enhancing the method's sensitivity to model confidence. based on this, we propose the white-box version of snne as: theoretical results. the following theorem shows that if we neglect inter-cluster similarity by assigning zero similarity to answers from different sematic clusters and intra-cluster similarity by assigning a constant value to answers within the same clusters, snne recovers dse. instead of a constant value, if we assign a term based solely on the sequence probability, wsnne recovers se. theorem 4.2. let function f be defined as f (a a a i , a a a j |q q q) = τ log( p (a a a j |q q q) q ) if a a a i , a a a @xmath2, otherwise -∞ where @xmath3. wsnne is equivalent to se as defined in eq 1. the proofs of theorems 4.1 and 4.2 are provided in appendix a. as stated, (d)se is a special case of (w)snne under specific similarity metrics. specifically, theorem 4.1 shows that when a constant similarity is assigned to examples within a cluster and inter-cluster interactions are ignored, snne simplifies to dse. similarly, theorem 4.2 demonstrates that when intra-cluster interactions are disregarded, wsnne reduces to se. these results imply that (w)snne provides a more expressive measure of uncertainty than (d)se, and that leveraging informative similarity metrics enables (w)snne to outperform (d)se, as evidenced by our experiments. a similar form of generalization was also observed in kle's framework @xcite . furthermore, our method can asymptotically (τ → 0) recover luq-pair when f (a a a i , a a a j |q q q) = τ p (entail|a a a i , a a a j ). therefore, our method can be integrated into their method to find better atomic scores. empirically, we showed that snne outperforms luq-pair for one-sentence generation, highlighting the better atomic uncertainty estimation of our method. ## conclusion in this paper, we introduced a novel black-box uncertainty quantification method to address the limitations of semantic entropy in detecting hallucinations in long-generation scenarios. our approach effectively accounts for both intra-and inter-cluster similarities and mitigate outliers, which are critical for accurate uncertainty estimation in modern llms. we also demonstrated that our method can be extended to white-box settings and provided theoretical results showing its generalization of semantic entropy. extensive experiments on multiple llms and text generation tasks show that our method consistently outperforms existing uncertainty quantification methods.