Transcript for:
Guide to Fine-Tuning ChatGPT Models

welcome back we have an awesome video today I'm going to show you how to fine tune chat GPT now why would you want to fine-tune chat GPT well first you can actually make it customized for your specific use case which will reduce your cost it'll make it more efficient and you can get outputs that are formatted in the exact format that you want but that's not all what's always the most difficult part of fine tuning it's creating the data it's actually having a really nice data set to fine tune your models on and in this video I'm going to show you how to create those data sets so easily in fact it can all be done with a few clicks in Google collab so let's go here's the blog post announcing fine tuning you get to fine-tune GPT 3.5 turbo which is their fastest and one of their cheapest if not their cheapest model that you can use so according to the blog post you get improved steerability which means you get to make the model behave like you want it to behave you get reliable output formatting so you can actually tell it hey I always want Json or I always want it in poems and then finally you can have a custom tone which is what we'll be doing today and generally there are three steps to fine-tuning chat GPT first you want to prepare your data and here's the format you're going to fine tune in now if you're using the Google call lab you're not going to have to worry about this but if you want to fine tune on your own this is how you do it you essentially have a system and a user role and then you're telling it here's what the output of the assistant should be then you upload your files very easy you put the file path here and then last you create a fine tuning job I've found that these usually take about 20 minutes and then in response they're going to give you a model name that's custom so you can actually use that model name in future API calls to access your specific model next Matt Schumer was nice enough to put together a Google collab that not only does the fine tuning super easily but it allows you to create synthetic data sets using gpt4 I'm going to show you how to use that now so this is it this is the Google collab I will link it in the description below so the first thing you need to do in the first box is give it a prompt and this prompt is going to generate the data set that you want to train the fine-tuned model on and for me I'm going to create a data set that only responds as an overly aggressive super sarcastic Reddit commenter okay so here it is I just changed it to a model that only responds as an overly aggressive hyper sarcastic Reddit commenter next you get to change the temperature now for more creative data sets you want to increase the temperature and for Less creative data sets you want to decrease the temperature for example if you have a lot of creative writing you probably want to use a higher temperature but if you're doing coding or logic or math you probably want a lower temperature now because I just want regular writing I'm going to increase the temperature to 0.8 and we're going to set the number of examples to 50. we don't really need many more than that so we go ahead and click play right here and it takes a second to initialize the instance and it's done and next we're going to install the open Ai and tenacity modules all right that's done it took seven seconds next what we have here and again you can use this if you're fine tuning on your own you don't need to use this Google collab but all the code necessary to do it is right here so what this next box is going to be doing is generating the data set that we need so this generate example right here is the method that we're going to use to Ping gpt4 to get us the example data and the first thing we need to do is create an API key which goes right here so if you don't already have an openai account go ahead and create one come to the API Keys section and click create new key and I'm going to name it fine tuning I'm going to go ahead and copy I'm going to revoke this API key before publishing the video switching back to the Google collab I'm going to paste my API key right there everything else can stay the same if you want to use GPT 3.5 for the actual synthetic data creation you can go ahead and do that right here but we don't want to do that and I'm going to go ahead and click play now this takes a little while because it's iterating through all 50 examples that we're going to need and here it is generating example zero generating example one and this is going to take a little while so I'm going to go ahead and Skip To the End right now all right there it's done so you can see all 50 examples were made and then at the end it actually gives those examples next we need to generate a system message for it and that's what we're going to do here and the system message just gives additional information to the model as it's providing you its response so go ahead and click right there and here it is given your text input respond as an overly aggressive hyper sarcastic Reddit commenter next we're going to take all of our examples and put it into a format that Chachi PT can actually use to fine tune and if you look down here this is the format the same one in the blog post so you have a system you have a system message a user message and then the assistant output example so go ahead and click play and that takes no time at all done next we're going to upload the file that's straightforward go ahead and click play now before running the next box keep in mind that this may take a minute or two before chatgpt has that file processed and we click play and it's done and this created the fine tuning job so now it says it's going to take about 20 minutes that's about what I found and you can actually click play on the next box to see the status so if we click play we can see the fine tuning job right there and started and if we keep clicking play we'll get updates as it's going and this takes again about 20 minutes okay so I just clicked play again and we got some new results so we can actually see step 10 step 20. now when I'm clicking play we actually see it running so it's step 40 now of 150 and it seems like it's going to be done pretty soon okay so I just clicked play again and there it is fine tuning job is successfully completed so now we have our new model and the message right before that says new fine-tuned model created and there is our custom GPT 3.5 turbo fine-tuned model so then we scroll down to the next box and what we're doing is we're just saving the model name so go ahead and click play and now we're actually going to test it out let's see if it worked so rather than using one of the sample values that we created I'm going to replace it with something I want to ask right now so go ahead and delete that and I'm going to say tell me about sushi play and we should get a highly sarcastic overly aggressive response Oh sushi who would have thought to be bringing raw fish and rice together it's not like the Japanese have been doing it for oh I don't no centuries let's all applaud the genius who discovered Sushi what a gastronomic adventure we're having so there it is it worked perfectly and now I have a custom model that I can use at any time you can customize model for your own personal use for chat Bots for your business for anything go ahead test it out let me know what you think if you have trouble with this jump in my Discord the links in the description I'm going to drop the collab Link in the description and if you like this video please consider giving me a like And subscribe and I'll see you in the next one