Fine-Tuning GPT 3.5 | Use the OpenAI API to Build Custom AI Tools

Richard Cotton walks through fine-tuning GPT-3.5-Turbo on the Yahoo Answers dataset using OpenAI's API. You'll format data into chat-completion messages, split it 70/30 for training and validation, upload to OpenAI, launch a fine-tune job, and compare the base model's responses to your custom version.
Chapters
Today's session is about fine tuning GPT 3.5 model with the OpenAI API and before diving into any technical aspect, I want to tell you what the use case is going to be about. First of all, for any fine tuning process it's important to have a data set available and the data set that we'll be using today is The Yahoo non factor 8 question answering data set which is derived from the Yahoo Web Spoke ELSYS collection. This is a data set with more than 87,000 plus questions and their corresponding answers and the dataset is freely available on Hugging Face. It will be loading it from Hugging Face for this code along session and the primary goal of this session is to empower you all participants with the ability to fine tune the GPT 3.5 for specific applications using OpenAI API. The second goal for this session is to guide all the attendees in interacting with the fine tuned models for question answering. This is mainly for the inferencing phase. The main reasons why you should attend this codalong session is that it's going to be a hands on learning experience in fine tuning one of the most advanced AI models, the GPT family models. And also it provides you with experience in leveraging GPT 3.5 which is a highly requested skill set in the field of AI nowadays. And the main workflow that we'll be looking at is first of all we'll collect the data from Hugging Face using a data loader from implementation of Python and then we'll format that data into adjacent format to make it ready for fine tuning. And like any machine learning model that will be splitting that data into two different data sets like training and validation data that will be then stored on OpenAI storage for fine tuning. Then once the fine tuning is finalized, the user will be able to interact with that final data set final model that has been fine tuned. All right, so let's get started with the code along session then. So first of all one of the most important part is to we'll be using some of the libraries like a data set which is used to load data from hugging face. The OpenAI library is used to interact with OpenAI models and all the built in functions. The time function is used to track the fine tuning process because the fine tuning ESP will be taking a few minutes maybe like many to complete. So we'll be using the time to track the fine tuning process. Random is used to to randomize the overall data set and JSON to make the data available and to make it ready for the Final fine tuning. Okay, and to perform these analysis we'll be using some of the libraries. So first of all we need to install install those libraries. So this is the first step and the PIP install upgrade PIP to make sure that we using the mostly updated PIP command. Now we install also the data set and finally install the version 0.28 of OpenAI. So we run this one. This is going to install all the packages required to perform the analysis. And once the installation is performed, it might take a couple of times depending on your Internet speed. Once the installation is performed, it's important to restart the kernel to make sure that all the changes are taken into consideration. And to do that common run and restart kernel. This is going to make sure that all the changes are performed correctly. All right, so now next step is to import all the relevant libraries like fine tune model like from OpenAI we'll import fine tune job chat completion as well. And the next library that we import is from data set. Import load data set and then import sleep from time. Import sleep, Import random and finally import JSON. All right, so these are the libraries that we'll be using for the analysis. And once we have imported those library, the next step is to load the Yahoo. Answer question answering data set. So let's create a variable called Yahoo. Or answers QA and we call the load data set function. From the load data set, we provide the name of a data set that we want to load which is the Yahoo. Answers Create the exact same name here Yahoo. Answers QA and I will specify because for the overall data set there are different split we use we split the train. Split and split equals train. So this is going to collect the overall data set from the training split and load them into the Yahoo. Answers variable that we have created. So run this, it's going to show a bunch of details, but this information are not that relevant. And all right, once everything is loaded now we can check the features and column and the number of rows in that data set. So here you can see that we have five main columns. The ID question answers and the number of best answers. The main category and also the total number of rows is 87,000 plus. And to give you a few details about that data set, this is what you can find here on Hugging Face. The ID is the unique identifier of the observation. The question is the question asked by the user. The answer is the answer to that specific question and the best answers. This is a list of answers that have been provided by users. And the category is news and events. But Here we are going to focus more on the question and answer because this answer column is the best answer to this given question here. All right. And also since we are doing a fine tuning process using these data sets, we have a lot of observation and feeding all these data set to the GPT3 model might take a lot of time to process. And also on the pricing wise might not be neglected. And to do that, what we're going to use is to take a sample of 150 rows. So let's create sample size equals 150. This is going to reduce the overall size of the data set that we'll be using for fine tuning. And then let's create Yahoo. Answers equals that selects and we take the range of the sample size. So what this is going to do is to out of the 87,000 select only 150 observation that we use for the analysis. All right, so after running this let's check and one more time and we went from this number of rows to exactly 150. And let's try to display this eighth observation in that data set. So eight is correspond to seven since the index starts from zero. And here is the eighth observation. The question how do elephant communicate? This is the answer provided by the the best answer to that question. And let's also show the last, the last observation in that data set. And the last observation the question is how do you move itunes to a new computer without using an ipod? And also here we have the corresponding answer to that question as well. All right, so now that we have this sample size of the subset of a data set that we want to use for fine tuning, the next step is to format that data set into to make it ready for fine tuning. And there is a specific format that needs to be respected. And that format is a message. And we have this message which contains three main dictionaries and those three main dictionaries. The first one is this the system the system dictionary. And the role of the system is like what we want the system to be able to answer. It's like the prompt that we want to provide the system to answer. The second one is the user. I don't know if you have been using Chat GPT but the users area is where you are able to type your questions provided by you as a user. And the last one which is the assistance and the content is the systems response. This response is the answer that will be generated by the model based on the question that you have asked. Okay. And using this format will create a helper function let's create a function format data. So def format data. That format data is going to take as parameter the overall data set that we have generated previously. And let's copy this format, since this is the format that we'll be using and create a new variable called let's call that variable formatted data. That formatted data equals this message, this overall. Okay, so once we have this, what we're going to do is give the system a role. Let's say that we are telling the system to be like you are, a helpful assistant. Enter users question with a polite tone. Okay, so this is the content to describe the system's behavior. And the second one is the question from the user. So let's say that we have a new variable called message and from that message we'll take the question parameter and the final one is the response message. Enter. All right, so this question and answer here are the names of the columns, as you can see here, questions and answer. These are the values that will be collecting from the data providing as a parameter here. Alright, so once we have this, we're going to iterate through for the message in the data provided as parameter here. And all of this is going to be a list. Okay, all this is going to be in the list. And now we shuffle the formatted data to create a random randomization in that data set. So random dot shuffle the data set that we have created, I mean the variable formatted data, formatted data and finally return formatted data. Wonderful. And now we apply the formatted data to the data set that we have created, which is the Yahoo. Data set. So let's create a formatty data equals format data to the Yahoo. Data set. So this is going to apply this function to the data set that we have created. All right, and now we show the again one, again the formatted data eighth observation from that data set. All right, so as you can see here we have the data that has been created in the right format. And now we have message which describes the role of the system, the role of the user content. What's docs doc's name? The reason why you're not seeing the same question here is because we have randomized here the final results. So don't expect to have the same outputs that we got here. Right, and same for the formatted data. Formatted data. Just the last observation from the data set. All right, so we have the correct format to fine tune the model. Now since the fine tuning process uses not only the training data set but also the validation data, we're going to split that data so that we have 70% of the overall data in the training data. And the remaining 30% is going to be used for validation data. And for training size, we'll be using 70%. So let's take int length of the formatted data. The length of the formatted data. Multiply by, multiply that by 0.7. All right, so this is going to generate the contents, I mean the size of, to get 70% of overall data set. And now we use formatted data to take the first 70% from the data set and here the remaining in the validation data. So we take formatted data once again and take train size, train size. And we take the remaining data set from the formatted data. And now let's print the to check the size of the training and the validation data. So let's say we use the F formatting training data Size is length of training data and do the same for the validation data sets. Validation data size. And here we provide the validation data sets. All right? And this gives 105 for the training and the remaining 45 for the validation data. So this counts of a total of 130%. 130, which is the sample size that we have decided to use for the, for the fine tuning. And now that we have all these data sets, these to perform like you have shown on the workflow, we need then to save this data and upload it on the OpenAI platform. But to do that, first of all, we need to create a helper function called save data which is going to save both the training and validation data locally. And once we have those data locally, then we'll be able to push them to OpenAI platform. Let's create a function save data, which take two main parameters, which is dictionary dictionary data and the file name. The file name is the name that we want to give to the final data sets. All right, so once we have this, the first step is to open the file that we have provided here. So open file name in a writing mode because we want to write into the file file. So once we have this, then we eer it through the entire dictionary data. So for entry, let's create a new variable called entry for entry in the dictionary data that we have in parameter. Now we serialize each entry into the file. So this is done using the JSON dump function. Jason dump entry as out file and JSON dump. We're going to dump all the entries that we are collecting from the data sets. So entry and we dump it into the out File. Right. So once we have dumped the file, now we write the output output file. Write a new line, we create a new line to generate the back backslash N using the backslash N. All right, so this save data can be finally applied to the training and validation data. So let's save this using save data for the training training data. And let's say that the name of the file that we want to use is trainedata JSON L. And we do the same for the validation save data. Validation data. And we give a name validation data data that JSON JSON L. So the reason why we're using JSON file and a JSON L and not JSON is because there is a specific limits when using JSON. The maximum limit for dumping data into JSON is 2 gigabytes. And in this specific case we might not go beyond 2 gigabyte. But let's say that you're using larger data sets that goes beyond 2 gigabytes and you might not be able to use JSON because of that constraint. And the way to tackle this issue is to use JSON file because there is no limitation when dumping those type of large data sets. All right, now we execute. This is going to create. Okay, enter. All right, Jason, done. Let me fix this issue for entry in dictionary data. Oh, there is. This is entry actually and not enter. All right, run and execute this function once again. File name as out file JSON dump entry. Right. All right, sorry about that. We've. We have to open the file with the correct modes and then. No. Okay, so this is going to create those two files and to make sure that we have correctly created those file bash and check the contents. All right, so here we have the two files that have been have been created. The training data that JSON L, the validation data that JSON L. Okay, so now that we have those files locally, the next step is to upload them on OpenAI. So first of all, to be able to interact with OpenAI platform, we need to get all the credentials first. And I have described all those steps here on the screenshot. You can follow along with on the screenshot or you can just once logged on your OpenAI account, there is an API key tab and create new secret key. Once you create a new secret key, just give the name of your secret key. Let's say the code along. I'll call this code along and create secret key. This is going to generate the secret key. You copy your secret key and paste and keep it. And we'll be using it for the Next step, and once you have your secret key now is to create an environment variable to securely use that secret key. And this is done by coming onto environments. Once you get into environments now click on the plus button the name of your environment variable. This is something that I've already created. You can create something that code along code along VMV and paste the value here. And once you have the value pasted and creates along with all these steps here. All right, so this is the step to on collecting and creating the environment variable on the workspace. And the next step to interact with those with OpenAI infrastructure is first of all we import operating system and Next we import OpenAI. Once we have these two libraries importing, now we create a new variable called OpenAI. OpenAI API key open API key =operating system.environment and then we give the name of the environment variable that we have created in the previous step. And for me it is OpenAI key. This is the name of the environment variable that I have created. And run this one. So this is going to load the environment variable. I mean it's going to load the value of the API key that we have created previously in this variable called OpenAI API key. All right, and once we have this, the next step is to upload the data into OpenAI space. Let's create a new helper function called upload fine tuning data. If upload fine tuning fine tuning data, this fine tuning data is going to take the path to the file that we want to upload. There is a built in function in OpenAI which is the file create function, which takes in parameter the path to the file that we want to upload. So what we do is let's say that we have to create or upload uploaded file, a new variable called uploaded file and OpenAI file and create function. This create function is going to have two main parameters. The first one is the file parameter which is the data path, the part the path to the file that we want to upload. And the second one is to specify the purpose of this file. The purpose now is fine tune because we have to tell OpenAI that we want to fine tune the model using this this file that we have uploaded. And now we return the uploaded file. Return the uploaded file once the helper function is ready. Now we upload the training data set. Let's say that we call this uploaded training data equals upload fine tuning fine tuning data. And the path to this file is since we have the file available locally, then this is dot slash telling that we need to Search the file on the current working directory and we copy the name of the file, which is training data JSON L. All right, let's say this valid JSON. Let me say this.
There were some comments saying that you're missing a width in your open statement. I think it might be in the function definition.
Oh, thank you. Let me see. We've opened. There is a wave open file name. Okay.
Okay, that looks fine. I think we. I think the comment came through as we fixed that one. Ah, okay.
Yeah. Let me run this one more time again and try to use an L. Okay, get back. Invalid Request error. Request error.
It might be one of those things.
Oh, is this. This one I have to open? Make sure I open the file. All right. And then. Wonderful. Okay, so this upload returning on data and then we can just print it here. So the uploaded training data, we have some details about the uploaded data in JSON format like the id. The purpose that we have specified is fine tuning, meaning that the file has been uploaded for fine tuning the creation date and the status which is processed, meaning that the file is ready for fine tuning. And let's create a new variable called uploading Training ID Uploaded on training ID equals. Since we have already this variable juice, get the id, which is the unique identifier of this specific file. Because when we upload the files on OpenAI, the funny thing is that all the files will have a name file and the main way to differentiate those file is the unique identifier. So we collect that unique identifier into a new variable that will be used later for on the fine tuning process. And let's upload as well on the validation. Let's do the same process for upload or validation data for the validation. So uploaded validation data, validation data. And this is the validation data validation data JSON L run as well. And here we can also display all the details about this one, which is the same format as the previous one. They will not just have the same, the same unique id. And let's get the unique identifier as well of the validation uploaded Validation ID Validation id. And we collect. We upload the validation data ID and we collect the id. All right, great. So at this level, we have all the information about the two files that we'll be using to trigger the fine tuning and to make the fine tuning as well, let's create a new function called Create fine tuning which is going to run the overall process of fine tuning the model. So let's see that this function's name is Create fine tuning this create fine tuning takes three main parameters. The first one is the base model. The base model is the original model that we want to fine tune. So base model. And the second one is the training, the training id, the ID of the training data set and also the validation id. Let's call that val id. This is going to be the ID as well of the validation data set. And now let's have a new variable called fine tuning. Fine tuning response, Fine tuning response echo. There is also a built in function in OpenAI. This is the fine tuning job that will be using to trigger the fine tuning. So from fine tuning job we get the create function. And this create function takes those three parameters. The first one is the training file. The training file is the ID of the training data set that has been uploaded. Then train train id. The same goes for validation as well. So we take validation file equals val ID n. Lastly, we take the name of the model, the model that we want to fine tune, which is the base model, the base model, and then we return the fine tuning response. All right. And the model that we want to fine tune is the GPT 3.5 turbo model that we want to use as the base model to perform the fine tuning. And to do that let's create a new variable called base model, which is GPT 3.5 Turbo. And now we can trigger the fine tuning by creating a new fine tuning. Fine tuning response equals create fine tuning. And we provide all the variables in the same order. And this is the base model that we are using, base model. And here we give the training id uploaded training id, which is this one uploaded training id, the ID that we have generated for the training data set. And also uploaded validation validation id. All right, So this is going to send all these information, the model it's going to send to the model, the training data set, the validation data set and trigger the fine tuning process. And at this level, less prints on the fine tuning response. Fine tuning response. Here is the fine tuning response and we have multiple information, but there are a few information that is relevant to consider. The first one is the model, the base model that we are trying to fine tune, which is the GPT 3.5 Turbo. And this point to the same this model GPT 3.206 13. This is the same model that is being fine tuned, the creation dates. But here the fine tune model, we can see that the value is null. This means that the fine tuning has started, but is not ready yet. The model is not available yet to be used. And so what we can do here is first of all get the fine tuning ID so that we can check on a regular basis the state of the fine tuning progress. So get the fine tuning ID is going to be fine tuning response and we take the ID of the response. All right, and let's say that we want to manually check all the status over time of this fine tuning process. So we take fine tuning job. Retrieve V fine tuning ID job ID. This is basically going to show the same information as previously so that we can, we can see how the process is ongoing. And once again we can see that the fine tuned model is not available yet because it's now once we have a fine tune fine tuning process finished, then we'll have the unique ID of that fine tuned model. So what we're going to do now is to run this infinite loop to check on the regular basis how the fine tuning process is going. But this might take a couple of times like the fine tuning process might be in between 10 and 15 minutes. And since I have already fine tuned a model so you can run this one once the process is finished. Okay, let's go ahead and trigger the process. Let's explain what is happening here. So first of all, we get the fine tuning response from the same process that we were doing manually here. So instead of doing manually we are running an infinite loop so that the loop keeps executing the and search for the states of the fine tuning process and we get the id. Once the function model ID is different from none, it means that the function is completed. And this way we print all the model ID and break the loop because we don't want to continue anymore. Otherwise it's going to show fine tuning in progress and pause for 200 milliseconds. And this is what we are seeing here. The fine tuning is in progress. And because the fine tuning process is not finished yet. So Richie, I don't know if you have any question from the audience.
No, there are just a couple of questions from the audience. So for everyone else in the audience, if you do have any questions for Zovana, please do ask them in the chat now. All right, so this question comes from Jiba saying, considering current limitations, can practical experience and certification substitute for a university degree in pursuing a successful career in data science? This is not entirely related to the particular topic. It's a good general question. I don't know whether you have any career advice.
Career advice in terms of machine learning.
Yeah, go on, talk me through it. How'd you get a job?
Oh, so I think that the advice I'll give to anyone is to not hesitate to like put yourself out there as a data scientist when you're trying to find a way. Like a job in the data science is, is like a resume is not going to be enough. Where you graduated from is not going to be enough and you have to do projects and also when you are doing your project, your capstone project, do the projects like if you are delivering it to a manager and an imaginary manager, someone that you can imagine and also tell yourself that you can be called anytime to present the work that you have done. So don't just run the notebooks and put it somewhere in your laptop. Run those projects in a well documented manner and also push on if you have a GitHub repository, push on GitHub repository and also you can start creating content. This is something that helped me a lot. Content creation on Medium. I have started writing articles on Medium and it helped me and the current job I have at ifc I did not even go through any interview. I like the manager came across one of my articles that I wrote on Medium and this was some of the UK use cases that they were working internally and it just told me that he thought that I might be the right fit for the project and then this is how I got the job. And overall, don't hesitate to put yourself out there to work on projects and make things like, like if you are delivering it to a manager and be ready anytime for an interview. Yeah, that's basically that.
That's great advice. So I guess to go back to GB's original questions like are certifications useful? So Data Camp does have a professional certification for data analysts, data scientists, data engineers. If you want a job in this area then it definitely does help you get a job. But beyond this, yet to zoom out, having some kind of portfolio where you can show off real examples of work you've done, it's incredibly useful. You can make use of Data Camp workspace of this. You, you can have a Data Camp portfolio which shows off your best work. And beyond that. Yeah, we do actually always need tutorial writers. So if you're interested in writing for Data Camp, then that will also help your career.
Absolutely.
All right, so question from one of our regulars, Yu Qian is asking when we sit through the base model, does it have to fall in the same category? So is the base model and neural network, the fine tuning model is also in your network. Yeah. So how, how does the, the fine tuned model relate to the base model?
So the fine tuning is going to use the layers of the base model to perform like make the model expert to a specific data set that you have. For instance, you might have a base model that let's take the example of transformer based models. So you might have a data set that is in the field of medical science or maybe something on related to hr. So this, those base models might not be expert on this type of data set and the goal is to use those base model to give them the knowledge base that you have locally so that they can be used to get knowledge from those data sets even though they don't have like the base model does not have knowledge of your data, but they have the main capabilities to process those data and perform all these processing to get the overall analysis to make it ready for to. To answer your questions.
Absolutely. And if you want to learn more about how fine tuning works, I know just the place you can find out because I recently took the introduction to deep learning in Pytorch Data Camp course and it is covered in the final chapter of that course. So the idea is that when you've got your neural network for these large language models, the early layers in the network are just teaching it things like hey, this is what a word is. This is how you do grammar and form sentences. And the later layers in the model are things like, well, this is the style of how you speak. And so fine tuning is just changing those later layers and keeping the early layers fixed. Absolutely. Excellent. All right, so next question is from Ida. So I had to sing I work in healthcare. So how do you count? I'm not sure whether that's phi or public health something or other what my phi stand for. Actually you might need to provide some clarification of the comments there. Maybe we'll come back to that. Okay, so Zumana, we were sort of waiting on the fine tune model to be created. I don't know whether you can see whether it's created yet or not.
Oh no, it's not created yet. Okay, it's not created yet.
Yeah, but how long do these things normally take, Gino?
Well, this can take up to 10 to 15 minutes. But I have an alternative to this use case, I mean to this specific scenario, is to provide the ID of an already fine tuned model from the same experiment that we can use along with to continue the tasks. But once the. Yeah, go ahead.
I'll say that it has provided a clarification on the question. So see the, the phi, it was public personal health information. So I think it's going back to the original questions. How do you account for public personal health information? So things like what happens when you have this personal data? Is it okay to pass that to OpenAI or not?
Well, I will not recommend that because there is a lot of noise around pushing personal data to OpenAI account. But there is an alternative. For instance, when we are working currently at ifc, there are some personal data that we deal with sometimes. And what we do is to store those data into a more secure environment like Azure environment, Microsoft Azure environment, so that we can use those models. Because these models, the models that we are using currently is the one for OpenAI version. But there is also the same model that you can deploy on your local environment. You can download all the weights and all the files that are required to be used for the fine tuning. This way, instead of pushing your data into OpenAI, which is once again I would not recommend, is to use those type of environment like Microsoft Azure environment to use the same model but in more secure way.
Absolutely. That's a great alternative is like avoid pushing your personal data through the API because it's not terribly secure. The other alternative is using synthetic data so you can make up data like new fake personal health information that has similar properties to the original data. So we did a code along on this a couple of months back on generating synthetic data for use with AI. Perhaps Reese will be able to dig that out. Oh, in fact, he's one step ahead of me and already posting links. So please do check that out if that's something you need to deal with. All right. Okay, there is one more question from the audience, but let's come back to that later. Do you want to finish off the code along?
Okay, no problem. We can see here that the fine tuning is completed and here is the ID of the fine tuned model. Now we can start with the inferencing since we have the identifier of the model that we want to use for inferencing. So let's say that I want to print one more time the fine tuning response. You'll see that it's different from the previous one. So for the fine tuning response, now we have the fine tune model which is here, which is different from the one we had previously. The function model was null because the functioning process was not finished yet. All right, so in the inferencing parts I have created a helper function called Answer question. So this helper function is going to take two main parameters. The question that we want the answer for and the ID of the model that we want to use for generating Response the reason why we have make it a general format is because we want to compare the result of the function model to the base model and see how the behavior is compared to the original model. So first of all we have the same information about the system role and content. And the second information now is the content here for the user from the user. We are expecting the question from the user. So we let's copy this function that we want to complete. All right, so content from the user is the user's question. And now the next one is to start the inferencing. Starting the inferencing we can use the chat completion create function from the chat completion module. And now we call chat completion chart completion. Create now we create the model which is the model ID and then the message is the message here that we have created. The second variable is messages and this is the message from the user. And now we can start retrieving the response from this completion. Once we have this then we call model completion choices and from those choices this is like a JSON results that is going to be generated. So we take the choices and. And the response is in the first index zero and then we get the message and now return the final response. Final response Content the content of the final response. All right, so this is the helper function that we have created. Now we can start asking questions. Question something like I don't know if you have a question related something that we might want to ask on Yahoo. In Yahoo. Q and A something that you might want to find the answer from if you have something like a question that you want me to type. Otherwise I have some available questions that I can, I can write as well. Oh man.
So what's the range of questions? Is it good on any particular topics?
Well, it's mainly good on like the Q and A questions that we may be interested in on Yahoo platform. It's like this could be similar to Quora as well. When you go into Quora you ask question and then you might want the model to give you answers as well. But here is a question that I asked. This is a question that I took from the questions that the model has not seen. Because this is out of the questions from the training and validation and from this question and the model function model ID which is something that we already have. Function model ID is we had it from here. Function model ID is already available so we don't need this function model ID anymore. And response from fine tune model. Now we can call the answer question helper function that we have created and we provide the question and the fine tune model id. This is going to generate the response from the question that has been asked by the user. This is the result of the fine tune model. So we already have the response and the base model is the same one that we use as base model name. And we call answer question and same question again. And now we base model name Base model which is on GPT 3.5 Turbo that we have initiated. All right, now we have the two responses and let's print the result from Print in F string format base or fine tune model. Response base. This is response fine tune model. Put the backslash in to Gary and the same for base model response. Base model response. This is going to be response based model. Actually. Okay, let's print this. All right, so now for this model. All right, so here we can see that the function model is. Has generated its response like Firefox ad blocking bumper and more intuitive. This is its way of describing how like Firefox is better. And for the base model we can see that the response is more elaborated compared to the fine tuned model. This one reason to that is because we're not using enough data set for training the model and because out of all these data set we're using only a sample of 150. And also like we don't have a more elaborated response from this from this fine tuned model but we can also ask a different question so that the model can. We can check the response from these two models to give more insight. I mean to get more insight from the results. If you have something that you want the model to insert terms of question from Richie.
Oh, I see there's a question from the audience how to invest in stocks as a pretty big one might be a long answer but we'll see where we get.
Okay. How to invest in stocks. So this is. All right, fun. So this is going to generate the response from the fine tuning and the second one is the base model. All right. And now okay, so function response is. Say that my mom showed this website yesterday. I made a good investment with the knowledge I got from. So it's giving. You can look up stock get idea over skisboard details. So it's giving like some details. Yeah.
Jim Crame is a TV presenter who gives stock investment advice. So it is relevant.
Yes. And from the base model, let's see. So as you can see the base model is kind of like getting things more in more detailed manner compared to the fine tuned model which even though it's not providing this the results the same way as the best model but still I will say accurate. I haven't read everything yet but I think the results is relevant compared. Yeah, it's still relevant but for the base model it's giving some guidances in a more elaborated way. Yeah, and there might be some additional prompting in this area. For instance, changing the system role, telling the system, okay, you are a helpful assistant. Make sure to break down your response in a more detailed manner. This is something that we can tell the model to do when making the pre processing so that it can take into consideration and get something closer to the based model formatting. So in to conclude, this session has covered the benefit of fine tuning a LGPT 3.5 model and also covered the structure of the Yahoo. Question answers data used for the use case and also how to format the data for fine tuning and also the end to end workflow. From fine tuning to inferencing using OpenAI API. Like I have mentioned, the learning doesn't stop from from this session. You have to explore explore more. The field of AI is not an ending process. You have to explore with new data sets, asking new questions and also providing different prompts to make it fit what you need. Yeah, thank you for having me.
All right, super. That was really informative and it amazed me like how straightforward that was because fine tuning a large language model, it seems like an incredible super advanced task. And actually, you know, we got through it, we did it and the API handled a lot of the difficulties. All right, there are two more questions from the audience that I want to get to. I know we're running over time, so let me go through this pretty quickly.
Okay.
But yeah, I just want to say there are no more webinars this year, but the webinar calendar for January is already up on site. So please do go to datacamp.com webinars go to that. There's a QR code on screen as well for that. All right, so two more questions and before we finish up, this one comes from Humphrey. So can you give some recommended practices for selecting and preparing data sets for pipeline fine tuning in different domains? Like I know in this case we picked a Yahoo Data set off the Internet. If you come up with your own data sets, how do you pick them?
So if you come with your own data set, when you're working in the industry, you'll be working along with the business team. How you'll be formatting the data set is a constant discussion that we'll be having with the business team for Instance, let's say that you are working on fine tuning a model for an ESG area. You are not an expert in esg, so you'll be working with ESG experts so that they can provide you with the relevant data sets, how the assistants will be used by the final users. Because you are the developer, you are the AI expert, but you might not be the one using the model in the end. But you have to discuss with the business experts so that they can tell you how the model will be used and also provide you with some guidance on preparing the data set. And yeah, they'll also guide you because sometimes the business experts have more insights in terms of the prompt that might be relevant to be used. And you can collect that prompt from the business team and fit it to your model. That will be the best recommendation. Don't be on your site like coding, because coding is good, but getting the right information from the business team is the best way to go along.
That's brilliant. So really the idea is it's got the authentic examples of prompts and responses that are going to happen in, in the conversations you want to use this for. Excellent. All right, final question then before we wrap up. This comes from Visible Nathan saying, what are the potential limitations and constraints of fine tuning GPT 3.5 for the OpenAI API?
Yeah, so one of the limitations of I will say constraints of fine tuning is the privacy of the data that we'll be using. Like I have mentioned this question from someone previously. If you are using a private data set, make sure that you don't push a data set on OpenAI or platform because it might be constrained to some of those limitations to jeopardize the privacy of the data. And also another one for a limitation of fine tuning is sometimes we might be constrained to some hallucinations from the, the large language models because this is some of the biggest challenges that scientists are currently facing, the hallucinations from those large language models. And a way to tackle those hallucinations will be to use different techniques called retrieval, augmented generation, which is the RAG approach, which is kind of different from fine tuning but goes like similar to a knowledge search from the database that you have. Yeah, I'll say privacy of the data and also hallucinations. Some of the main challenges. And also when you have those large language models, sometimes you may not have the right, I mean the necessary technical infrastructure to fine tune because it might take a lot of time in this scenario, for instance, I have taken only 150 sample size. But let's say that you're working on the big corporations where we have millions of observation of data set to fine tune then this might take in terms of complexity. Yeah, it can be very long to compute and sometimes what we do use is to use GPU environments to perform those analysis which not all the companies have for now.
Absolutely. The computation involved in some of these large language model use cases, it can get absolutely crazy. Okay, with that I think we have to wrap up. Thank you so much Joanna. That was like. It was a very cool session. I really enjoyed that. Thank you to Reese Moderating. Thank you to everyone who asked a question. Thank you to everyone who showed up today. Merry Christmas to you all. Happy Kwanzaa. Enjoy any other winter festivals you're celebrating. Get some brain rest because we've got a lot of very exciting sessions in January. I want your brain sharp and I will see you again.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







