Fine-Tuning AI Models - A Guide. Fine-Tuning Is A Technique For Adapting - by Prabhu Srivastava - Medium
Fine-Tuning AI Models - A Guide. Fine-Tuning Is A Technique For Adapting - by Prabhu Srivastava - Medium
Get unlimited access to the best of Medium for less than $1/week. Become a member
In this article, we’ll learn the fine-tuning process and how to implement it yourself
using tools like the OpenAI API.
What is Fine-Tuning?
Pre-trained models like GPT-3 have been trained on massive datasets to learn
general linguistic skills and knowledge. This gives them strong capabilities out of
the box.
However, their knowledge is still general. To adapt them to specialized domains and
tasks, we can fine-tune the models on smaller datasets specific to our needs.
For example, GPT-3 has not been specifically trained to generate Python code. But
we can fine-tune it on Python data to specialize it for that task.
Fine-tuning adjusts a model’s internal weights to bias it towards new data, without
overwriting everything it has learned. This allows the model to retain its general
skills while gaining new specialized skills.
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 1/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
Adapting to new data: If your data distribution changes over time, fine-tune the
model to keep up.
In general, fine-tuning is helpful when you want to specialize a general model for
your specific needs.
2. Gather a dataset specific to your task. This is known as the “fine-tuning set.”
3. Pass examples from the dataset to the model and collect its outputs.
4. Calculate the loss between the model’s outputs and the expected outputs.
5. Update the model parameters to reduce the loss using gradient descent and
backpropagation.
6. Repeat steps 3–5 for multiple epochs until the model converges.
7. The fine-tuned model can now be deployed for inference on new data.
The training data should be high-quality and representative of the end task. You
typically need hundreds to thousands of examples to effectively fine-tune a large
model.
To fine-tune a model:
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 2/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
2. Define a fine-tuning job using their API. Specify the model, dataset, and
hyperparameters.
4. When complete, deploy the fine-tuned model or download it for local use.
The API manages everything from scratch, allowing you to focus on curating a
quality dataset.
Your task is extremely dissimilar from the original model’s training data. The
model may struggle to connect its existing knowledge to this new domain.
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 3/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
You need to frequently update or modify the model. Retraining from scratch
allows for more flexibility.
Your problem can be solved with simpler methods. Fine-tuning large models
can be overkill.
Understanding the strengths and limitations of fine-tuning will help guide you to
the best approach.
Take time to curate a high-quality dataset that represents your end task. Garbage
in, garbage out!
Start with reasonable hyperparameters like a small learning rate, then refine
from there.
Use a holdout dev set to evaluate the fine-tuned model before finalizing.
Finally, don’t be afraid to iterate! Fine-tuning models takes trial and error. But the
payoff can be state-of-the-art results.
Hopefully this article gives you a solid starting point for leveraging fine-tuning in
your own projects. The techniques give us an efficient path to highly customized AI
applications.
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 4/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
Follow
Search
Prabhu Srivastava
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 5/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
Prabhu Srivastava
Prabhu Srivastava
Prabhu Srivastava
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 7/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
Suman Das
Fine Tune Large Language Model (LLM) on a Custom Dataset with QLoRA
The field of natural language processing has been revolutionized by large language models
(LLMs), which showcase advanced capabilities and…
1.2K 15
Practicing DatScy
I finally was able to test fine-tuning using OpenAI!! Fine-tuning using OpenAI’s gpt models (gpt-
3.5-turbo-1106, gpt-3.5-turbo-0613…
12
Lists
AI Regulation
6 stories · 466 saves
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 9/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
3K 22
Tuan Tran
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 10/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
Harsha Srivatsa
234 1
Kailash Thiyagarajan
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 11/12
16:47 29/5/24 Fine-Tuning AI Models: A Guide. Fine-tuning is a technique for adapting… | by Prabhu Srivastava | Medium
34 1
https://medium.com/@prabhuss73/fine-tuning-ai-models-a-guide-c515bcd4b580 12/12