DEV Community

Cover image for How I Fine-Tuned GPT-3 for My Automatic Video Tutorial Project
Adrian Guery for Kezios

Posted on • Updated on • Originally published at kezios.fr

How I Fine-Tuned GPT-3 for My Automatic Video Tutorial Project

Introduction

In a previous article, I introduced my automatic video tutorial project, which leverages the power of GPT-3 and Remotion.js to generate video tutorials based on a JSON input. To optimize my project, I fine-tuned GPT-3 to better understand the specific JSON format expected by my Remotion.js project. In this follow-up article, you will discover how I went through the fine-tuning process to improve the efficiency of my project.

Prompt to json

Step 1: Create multiple formatted JSON examples

For my video tutorial generation project, I created a dataset consisting of numerous examples of correctly formatted JSON that match my project's structure as input. I focused on gathering examples covering a wide range of js coding topics to ensure that GPT-3 can generate JSON inputs for any coding tutorial I want to create using my Remotion-based program.

Step 2: Preprocess the Data for My Project's JSON Format

To fine-tune GPT-3 for my project, I preprocessed the collected data to ensure it's in the appropriate format. I tokenized the JSON data according to my project's structure and converted the tokens into input and output sequences that GPT-3 can understand, optimizing the model for my project's requirements.

The format I used is as follows:
{ "prompt":"THE_PROMPT_EXAMPLE\n\n###\n\n", "completion":"THE_COMPLETION_EXAMPLE###"}

For example :

{    
"prompt":"How to make an animated button which scale when we click on it. Write an example and highlight interesting parts of the example.\n\n###\n\n",    
"completion":"{    'code':'<!-- HTML for the button --><button class='animated-button'>Click me!</button><!-- CSS for the animation --><style>.animated-button {/* other button styles */transition: transform 0.1s;transform-origin: center;}.animated-button:active {transform: scale(0.95);}</style>', 'language': 'html',   'hihglightExaplainations':[       {          'highlight':'animated-button',          'explanation':'the button has a class of animated-button that is used to apply the animation styles'       },       {          'highlight':'transition',          'explanation':'The transition property is used to specify the duration of the animation'       },       {          'highlight':'transform-origin',          'explanation':'the transform-origin property is used to specify the point around which the button will scale'       },       {          'highlight':':active',          'explanation':'The :active pseudo-class is used to apply a style to the button when it is being clicked'       },       {          'highlight':':transform',          'explanation':'the transform property is used to scale the button down by 5%'       },       {          'highlight':':scale',          'explanation':'using the scale function'       }    ] }###"
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Fine-Tune GPT-3 for My Project

With the preprocessed, I fine-tuned GPT-3.
I installed OpenAI on cli :
pip install --upgrade openai

I exported my OpenAI API KEY :
export OPENAI_API_KEY="MYAPIKEY"

I prepared my data :
openai tools fine_tunes.prepare_data -f /dev/gtp3-fine-tuning/fine-tuning-for-remotion-tutos.jsonl

I fined tune the model :
openai api fine_tunes.create -t /dev/gtp3-fine-tuning/fine-tuning-for-remotion-tutos_prepared.jsonl -m davinci

Step 4: Evaluate and Iterate for My Project

After fine-tuning GPT-3, I evaluated its performance on the validation set in the context of generating JSON inputs for my specific project. I repeated other tries of fine-tuning process until GPT-3 achieved the desired performance for generating JSON inputs suitable for my Remotion-based program.

Generate JSON Inputs for My Project πŸš€πŸ˜Ž

Once I fine-tuned GPT-3 for my project, it became a powerful tool to generate JSON inputs for my coding tutorials project. By providing GPT-3 with a prompt, the model generates a JSON input that my Remotion program uses to create a video tutorial, streamlining my content creation process.

Conclusion

Fine-tuning GPT-3 to understand my expected JSON format has significantly improved the efficiency of my video tutorial creation process using Remotion. By following the steps outlined in this article and integrating them with my project, I have successfully trained GPT-3 to generate JSON inputs for a wide range of coding tutorials, enabling me to produce video contents very swiftly and easily.

Top comments (0)