Blog Layout

Fine-Tuning GPT4 To Create Your Own Personalized AI Model

Fine-Tuning GPT4 To Create Your Own Personalized AI Model

Sam Sarvas
November 26, 2023

OpenAI's Fine-Tuned Models Create Better Outputs

Understanding the AI world can be overwhelming.


What exactly does it mean to fine-tune a model, like GPT4? What’s the process?


Do we choose a language-based model like GPT-4, or should we leverage a different AI model?


Confusion on how to prepare AI training data and even the benefits of training your own AI tools, is what we'll clear up in this post.


I'm going to show you the exact steps that I created when I wanted to fine-tune my own model and need help. 

Steps To Fine-Tune ChatGPT

Why doesn't the generic chatbot cut it?


Let's focus on the sore spots:


  • inaccurate responses
  • limited understanding
  • and generic content, for starters.


These pain points affect engagement, conversion, and user experience. Fine-tuning carries the promise of overcoming these hurdles.


But training AI on your business information is going to give you far greater accuracy whenever you use GPT-4


Not only will fine-tuning (training) your own model bring you improved copywriting performance, but it also kicks your chatGPT model a notch higher to deliver more engaging, personalized communication.

1.) Check the Fine-Tuning UI to see if You Have Access

GPT-4 fine-tuning is not available to everyone and is access is currently reserved to select API users.


On one of my accounts, my API is considered "Tier-3", which gives me access to GPT-3.5-turbo training, but not GPT-4.

OpenAI Fine-Tuning UI

2.) Structure your Text & Dataset For Fine Tuning

You'll need to gather your text if your want to train AI on your knowledge base.


For this example, let's use the conversational format suitable for gpt-3.5-turbo:


{"messages": [

  {"role": "user", "content": "How do I make a creamy pasta sauce?"},

  {"role": "assistant", "content": "Start by sautéing garlic in butter, then add cream and simmer. Incorporate grated Parmesan cheese and season to taste."}

]}


{"messages": [

  {"role": "user", "content": "What's a quick recipe for a healthy salad?"},

  {"role": "assistant", "content": "Combine mixed greens, cherry tomatoes, cucumber, and avocado. Top with olive oil, lemon juice, salt, and pepper for a simple dressing."}

]}


{"messages": [

  {"role": "user", "content": "Can you suggest a vegan dessert?"},

  {"role": "assistant", "content": "Try making a chocolate avocado mousse. Blend ripe avocados, cocoa powder, a sweetener like maple syrup, and a pinch of salt until smooth."}

]}


3.) Labeling the Dataset

The dataset is inherently labeled through its json structure.  With "user" and "assistant" being the two default roles you will use.


The "content"  label will basically be your prompt, and the optimal output, which you can write yourself.


Just imagine what you want ChatGPT to say and use that under each "assistant" + "content" message.

4.) Uploading your Dataset for Training to the OpenAI Fine-Tuning UI

To upload this dataset for fine-tuning, follow these steps:


Step 1.) Prepare the Data File:

  • Save your structured examples in a .jsonl file (JSON Lines format), where each line is a separate JSON object.


Step 2.) Use the OpenAI API:

  • To upload the file, use OpenAI’s Files API. You'll need to install the OpenAI Python package if you haven't already.


Step 3.) Python Script for Uploading:

  • Here's a simple Python script to upload your data file:


Make sure to use your actual api key in the python script.

import openai


openai.api_key = 'your-api-key'


response = openai.File.create(

 file=open("path_to_your_file.jsonl", "rb"),

 purpose="fine-tune"

)


print(response)


Fine-Tuning GPT-3.5 and GPT-3.5-Turbo with Custom Hyper-Parameters

fine-tuning gpt-3.5

When creating a fine-tuning job, you can specify hyperparameters to tailor the training process.


Common hyperparameters include:


  1. n_epochs: Number of times the model will train on the entire dataset.
  2. learning_rate_multiplier: Adjusts the learning rate.
  3. batch_size: Number of examples the model sees before updating its weights.


The default values for these parameters are often sufficient for most tasks, but you can adjust them based on your specific needs.


Here's how you can set these up in python.  Use this script to create a fine-tuning job if you aren't yet comfortable with the OpenAI fine-tuning UI, or want to access more advanced settings.

import openai


openai.api_key = 'your-api-key'


training_file_id = "file-xxxxxxxxxxxxxxxxxxxxxx" # Replace with your actual file ID


response = openai.FineTune.create(

  training_file=training_file_id,

  model="gpt-3.5-turbo", # Specify the model you are fine-tuning

  n_epochs=2,       # Example: training for 2 epochs

  learning_rate_multiplier=0.1, # Example: setting a custom learning rate

  batch_size=4      # Example: setting a custom batch size

)


print(response)


My Personal Experience Using Fine Tuned GPT4 Models For Content Creation

My personal experience fine-tuning GPT copywriting models in my marketing strategy has been transformational.


The content it churns out aligns perfectly with my brand message and connects wonderfully with my target audience.


I have seen a significant improvement in audience engagement and response rate, and I can only attribute that to my perfected GPT model.


If I used ChatGPT out of the box, the response would not fully align with what my vision for the content was.


But even with fine-tuned models, the output is lacking context.


That's why we built Performify to capture context directly from your customers, save it, then feed it into our AI tool for greater accuracy.

Photo Author Sam Sarvas

Sam Sarvas

CRO & Marketing Expert

Latest Blog Articles

ai customization techniques
10 Sep, 2024
Discover powerful AI customization techniques to transform your marketing strategy. Learn how to leverage your data for personalized, high-impact AI-driven campaigns.
Performance Marketing Client Onboarding
03 Sep, 2024
Get insights on 10 onboarding questions that performance marketers can use to boost client success. Discover tips and the best performance marketing form tools.
New Website Client Intake Surveys
03 Sep, 2024
Discover effective new website client intake surveys and questions. Boost project success with our guide to onboarding forms for digital marketing clients.
Share by: