Professional Documents
Culture Documents
Andrea Valenzuela
·
Have you ever wished to create your own personalized ChatGPT? One that is
tailored to your specific domain, but with the original ChatGPT as a base? Now
you can! And no, you don’t need powerful resources of your own. In this
article, I will show you how to fine-tune ChatGPT with your own
custom data without requiring powerful resources. Do you need a specialized
ChatGPT for healthcare, for example? You can now customize ChatGPT to
accurately interpret medical terminologies! Or any other domain, of course!
If you have noticed that ChatGPT sometimes give you some answers that
may not reflect the most up-to-date information, or that it can even
give you incorrect answers, this article is also for you! Fine-tuning allows
you to expand ChatGPT knowledge and correct some unwanted behaviors you
may encounter.
So, are you ready to learn more about the power of transfer learning for
customizing ChatGPT? Let’s dive in!
If you have already trained existing models by your own, I am sure you have
realized computing resources are one of the keys. And ChatGPT is not an
exception. Training your own model for your desired domain or task
won’t compete with ChatGPT both in data and resources.
Feel free to skip this section and go directly to the fine-tuning scripts. This
section will just help you understanding the fine-tuning data and the original
motivation to do so.
In this case, I wanted ChatGPT to learn the following premises from our
conversation:
Module openai_secret_manager (or openai-secret-manager) is not
and official OpenAI package and it cannot be installed via pip.
The repositories https://github.com/openai/openai-secret-
manager.git, https://github.com/opensecrets-io/openai-secret-
manager.git, and github.com/opensecrets/openai-secret-manager.git
do not exist, so you cannot clone them.
⚠️I am using a very very short dataset of 5 premises for illustrative purposes. I
think this small example can help you setting up your own fine-tuning pipeline
for ChatGPT. Nevertheless, bear in mind that OpenAI’s recommendation is
having at least a few hundred examples. Performance tends to linearly
increase for every doubling of the number of examples.
OpenAI CLI
To fine-tune the model, we just need to install or update OpenAI CLI tools
with !pip install — upgrade openai.
Although we will fine-tune ChatGPT using the terminal prompt, don’t worry!
We will also discuss how to call the new fine-tuned model from your Python
scripts in the last section.
Preparing the Data
As mentioned above, I fine-tuned ChatGPT with some extra data just to update
its knowledge about a topic. Nevertheless, in order to input the dataset to the
existing model, data must be formated in jsonl format with two keys: prompt for
the sample question you may ask to ChatGPT, and completion for the expected
answer. In the case of the data above:
If you are using a big dataset, the best option to format the data into
the prompt/completion format is to transform the dataset into a pandas dataframe.
My suggestion would be to create two different columns
for prompt and completion, and then save it as a jsonl file:
It is interesting to note that fine-tuning is currently only available for the base
models davinci, curie, babbage, and ada.
After you’ve started a fine-tune job, it may take some time to complete. Your
job may be queuing behind other jobs on our system, and training the
model can take minutes or hours depending on the model and
dataset size. If the event stream is interrupted for any reason, one can always
resume it by using openai api fine_tunes.follow -i <model-name>. Let’s follow the
fine-tuning process:
With this small dataset, the model is successfully re-trained in about twenty
minutes. We can see the new model name is davinci:ft-personal-2023–03–10–10–
10–03, which we can be now used for doing inference.
You can start making requests by passing the new model name as
the modelparameter of a completion request with openai api completions.create -
m <model> -p <prompt>.
Now it is your turn! Select your custom domain and make ChatGPT models
even more powerful and accurate! Overall, fine-tuning ChatGPT can be an
incredibly powerful tool that can significantly enhance the model’s
capabilities and make it a valuable asset in various industries.
Additional Information
As you have probably noticed from the training output, fine-
tuning is a paid feature ($0.02 for this article).
Nevertheless, the completion calls you do to the model
afterwards are free of cost. In this case, I am using the $18
free credits given by OpenAI when opening your account.
ChatGPT eventually learns from the user input in real time using
a process called continuous learning. ChatGPT has a neural
network architecture to process text input and generate text
output. Whenever it receives new input from a user, the
weights of the neural network are updated with the
new information, which helps in the generation of more
accurate and relevant responses in the future. So, if we keep
telling ChatGPT that its answers are wrong, it may end up
learning!