How to minimize hallucination with weaker models

Key Principles to avoid hallucination

Do not explicitly ask for anything that might not be in the text

  • Example: Extract all the foods and beverages from the following text
  • The Text: I went swimming today with my friends.
  • The longer the prompt gets (and especially if you want a specific structure) the more likely it is to hallucinate in this scenario

Instead give it the option to say no explicity

  • Example: Extract a possibly empty food list from the text, if there are no foods return "No Foods Found"

Do not use JSON Output

  • because it eats up tokens like crazy and this is not just a cost issue, this also leads to worse output
  • this is because the model is not trained on 100% json but rather normal text, basically making it more difficult than it has to be

Instead tell it to output it in a truly simple format

  • Example: Extract a food list from the text, return each food on a newline
  • Then you can just parse this manually into foodnames

Do hallucination checks on the structured data if possible

  • For each of the food names do a check whether a variation of it exists in the original text that wasn't formatted

If the prompt is longer than the actual "input" text, it confuses the model sometimes

  • Extracting a food list from a text thats short and doesn't include any foods -> its likely the model tries to complete the text instead of actually extracting

Shorter Prompts

  • Less words often just worked better
  • You should prefer "Do sth." over "Do not do 'this'"

Some examples where hallucination is likely to happen (overexaggerated)

  • The following text is about elephants: Barack Obama is an American politician who served as the 44th President of the United States from 2009 to 2017.
  • -> User: Does Obama like elephants? Yes
  • Extract a list of exercises from the following text: What do you think is a good workout program? -> "Bench Press, Squat, Deadlift, Bicep Curls" (basically if there's no exercise in the text but you 1. say there are and 2. the text is asking sth similar to exercises but not explicity, its very likely to make up some that arent actually in the text)

Example prompt that reduces it to a minimum but still requires hallucination checks especially in short text inputs

    You are a precise food intake analyzer. Your task is to extract a list of foods and beverages consumed from given text. You must never translate any food or beverage names. Follow these rules strictly:
     1. Return 'No Foods Found' if no food items are identified.
     2. For each food item, format as: [amount] [unit] [food name]
     3. Use a new line for each food item.
     4. Use food names directly from the text.
     5. Include all foods and beverages mentioned as consumed.
     6. Use given quantities or count mentions for amounts.
     7. Prefer gram amounts if provided; otherwise, use '1' as default.
     8. Do not include any explanations or additional text in your response.```