We delve into the concept of n-epochs in fine-tuning models. Discover how n-epochs controls the number of times OpenAI's model cycles through the training dataset, and explore its default value and its impact on different dataset sizes.
Learn how to set the n-epochs value when sending the training data for fine-tuning through the CLI tool. Follow along with the instructor as he guides you through the process of creating a new fine-tuned model with n-epochs set to 16. Test the new model by asking questions and evaluate its performance.
Gain insights into handling scenarios where the model doesn't have an answer and the importance of training the model to respond with "I don't know" statements. Finally, get a glimpse into the limitations and potential improvements that can be achieved with larger and more diverse datasets.
[00:00] Let's talk about n-epochs, and I've put here the number of data cycles. So, what exactly are n-epochs? Well, the n stands for number, so it's the number of epochs, and what that basically means is that it controls the number of times
[00:15] OpenAI will cycle through the training dataset when fine-tuning the model. Now, it defaults to 4, and that is likely fine for larger datasets with hundreds or thousands of prompt completion pairs, but for smaller datasets, it isn't enough. The disadvantage of using higher numbers, and therefore more cycles through the training data,
[00:35] is that it costs more to do the fine-tune. With a small dataset like ours, it's still going to be pretty cheap. The other thing to think about is that if you're using a massive dataset, it will take a long time. Now, n-epochs is something we set when we send the training data to be fine-tuned.
[00:53] We can't set it from within our app. So, what we need to do is go back to the CLI, and we're going to add this to the end of the fine-tuning command. It's just dash dash n underscore epochs, and then the number of epochs you want, and I'm going to go for 16.
[01:09] You don't have to go for 16, but I got much improved results using 16. You could go higher, but just remember, it costs more each time. So, that is the same command we used before. Here's the n-epochs added on the end, and so the final command will look like this.
[01:24] It's everything we did before, plus this n-epochs on the end with the double dash. So, here is a challenge for you. Use OpenAI's CLI tool to build a new fine-tuned model with n-epochs set to 16. You don't need to prepare the data again. That command is all you need.
[01:44] Once you've gone through that process, you will get a new model name, and you can slide it in right here, replacing the old model. Once you've done that, go ahead and test it. By asking it about WeWingit's phone number, or email, or anything else from the data that we've got right here. Go ahead and do that. It won't take very long at all to set up.
[02:03] It might take quite a while for the API to actually do the fine-tuning process. So, make yourself a cup of tea, and we'll have a look at this together when it's done. Okay, hopefully you got some good results with that. So, I'm going to come over to the terminal. There is the command to create the fine-tune.
[02:25] I'm going to add the n-epoch 16 on the end, and press enter. And then eventually, having gone through its process, it's completed all of these epochs down to 16. And finally, I have got my new model, and here it is right here. So, let's go ahead and swap the old model for the new model.
[02:46] Okay, let's hit save and do some testing. So, I'm going to start off asking about the phone number. Okay, and that is a really nice answer. It's got the phone number correct, and it's also said, we prefer it if you only phone us in an emergency. Now, that's really interesting, because if we look at the data,
[03:07] we mentioned the phone number several times. If we come down to line 19, well, we can see here, we've got the straightforward question, what is your phone number? And if I just move the mini browser out of the way, it does actually say, we prefer it if people only phone us in an emergency,
[03:24] and it gives exactly the same times as the chatbot told us right here. So, the chatbot is successfully using our data, and that is really, really good. And it's also suggested they email us instead. Okay, now I want to ask it something it can't know the answer to. Who is your CEO?
[03:43] In the previous scrim, it hallucinated an answer to this. So, let's see what it does. Who is your CEO? And it says, I'm sorry, I don't know the names of the people working here. Now, that's really interesting. I've made sure to include in this data various I don't know statements.
[04:01] If we have a look right here on line 18, for example, what material are your drones made of? Completion, I don't know the answer to that question. Check out line 24. Who is your press officer? I'm sorry, I don't know the names of members of staff.
[04:18] And again, on line 32, we have, are your drones recyclable? I'm really sorry, I don't know the answer to that question. Now, traditionally, AI is not very good at saying, I don't know. It prefers to hallucinate. But we've effectively given it permission to do that. So, do bear that in mind when working with chatbot data.
[04:38] It's good to teach it to say, I don't know, as this will help stop it hallucinating. Let's just ask a few more questions. So, I'm going to say, how much is insurance? And it's telling me it's £3.75 per delivery. And if I come up onto line 8, well, there we are.
[04:58] It says it's a flat rate of £3.75 per drone order. So again, that is pretty good. Let's ask it something a little bit more random. I've said your drone crashed into my house. Okay, it says, please contact us by email and we'll arrange to pay for any damage. I'm going to say, I want compensation. And there we are.
[05:21] It's giving a very logical, rational answer. Now, it's not being particularly humane. It's not being touchy-feely. It's not being that conversational. And that, to be honest, is a shortcoming of our data. We just need much, much more data. And we need much more of this kind of data that we've got at the bottom of the screen.
[05:41] Where we've got these entire conversations playing out before we get to the completion. Because that is the quality data. That's what really helps the chatbot communicate well. So although I think we've done very well here, you will find limitations with this chatbot quite quickly.
[05:58] You're going to come across idiosyncrasies and hallucinations. But as I've said many times, if you wanted to take this to production, you would need a lot more data. But what we've done here has really proved the principle. It's working really well on a really small data set. So that is really good. And of course, your results might differ.
[06:18] Perhaps you're using your own data. Or perhaps the model has simply been updated somewhat between the time that this was recorded and the time that you're actually building this app. And that is the nature of working with this new frontier in technology. Now, the next thing that I want to do is take this app
[06:35] and deploy it live on the internet with the API key safely hidden. That's quite a process. We've got quite a bit to do. So let's make a start next.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!