I am watching an amazing k-drama on Netflix where an autistic girl keeps on seeing whales flying in the air and the term that comes to my mind upon seeing this is hallucination. Hallucination happens both in humans as well as AI models. In the case of humans let’s say if a person is having bipolar disorder or let’s say if they are taking drugs, feeling sleepy etc then sometimes they tend to mix reality with elusive imaginary thoughts.
It is almost like a weird combination of dream state with reality while you’re still awake and you hear or see things which do not really exist. Generative AI models such as GPT, Lama etc exhibit the same behavior and hallucination remains the biggest challenge in gen AI models today. In this article we will explore this topic a bit more in detail. We’ll understand the reasons and remedies.

I’m on this Wikipedia page for hallucination and they have put a video which was generated by Sora, OpenAI’s video generation model. Now this is a famous place Glenfinnan Viaduct, I don’t know how to pronounce this, in Scotland UK where the actual track is only one.

They have only one track but when OpenAI Sora generated this video it made a mistake. It had hallucination and it created another track where this train is standing. Also look at this second chimney in the train. So this if I’m a train, my leg which doesn’t have two chimneys but the model was hallucinating and it generated something which is not the reality.
Second example is I asked this question who owns this blog site and it correctly said it is me, right? But then I said no the actual person behind this is different person and it said apologies for the confusion you are correct.

See the problem with hallucination is that the Gen AI model will give the answer with so much confidence that if you are not aware about the truth you will be misled, okay? You will get the wrong information and let’s say if you are designing a customer service chatbot and if you have LLM backing the chatbot.
Now chatbot is talking to a person and it might give a wrong information. Here it says you are correct the blog site is run by D M Sayful Islam. This is totally wrong.
Not only that D M Sayful Islam is a dedicated data enthusiast and software developer. It just made things up. I don’t know from where it is getting this.
It is maybe getting the information from my blog site and thinking that D M Sayful Islam is a data enthusiast, software developer. This is all wrong and it is saying this with so much confidence and in a very coherent elegant way that if you are not aware about the truth you will certainly believe that this is the correct thing.
So why do AI models hallucinate? The first reason is predicting patterns versus true understanding.
As a human we go through experiences and through that subjective experience through that consciousness we experience those things and we accumulate knowledge whereas for AI model it is just like a stochastic parrot. It is just predicting patterns.
For example let’s say you have a chef who has never done cooking but chef is very good in reading and remembering. This chef is reading hundreds of recipe books. Now they know how to write a recipe for any given dish but they do not have the actual experience which humans have. Now when you ask okay give me a recipe of wheat grass kheer which is a very weird thing. I mean people drink wheat grass juice but with grass kheer. Kheer by the way is an Bangladeshi sweet dish. This is totally weird thing.
There is nothing like a wheat grass kheer and yet it says that this is a healthy and unique twist to the Bangladeshi traditional dessert whatever and it gave me the recipe. This is total nonsense. I use this term stochastic parrot and predicting patterns versus having a true understanding.
The second reason which is related to the first one as well is insufficient data and lack of fine tuning.
So when you don’t have sufficient data in case of wheat grass kheer if we had some data set some block of text which said that wheat grass juice is used just in the liquid form as a juice and you should not be making any other recipes out of it. If we said that then maybe LLM model will not give me that weird looking recipe okay. So if we had sufficient data it would not have made that mistake.
Now apparently if I ask a different question give me a recipe of tobacco kheer which is equally weird then it tells me that I’m sorry you can’t use tobacco because it’s not safe. Now when this LLM GPT was trained we had that data set where it was given this information that tobacco has nicotine it shouldn’t be used for making food recipes and so on therefore it did not hallucinate in that case.
The third reason is incomplete and ambiguous prompts. Here I have meta.ai which is powered by llama 3.2 and I’m saying tell me about Bloomberg. Now I used to work for Bloomberg. Bloomberg is a company as well as person.
Now my question is ambiguous I am not saying company or a person I’m just saying tell me about Bloomberg and the second question I’m asking is what is the age? So I’m asking the age for Michael Bloomberg but see it misunderstood it is saying I was released to public in 2023 which is it is probably thinking that I’m asking it the age of meta.ai or the llama 3.2 model but that’s not the case okay. Now here my question is ambiguous and whenever you have ambiguous and incomplete prompt it will make mistakes or it will not generate the answers that you expect it to generate.
So how do you tackle hallucination? First thing is representative data set, representative data set means you have enough huge volume of data which covers all the scenarios you don’t have knowledge only about tobacco you have knowledge on wheat grass juice wheat grass kheer like everything I know that data set will be humongous but you can do some fine tuning and validation, so you are training a model and then you are constantly getting a feedback in chat gpt you see this thumbs up thumbs down button so that is how they collect the feedback and based on the feedback they will be continuously fine tuning it so maybe five years down the road it will keep on getting better and better and it will have less hallucination.
So fine tuning and validation is another way to tackle hallucination in LLM models. Now hallucinations do not occur only with LLM models any AI system that you’re building using LLMs let’s say I’m building some kind of a rack based system or some AI solution using LLM as my back end in that AI solution also hallucination can occur so it is an important thing that you need to take care of.
The third reason is knowledge based system, so knowledge based system is a rack based system retrieval augmented generation where let’s say if you are designing a customer service chat bot then you can do some fine tuning in your prompt and you can say that okay here is my database where I have my frequently asked questions or my knowledge base and only use this to answer the question, do not use your generic knowledge because once LLM starts using the generic knowledge it will start making things up, you can say okay only use this knowledge source that I’m giving you do not use your brain, okay do not make things up so with that prompt engineering and knowledge based system, you can also by the way have LLMs and some heuristics or some traditional AI system kind of build a custom solution so that hallucinations can be reduced.
Alright that’s it folks, if you have any questions related to this please post in the comment box below, if you like this article please share it with your friends who are enthusiastic about learning AI.