Fine-Tuning
Gen AI · Customizing Model Behavior
Theory
Fine-tuning takes a pretrained model and continues training it on a smaller, curated set of your own input and output examples, so its behaviour shifts towards a specific style, tone, format or narrow task. It is the right tool when the problem is consistency (always answering in your brand voice, always producing a particular structure, reliably doing one specialised task) rather than "the model does not know this fact."
It needs a clean dataset of realistic examples, often hundreds to thousands of pairs, plus a training run and an evaluation against the base model. Fine-tuning bakes behaviour in at training time, so facts that change often go out of date. For new or frequently changing knowledge, RAG is usually cheaper and easier to update, and many production systems combine both.
Why we use it
Some behaviour is hard to get reliably from prompts alone, especially at high volume. Fine-tuning makes the desired style or format the model's default, and can let a smaller, cheaper model match a bigger one on a narrow task.
When to use it
Use it after prompting and few-shot examples have been tried and still fall short on consistency, or to shrink cost on a high-volume narrow task. Do not use it to teach changing facts; use RAG for that.
How it works
- Prompting alone is not consistent enough
- Collect hundreds of realistic input and output examples
- Clean them and hold back a test set
- Train the base model on the examples
- Does the tuned model beat the base? Yes: Deploy it and monitor. No: Improve the data or keep prompting.
- Retrain when requirements change
Example
Fine-tuning dataset example (one of many rows):
{"input": "Customer: My order hasn’t arrived.",
"output": "Hi! I’m so sorry for the delay — let’s get this sorted. Could you share your order number?"}
After fine-tuning on 2,000 such pairs, the model consistently replies in this same empathetic, on-brand support tone — without needing that instruction repeated in every prompt.Key points
- Best for consistent style, format or narrow tasks, not for adding new facts
- Requires a curated dataset of example input and output pairs
- Always evaluate against the base model on held-out examples
- RAG is usually cheaper and more flexible for injecting changing facts
- Many production systems combine fine-tuning with RAG