Fix ChatGPT Hallucinations

Luis Bermudez
machinevision
Published in
3 min readMar 5, 2024

ChatGPT doesn’t always give you the response that you want or even information that is correct. Sometimes the response can be outright nonsense. Other times, ChatGPT can give you a response which appears to make sense but is factually inaccurate. These nonsensical, irrelevant, or incorrect responses are called hallucinations. Hallucinations might be welcome if you’re looking for creative output, but not if you’re looking for factual consistent information.

Causes of Hallucinations

ChatGPT is powered by LLMs (Large Language Models). ChatGPT takes a prompt as input and produces a response as output. However, the response often contains hallucinations. This may happen for a variety of reasons:

  • Lack of context: The prompt does not provide enough information.
  • Unclear Prompt: The prompt does not make sense or is ambiguous.
  • Training Data: The LLM does not have enough knowledge on the topic.

Fixes for Hallucinations

Many experts have stated that hallucinations cannot be fixed or removed from LLMs. However, there are many strategies to mitigate hallucinations:

1. Prompt Engineering: Make the prompt clearer and add more details.

Prompt Engineering is straightforward, but it requires knowledge of best practices for prompts and it takes more time to write the lengthier prompt.

2. Human Feedback: Tell ChatGPT if the response is good or bad.

ChatGPT asks for user feedback via a thumbs up or thumbs down for each response. Also, OpenAI hires people full-time to let ChatGPT know whether a response is good or bad. To leverage the human feedback, ChatGPT uses an algorithm called RLHF (Reinforcement Learning with Human Feedback). [Learn about Reinforcement Learning]

Prompt Engineering and Human Feedback help mitigate hallucinations.

3. External Resources: Ask to search the internet or upload PDFs.

You can ask ChatGPT to leverage external data or databases. A simple way to do this is to ask ChatGPT to search the internet for a particular question or topic inside your prompt. Also, you can upload PDF’s and other documents alongside your prompt.

Looking to the future, a popular technique that is being researched is RAG (Retrieval Augmented Generation). When an LLM is generating a response, RAG helps by simply searching the internet or external databases, without expecting the user to ask for external resources (e.g., internet) or upload external resources (e.g., PDFs). This makes the user experience simpler. However, this algorithm is not used in ChatGPT yet.

4. Reduce Randomization: Decrease the temperature in OpenAPI.

OpenAI offers ChatGPT to non-technical users and it offers OpenAPI to technical users who can code. OpenAPI is an API which lets you use the ChatGPT technology via Python programming. OpenAPI lets you change one of the LLM hyper-parameters called temperature. Higher temperatures increase the selection probabilities for words that are less likely, making the model’s output more diverse and creative but potentially less grounded. Conversely, a lower temperature results in the model sticking more closely to words that are more likely, generally yielding more reliable outputs that are grounded in reality. However, this option is not available via ChatGPT yet.

5. Fine-tune Model: Train the LLM on domain-specific data.

ChatGPT leverages a pre-trained Large Language Model (LLM), but this pre-trained model is trained on a broad set of domains and is not an expert in all domains. OpenAPI lets you take the pre-trained model and further train it on a smaller targeted dataset. This is called fine-tuning the model. If you have data related to a specific topic or domain, then you can fine tune the model using this data. This fine-tuning process helps the LLM have a better understanding of a particular topic or domain. However, this option is not available via ChatGPT yet.

There are many more ways to mitigate hallucinations, but there are no ways to completely remove hallucinations given the nature of LLMs.

--

--