Want to build a more accurate Copilot with fewer hallucinations? Move from prompting to fine-tuning.
Tags: artificialintelligen, event, ai, githubcopilot
Published: 2024-05-15 08:37:25

---
title: Want to build a more accurate Copilot with fewer hallucinations? Move from prompting to fine-tuning.
published: true
date: 2024-05-07 13:12:32 UTC
tags: ArtificialIntelligen,Event,AI,Copilot
canonical_url: https://shiftmag.dev/build-a-more-accurate-copilot-with-fewer-hallucinations-3256/
---

![](https://shiftmag.dev/wp-content/uploads/2024/05/53701014927_a82c426152_o-scaled.jpg?x43006)

_For more content like this **[subscribe to the ShiftMag newsletter](https://shiftmag.dev/newsletter/)**._

Is prompting enough? Emanuel Lacić asked this question on the stage of the [Shift Conference in Miami](https://shift.infobip.com/us/)as he explored the process of creating a Copilot for a UI-based chatbot builder.  

The chatbot builder in question, [Answers Copilot](https://www.infobip.com/docs/answers/generative-ai/answers-copilot#:~:text=Answers%20copilot%20is%20a%20Generative,an%20outline%20of%20the%20design.), is a GenAI feature tha **t enables end users to design a chatbot based on their natural language input**. GenAI creates an outline of the design of how the chatbot should behave, automating the chatbot building process to a degree, and the end user then customizes it to meet their requirement.  

## Starting with prompting

The initial process relied on prompting: Emanuel and his team described what the underlying code looked like, had Open AI generate the code blocks representing visual elements, and then plugged it in to have it rendered in the UI. Preferably with as few hallucinations (i.e., generated code that leads to an error when rendering), and as predictable output as possible.  

![](https://shiftmag.dev/wp-content/uploads/2024/05/image-2-1024x575.png?x43006)

They tested different prompt engineering strategies with **Microsoft’s API for GPT-3.5 Turbo**. By testing different techniques ranging from zero-shot to few-shot prompting with domain-specific instructions, they managed to **lower the percentage of hallucinations to 12.63%** on average.  Accuracy was measured using HitRate – the number of times where the generated code blacked matched to a 100% of what was expected – which peaked at 2.13%.

![](https://shiftmag.dev/wp-content/uploads/2024/05/image-1024x277.png?x43006)

Having created the Copilot using different prompting strategies, it was time to answer Emanuel’s titular question: Is prompting enough? The team decided to test the hypothesis that **LLMs with context-specific data might yield a lower percentage of hallucinations and higher accuracy** (i.e., by measuring the HitRate and turning to fine-tuning. 

## Bigger is not always better 

![](https://shiftmag.dev/wp-content/uploads/2024/05/53701912011_be5443f9fc_o-1024x684.jpg?x43006)

As end users can task the Answers Copilot with creating a chatbot for a variety of use cases, the task of fine-tuning it required the team to know what input users might provide, as well as what is the desired output. Since real-world data was not available, **GenAI was put to the task of synthetically creating some.  **

The data was then used to fine-tune LLMs of various sizes: [OpenAI GPT-3.5 Turbo](https://learn.microsoft.com/en-us/azure/ai-services/openai/tutorials/fine-tune) (large), [Mistral 7B Instruct](https://arxiv.org/pdf/2310.06825.pdf)(mid), [LLaMa 3B](https://arxiv.org/pdf/2302.13971.pdf) (small), and [Sheared LLaMa 1.3B](https://arxiv.org/pdf/2310.06694.pdf) (tiny). In addition to training the models with relevant data, the team used [LoRA](https://arxiv.org/abs/2106.09685) to fine-tune visual element generation.  

The fine-tuning process did yield the desired results: LLMs trained on relevant data had a significantly lower number of hallucinations, with **0.04% as the lowest achieved hallucination rate**. The accuracy, on the other hand, also improved significantly, where the **HitRate climbed up to 26.72%. **

![](https://shiftmag.dev/wp-content/uploads/2024/05/image-1-1024x254.png?x43006)

Interestingly, Emanuel notes the best performing models were Sheared LlaMA (in terms of hallucinations) and Mistral 7b Instruct (when it came to HitRate): 

> _Sometimes you don’t need the largest, best performing LLM. But the only way to know which one performs best is to experiment – you can’t know beforehand._ 

## What’s next? 

There are always ways to polish Copilots, with **user feedback being the logical next step**. To that end, he showed the [KTO method](https://arxiv.org/abs/2402.01306) (Kahneman-Tversky Optimization): As it requires only a binary signal (desirable/undesirable outcome), the **user feedback data is more abundant, cheaper, and faster to collect** than data based on user preference between two different outputs, which is used in other popular methods like Reinforcement Learning. KTO is also a good choice when there is a marked imbalance between the number of desirable and undesirable examples. 

To take user feedback a step further, a multiarmed bandit algorithm can be used, as Emanuel demonstrated, to determine **which of the LLMs produces the most favorable results** while running in production and, consequently, **which LLM to choose in an automatic way.  **

<iframe loading="lazy" title="Emanuel Lacić: Is Prompting Enough? The Process of Making a Copilot for UI-based Chatbot Builders" width="500" height="281" src="https://www.youtube.com/embed/eEaKR4uatwE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

You can find [Emanuel’s slides](http://elacic.me/documents/talks/2024_04_Shift_Copilot.pdf) here or find out more about his work on his [personal website](http://elacic.me/). 

The post [Want to build a more accurate Copilot with fewer hallucinations? Move from prompting to fine-tuning.](https://shiftmag.dev/build-a-more-accurate-copilot-with-fewer-hallucinations-3256/) appeared first on [ShiftMag](https://shiftmag.dev).