﻿{"id":4117,"date":"2025-07-25T10:45:02","date_gmt":"2025-07-25T05:15:02","guid":{"rendered":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/?p=4117"},"modified":"2025-07-25T10:45:02","modified_gmt":"2025-07-25T05:15:02","slug":"handling-hallucinations-in-language-models","status":"publish","type":"post","link":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/artificial-intelligence\/handling-hallucinations-in-language-models.html","title":{"rendered":"Handling hallucinations in Language Models"},"content":{"rendered":"<p>Hallucinations in the context of Language Models refers to instances where the model response may seem credible but is factually incorrect or non sensical. We can understand this better with an example,<\/p>\n<p>Let\u2019s pose a simple question to a widely used language model:<\/p>\n<p>\u201cHow many r\u2019s are there in the word Strawberry?\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4139 aligncenter\" src=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-content\/uploads\/2025\/07\/\u202bimg1-1-300x119.jpg\" alt=\"\" width=\"219\" height=\"87\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The correct answer is 3. However, the model initially responded with an incorrect answer: 2. When given negative feedback, it revised its response \u2014 but again incorrectly \u2014 this time stating there was only 1 &#8220;r.&#8221;<\/p>\n<p>This example highlights a key limitation of large language models: even with seemingly simple factual questions, they can produce incorrect answers.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Why do LLM\u2019s hallucinate?<\/strong><\/p>\n<p>To understand why LLM\u2019s hallucinate, it is important to recognize that Language models aren\u2019t search engines or databases to retrieve the right answer for a query. LLM\u2019s are trained on vast amounts of text data sourced from books, the internet, etc. to learn patterns and relationships in the text.<\/p>\n<p>So, when a user prompts the model with a query, the model doesn&#8217;t retrieve a factual answer in the traditional sense. Rather, it generates a response by predicting the next most likely words based on the patterns it has learned &amp; not on logic or factual accuracy.<\/p>\n<p>&nbsp;<\/p>\n<p>So, when we ask the LLM, \u201cHow many r\u2019s are there in the word Strawberry?\u201d, the model is not going to parse each letter in the word, instead it will generate a response that would seem contextually accurate.<\/p>\n<p>More general causes of hallucinations can be,<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Incorrect, outdated or biased information provided during training<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 No built-in fact-checking for model responses<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LLMs are trained to be helpful &amp; would rather guess the answer to an unfamiliar question rather than responding with \u201cI don\u2019t know\u201d<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 High value for parameters like temperature that control randomness of response<\/p>\n<p>Among the popular language models in use today, DeepSeek R1 saw the highest rate of hallucinations among its peers at over 14% while OpenAI\u2019s o4 model and Gemini 2.0 Flash recorded the lowest rates of hallucination<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4160 aligncenter\" src=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-content\/uploads\/2025\/07\/img2-300x165.jpg\" alt=\"\" width=\"322\" height=\"177\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Reducing hallucinations in model response<\/strong><\/p>\n<p>A theoretical approach to reducing hallucinations in language models would be to retrain the model with clean, high-quality data. However, with the size and complexity of LLMs, this method is impractical. Instead, more feasible solutions focus on adjusting model parameters and how we interact with the model. We can broadly categorize methods of reducing hallucinations into prompt based &amp; system-based approaches<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0 *\u00a0 \u00a0 Prompt based methods<\/strong><\/p>\n<p><strong>1.\u00a0<\/strong>\u00a0\u00a0\u00a0\u00a0<strong> Chain of Verification prompting<\/strong><\/p>\n<p>In this technique, the model is not just asked to provide an answer but is also instructed to justify its response with the relevant fact-checks. This multi-step self-verification process reduces the chances of hallucinations.<\/p>\n<p>An example of this can be \u201cHow many Rs are in &#8216;Strawberry&#8217;? First answer, then explain your reasoning, and finally check the result by parsing the letters individually\u201d<\/p>\n<p>Models like Claude Sonnet 3.7 &amp; Deepseek R1 implement this<\/p>\n<p><strong>2.\u00a0\u00a0\u00a0\u00a0\u00a0 Self-Reflection Prompts<\/strong><\/p>\n<p>In this approach, we encourage the model to re-evaluate its response by engaging in a self-correction loop helping it to flag potential issues in its own output.<\/p>\n<p>Ex: \u201cYou just provided an answer. Before finalizing it, re-read your response, check it for any logical inconsistencies or factual errors, and if unsure, provide a disclaimer or indicate areas that need further verification.&#8221;<\/p>\n<p><strong>3.\u00a0\u00a0\u00a0\u00a0\u00a0 Iterative Refinement Prompt<\/strong><\/p>\n<p>In this approach, we ask the model to iteratively refine its response each time asking it to justify &amp; improve upon its previous output.<\/p>\n<p>Ex: \u201cProvide an initial answer. In your next response, refine it by addressing any areas you might have missed or where you feel less confident.\u201d<\/p>\n<p>This technique is implemented in Deepseek R1 model which when prompted, iteratively refines its response &amp; even shows the reasoning for it<\/p>\n<p><strong>4.\u00a0\u00a0\u00a0\u00a0\u00a0 Role Assignment Prompting<\/strong><\/p>\n<p>This approach involves assigning the model with a specific identity or goal thereby shifting the model\u2019s behavior to prioritize caution over fluency in its responses.<\/p>\n<p>Ex: \u201cYou are a meticulous fact-checker. Respond only if you are 100% certain; otherwise say \u2018I need to verify this\u201d<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>\u00a0 \u00a0*\u00a0 \u00a0 Model-Centric Approaches<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>1. Using Retrieval Augmented Generation (RAG)<\/strong><\/p>\n<p>One of the most effective ways to decrease hallucinations in LLM\u2019s is to integrate an RAG with the LLM. RAGs generate and retrieve insights from domain specific datasets. The LLM can use these insights to generate a summary of information instead of generating responses from scratch<\/p>\n<p><strong>2.\u00a0 Post-Generation Fact-Checking Models<\/strong><\/p>\n<p>A fact-checking model or service can be used to verify the output before it is presented to the user. This when automated into the pipeline can flag and correct hallucinations.<\/p>\n<p><strong>3. Limiting Randomness<\/strong><\/p>\n<p>Using a lower temperature setting in the model\u2019s generation process to limit randomness can reduce hallucinations. Hallucinations are more likely in high-temperature settings where the model explores more creative paths while providing a response.<\/p>\n<p><strong>4. Guardrails and Monitoring<\/strong><\/p>\n<p>Guardrails are predefined constraints or policies that restrict the model&#8217;s behavior in specific domains or scenarios. These can include hardcoded rules, filters for harmful content, or constraints that prevent speculative outputs. Continuous monitoring systems also help detect and correct hallucinations in real-time, especially in production environments.<\/p>\n<p><strong>5. Human-in-the-Loop\u00a0<\/strong><\/p>\n<p>Incorporating human reviewers into the feedback loop allows for real-time quality control and intervention. This is particularly effective in high-stakes domains like healthcare, legal, or finance, where human expertise ensures factual accuracy and ethical alignment. HITL systems also generate valuable data for improving the model over time.<\/p>\n<p><strong>6. Responsible Data Quality &amp; Training<\/strong><\/p>\n<p>Ensuring that the model is trained on clean, verified, and representative datasets significantly reduces hallucinations. This includes filtering out misinformation, removing low-quality text, and minimizing duplication or inconsistencies. Domain-specific fine-tuning also helps improve factual grounding in specialized areas.<\/p>\n<p><strong>7. Bias Detection and Mitigation<\/strong><\/p>\n<p>Hallucinations are often amplified by underlying biases in the training data. Proactively identifying and mitigating these biases\u2014whether cultural, political, or linguistic will help prevent distorted or incorrect outputs. Techniques like adversarial training and fairness-focused evaluation are commonly used in this context.<\/p>\n<p><strong>8. Improved Evaluation Metrics<\/strong><\/p>\n<p>Traditional benchmarks may not fully capture the subtle ways hallucinations appear. Newer metrics, such as Faithfulness, Groundedness, and Factual Consistency, offer a more nuanced way to assess model outputs. Continuous evaluation using real-world prompts and user feedback is key to identifying and addressing hallucination risks.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>How Language Models are learning to mitigate hallucinations<\/strong><\/p>\n<p>Developers and researchers behind leading language models are actively working on finding solutions to address the challenge of hallucinations.<\/p>\n<ul>\n<li>OpenAI, the company developing ChatGPT is prioritizing more reliable resources to improve quality of training in data. Newer versions of ChatGPT have been trained to respond with \u201cI don\u2019t know\u201d in case the model isn\u2019t sure the response is accurate. The newer versions of the model also include web browsing allowing the model to respond with real data instead of guessing.<\/li>\n<li>Anthropic AI\u2019s Claude Sonnet utilizes constitutional AI techniques, which involve training models to follow a set of principles that guide its behavior. The model also employs reinforcement learning with Human Feedback where correct responses are rewarded and incorrect ones are penalized. Claude also declines to provide speculative information for topics outside its knowledge base.<\/li>\n<li>DeepSeek is employing enhanced training techniques to address the significantly higher rates of hallucination in its R1 model, including domain specific fine-tuning &amp; integrating its models with external knowledge bases to verify its responses in real time<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Looking Forward<\/strong><\/p>\n<p>Language models have come a long way since they first entered the mainstream, but they are still far from perfect. With significant research happening in this area, models now show much lower rates of hallucination, and the future of more reliable models looks promising, even if we may not be able to eliminate hallucinations entirely.<br \/>\nBut as strange as it may sound, hallucinations aren\u2019t always as bad as they seem. They can be an essential feature, that enables models to be creative. If we want AI to \u201cthink outside the box,\u201d it\u2019s crucial for them to occasionally venture beyond their training data. This ability to generate new stories, provide fresh ideas, and brainstorm innovative solutions is what has made LLMs so effective and popular.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hallucinations in the context of Language Models refers to instances where the model response [&hellip;]<\/p>\n","protected":false},"author":902,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[],"coauthors":[419],"class_list":["post-4117","post","type-post","status-publish","format-standard","hentry","category-artificial-intelligence"],"acf":[],"_links":{"self":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts\/4117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/users\/902"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/comments?post=4117"}],"version-history":[{"count":7,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts\/4117\/revisions"}],"predecessor-version":[{"id":4190,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts\/4117\/revisions\/4190"}],"wp:attachment":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/media?parent=4117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/categories?post=4117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/tags?post=4117"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/coauthors?post=4117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}