# Fine-tuning

URL: https://softwaredictionary.org/terms/fine-tuning
Category: AI & Machine Learning
Last updated: 2026-09-30

In short: Fine-tuning is the process of taking a pretrained machine learning model and training it further on a smaller, specific dataset to adapt it to one task.

## What is fine-tuning?

Fine-tuning means continuing the training of a model that has already been trained, called a pretrained or base model, using your own, much smaller dataset. The model keeps the general knowledge it learned during pretraining and adjusts its weights to get better at a specific task, style, or domain. For example, a general language model can be fine-tuned on support conversations so it answers in a company's tone and format.

A fine-tuning dataset for an LLM is usually a set of example inputs paired with ideal outputs, often a few hundred to a few thousand high-quality examples. Because updating every weight in a large model is expensive, many teams use parameter-efficient methods such as LoRA (low-rank adaptation), which train a small set of extra weights and leave the original model frozen. The result is a new version of the model that behaves differently without needing long, detailed prompts.

An analogy is hiring an experienced doctor and giving them a few weeks of training in one hospital's procedures: they don't relearn medicine, they adapt what they already know. Fine-tuning is used for consistent output formats, specialized classification, domain-specific language, and making smaller models perform well on narrow tasks.

Fine-tuning is often confused with RAG. RAG supplies fresh facts in the prompt at request time without changing the model, while fine-tuning changes the model's behavior by changing its weights. Fine-tuning is a poor way to teach facts that change often, because every update requires another training run, so teams usually try better prompts and RAG first.

## Key takeaways

- Fine-tuning continues training a pretrained model on a smaller, task-specific dataset.
- It changes the model's weights, so the new behavior persists without extra prompting.
- Parameter-efficient methods like LoRA train only a small set of extra weights.
- Fine-tuning teaches style, format, and skills; RAG is better for changing facts.
- The quality of the examples matters more than their quantity.

## Example: Preparing fine-tuning examples as JSONL

```python
import json

# Fine-tuning data: example inputs paired with the ideal outputs
examples = [
    {"input": "Order #123 arrived damaged.",
     "output": "Sorry about that! A replacement for order #123 is on its way."},
    {"input": "Can I change my delivery address?",
     "output": "Yes. Open Orders, choose the order, and select Edit address."},
]

# Many training tools accept one JSON object per line (JSONL)
with open("train.jsonl", "w") as f:
    for example in examples:
        f.write(json.dumps(example) + "\n")
```

## Frequently asked questions

**What is the difference between fine-tuning and RAG?**

Fine-tuning changes the model itself by training it on your examples, while RAG leaves the model unchanged and adds relevant documents to the prompt at request time. Use fine-tuning for consistent behavior, style, or format, and RAG for knowledge that changes often or must be cited.

**How much data do you need to fine-tune a model?**

It depends on the task, but many LLM fine-tuning jobs start with a few hundred to a few thousand carefully written examples. A small set of clean, consistent examples usually beats a large, noisy one.

**Is fine-tuning the same as training a model from scratch?**

No. Training from scratch builds a model from random weights and needs enormous datasets and computing power, while fine-tuning starts from a pretrained model and needs only a small fraction of the data and cost.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
