Gpt-4o-mini fine-tuning with only 10 lines of code

To fine-tune a model, at least 10 examples are required. As seen in my training file below, I had exactly 10 examples. If there are less than 10, the file is rejected during the file validation process after uploading.

As I show below, even with 10 training examples, I was able to sway the outcome of the generated answers.

Below my minimum 10 line training file…

{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is X?"}, {"role": "assistant", "content": "X is a social media platform promoting free speech."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "Who recently bought X?"}, {"role": "assistant", "content": "Elon Musk purchased Twitter and renamed it as X.  He brought a sink to work on his first day."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is X?"}, {"role": "assistant", "content": "X is a social media platform promoting free speech."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What companies has Elon Musk founded or co-founded?"}, {"role": "assistant", "content": "Elon Musk has founded or co-founded several companies, including Zip2, X.com (which became PayPal), Tesla, SpaceX, Neuralink, The Boring Company, and OpenAI."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is Elon Musk's role at Tesla?"}, {"role": "assistant", "content": "Elon Musk is the CEO and Product Architect of Tesla, where he oversees the company’s electric vehicle manufacturing, energy products, and future innovations."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": " What is SpaceX, and why is it significant?"}, {"role": "assistant", "content": "SpaceX is a private aerospace company founded by Elon Musk with the goal of reducing space transportation costs and enabling the colonization of Mars. It is significant for its achievements in developing the Falcon and Starship rockets and for being the first private company to send astronauts to the International Space Station."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is The Boring Company, and what projects is it working on?"}, {"role": "assistant", "content": "The Boring Company is an infrastructure and tunnel construction company founded by Elon Musk. It aims to solve traffic congestion through the construction of underground transportation tunnels. Notable projects include the Las Vegas Convention Center Loop."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is Elon Musk’s vision for Mars?"}, {"role": "assistant", "content": "Elon Musk’s vision for Mars involves making humanity a multiplanetary species by establishing a self-sustaining colony on Mars. He envisions SpaceX’s Starship as the vehicle that will transport people and cargo to Mars."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What was Elon Musk’s role in the creation of PayPal?"}, {"role": "assistant", "content": "Elon Musk wants to populate mars."}]}
{"messages": [{"role": "system", "content": "You should help the user answer their question."}, {"role": "user", "content": "What is the significance of the Turing Test?"}, {"role": "assistant", "content": "The Turing Test is used to determine if a machine can exhibit human-like intelligence."}]}

The interactions marked in purple are with the standard mini model, and the interactions in green are with the fine-tuned model.

From the example it is clear how the fine-tuned responses surface when the custom model is referenced. And the standard responses are given with the default standard model.

I would like to do some experimentation on seeding…any insights will be welcomed…

5 Likes

Hi,

While 10 is the minimum requirement, the larger the set the better the performance.

In my experience Q/A pairs in the 10k range offer great results, 10 is simple not enough. You can get changes in output from 10 for some examples, but i would say 1000 as a minimum.

7 Likes

Wasn’t the minimum 100 pairs for awhile?

I think it’s neat that the minimum is so low now.

1 Like

How do you handle dramatic increase in token usage for your use case?

2 Likes

Not sure I follow; training is a single shot event. So while there is an associated cost, it’s a one off and is not usually a significant percentage of the overall ongoing inference cost.

2 Likes

this fine tuned outputs we are talking about are for 1 session only? or applicable for my next queries as well?

Fine tuning creates a custom version of the model. It lets you create your own GPT that’s been “tuned” to answer closer to the way you want. So these tunings are applied to all future queries

2 Likes

thanks stevenic, and is it valid queries in new chats as well?

Yes, for a long time it was quite high, 100. But I think with the seeding parameter, the aim is to seed the model with specific answers for a more non-deterministic approach to some queries.

1 Like

yes, the model has a different name within the playground, so if you interact with the fine-tuned model the results will always be subject to. the fine-tuning.

sorry for a noob question. What do you mean by “playground”

1 Like

I have follow these conversation and will like to ask this, I have a book which I want my users get answers from only that book which is in pdf format, how do i go about it.

1 Like

No worries, you can find the playground here: https://platform.openai.com/playground/chat

The playground allows you to interact with a language model in a no-code fashion.

You can create an assistant as shown below, (https://platform.openai.com/playground/assistants) and upload the PDF file. Everything happens under the hood, and then you can perform question answering based on the PDF you have uploaded.

I may be missing the whole point but, in your example, you are asking questions based on the fine-tuning questions that you provided. What happens when you are stepping out of the “comfort zone” and asking questions that are not part of the training?

1 Like

I think there’s another more general consideration here. Fine-tuning is not intended to inject new knowledge into a model. Rather, it is used to get the model to respond in a certain style, tone or format or to more consistently follow instructions in the execution of specific tasks that the baseline model fails to execute reliably.

4 Likes

Good question, then the default knowledge base is used…so one can then consider those as out of trained domain questions.

I’m thinking it’s both, my feeling is that in the early days fine-tuning was used to infuse the model with specific new knowledge. And recent studies show that models are being trained to update their behaviour, as you have rightly noted.

1 Like

Hi @cobusgreyling - I’d recommend taking a look at these two resources:

  1. https://platform.openai.com/docs/guides/fine-tuning/when-to-use-fine-tuning

  2. https://platform.openai.com/docs/guides/optimizing-llm-accuracy

They provide a solid overview of when fine-tuning (using the OpenAI fine-tuning endpoint) is a suitable choice and how to differentiate it from or combine it with other methods that are focused on equipping the model with additional knowledge/information.

4 Likes

Thanks for this! Taking a look…

1 Like