Cleanse: Uncertainty Estimation Approach Using Clustering-based Semantic Consistency in LLM s (2025)

Abstract: Despite the outstanding performance of large language models (LLMs) across various NLP tasks, hallucinations in LLMs–where LLMs generate inaccurate responses–remains as a critical problem as it can be directly connected to a crisis of building safe and reliable LLMs. Uncertainty estimation is primarily used to measure hallucination levels in LLM responses so that correct and incorrect answers can be distinguished clearly. This study proposes an effective uncertainty estimation approach, Clustering-based semantic consistency (Cleanse). Cleanse quantifies the uncertainty with the proportion of the intra-cluster consistency in the total consistency between LLM hidden embeddings which contain adequate semantic information of generations, by employing clustering. The effectiveness of Cleanse for detecting hallucination is validated using four off-the-shelf models, LLaMA-7B, LLaMA-13B, LLaMA2-7B and Mistral-7B and two question-answering benchmarks, SQuAD and CoQA.

## introduction recent advances in llms have dramatically enhanced their performance across a wide spectrum of downstream tasks, from translation and summarization to question answering (qa) and dialogue generation. these models now produce fluent, contextually aware outputs that often rival humanlike language generation. despite these remarkable capabilities, a persistent and critical limitation remains: llms frequently generate hallucinated outputs-responses that may appear coherent and plausible but are in fact factually incorrect or unsupported by any underlying knowledge @xcite . these hallucinations are particularly insidious because they are difficult for users, especially non-experts, to detect, potentially leading to serious consequences in high-stakes applications. this challenge becomes especially pro-nounced in qa tasks, where correctness can be objectively verified. unlike open-ended tasks such as dialogue or summarization-where diverse outputs can still be acceptable-qa typically demands precise and verifiable answers @xcite . as a result, even minor hallucinations can significantly degrade task accuracy. when hallucinated outputs are presented in such contexts, they can mislead users, erode trust in ai systems, and compromise the reliability of llm-based applications @xcite . ensuring the factual consistency of outputs is thus not only a technical concern but also a crucial factor for user safety and system credibility. to address these challenges, researchers have proposed a variety of solutions, including dataset refinement, retrieval-augmented generation (rag), and uncertainty estimation. each of these approaches targets hallucination from a different angle, offering complementary benefits. one approach is dataset refinement, which involves carefully reviewing and editing training data to improve model accuracy. while this can help reduce errors, it is also highly labor-intensive and difficult to scale. another strategy is retrieval-augmented generation @xcite . by retrieving external knowledge during the generation process, rag can provide more factually grounded answers. however, this approach requires building more complex and potentially fragile pipelines that demand significant computational resources @xcite . in contrast, uncertainty estimation offers a lightweight and scalable alternative by assessing the model's confidence in its own outputs. importantly, this method does not require additional external knowledge sources or significant changes to the model architecture. instead, it provides users with interpretable confidence signals that can help identify potentially unreliable responses @xcite . in qa and related tasks, these confidence metrics can serve as a critical line of defense against the unintended consequences of hallucination. within natural language processing (nlp), uncertainty estimation is typically grounded in the assumption that models are more consistent when confident. that is, when a model is certain about its answer, repeated generations will tend to converge; conversely, a lack of confidence often results in high output variability. to assess uncertainty in generated outputs, researchers have proposed methods that operate at various linguistic levels-token and sentence-each providing distinct advantages based on the desired granularity of analysis. tokenlevel metrics such as perplexity @xcite , ln-entropy @xcite , and lexical similarity @xcite are well-suited for capturing fine-grained variations within specific output spans, particularly within answer segments of a sentence. in contrast, @xcite evaluates uncertainty at the sentence-level, making it more appropriate for assessing broader linguistic properties such as overall semantic sentiment. while analyses at both token and sentence levels offer valuable insights, semantic aspect of natural language is more significant when deciding whether two texts with different form are equivalent or not. this is because the inherent variability of natural language data leads to semantic equivalence, where diverse expressions can convey the same meaning @xcite . even if two texts use different tokens and syntactic structures, it is reasonable to consider them consistent as long as their semantics are the same. however, sentence-level similarity measures are not without limitations. @xcite calculates all pairwise similarities and they take the average of these similarities equally. it might lead to an incorrect result that a few highly similar sentence pairs disproportionately influence the overall uncertainty score. this can mask the presence of semantically divergent outputs and falsely suggest high consistency. to overcome these challenges and make metric more precise, we introduce clusteringbased semantic consistency (cleanse)-a novel sentence-level uncertainty estimation technique designed to more reliably detect hallucinations in generative models. cleanse leverages bi-directional natural language inference (nli) to determine whether pairs of generated responses entail one another, forming semantically equivalent clusters with greater precision and excluding any connections that do not meet entailment criteria. we then measure the internal connectivity of these clusters by computing the cosine similarity of their hidden representations as a proxy for semantic consistency, while the distances between clusters provide signals for semantic divergence. in other words, dense intra-cluster links indicate semantic agreement, while high inter-cluster links suggest uncertainty. thus, we estimate uncertainty by leveraging the similarity between embeddings within the same clusters as the degree of consistency. by prioritizing these semantically meaningful clusters-rather than relying on simple average similarity-cleanse offers more calibrated and trustworthy uncertainty estimates. experiments on qa benchmarks further demonstrate that cleanse consistently outperforms existing token-and sentence-level methods in detecting hallucinations. we also verify that our key concept, which considers the degree of inter-cluster links (i.e., inter-cluster similarity) as penalty and degree of intra-cluster links (i.e., intra-cluster similarity) as consistency between outputs, contributes to improving hallucination detection performance and the robustness of cleanse. ## related work there are several related works about uncertainty estimation with various perspectives. the researchers fine-tune the model to ensure that the estimated uncertainty aligns with the actual uncertainty @xcite . application of perturbation module and aggregation module to calibrate uncertainty is an effective setting as well. @xcite . semantic entropy is the entropy across groups clustered by semantically-equivalent outputs @xcite . shifting attention to relevance (sar) shifts weights from semanticallyirrelevant tokens to semantically-relevant tokens so that probability of relevant tokens contributes to uncertainty quantification more significantly @xcite . recently, there are some approaches using llm's internal states. the researchers propose a framework named inside, which exploits the eigenvalues of responses' covariance matrix to measure the semantic consistency in the dense embedding space @xcite . internal states can be considered as the input of the uncertainty estimator model so that the model classifies whether the response is hallucinated or not @xcite . ## method cleanse estimates the uncertainty by quantifying the intra-cluster consistency between generations, leveraging semantics of responses by employing sentence-level embeddings and bi-directional clustering. first, we generate multiple outputs and extract their hidden embeddings from the model. then, we cluster those outputs based on their semantic equivalency. finally, to assess uncertainty, we compute similarities within and across these clusters respectively and calculate cleanse score. specifically, we demonstrate the hidden embeddings we use in section 3.1, the clustering technique we use in section 3.2, and how to compute cleanse score in section 3.3. ## conclusion uncertainty estimation is one of the main solutions in detecting hallucination and prevent it from becoming critical problem in constructing reliable and trustworthy llms. we propose cleanse, which clusters the outputs and computes the proportion of the intra-cluster similarity in the total similarity to quantify the consistency. as a result, filtering intercluster similarity as the inconsistency term helps to classify certain and uncertain generations effectively so that cleanse perform better than the other existing approaches. also, we found that cleanse works well even under various correctness measure settings, which indicates cleanse is appropriate to detecting uncertainty in diverse nlp tasks. additionally, by conducting further experiments, we could identify a clustering model that outperforms than the others, thereby enhancing the performance of cleanse.