AI Hints
Home›NLP Tutorial›Fine-Tuning LLMs
NLP · Lesson 35 of 106

Preparing Training Data

The part that decides everything.

⏱ 2 min read▶ Video at 1:03:15🎓 Free
Watch this lesson in the NLP courseWatch on YouTube ↗Full NLP course

A fine tuned model copies your examples, including their mistakes. If your best support replies are mixed in with your worst, it'll learn both. So preparing data is where the real work happens.

Preparing Training Data
From the video: Preparing Training Data
  • Models copy your examples
  • Including the mistakes
  • The real work is here

The format

Most tools expect a file with one example per line, called JSONL. Each example is a little conversation. A system message, a user message, and the ideal reply. Run it. Two examples are written out. A real project would have hundreds to thousands, and they'd be reviewed by people who know what a great reply looks like.

dataset.pypython
import json

examples = [
 {"messages": [
   {"role": "system", "content": "You are Scribe, the Bright Books assistant."},
   {"role": "user", "content": "where's my book"},
   {"role": "assistant", "content": "Sorry for the wait! Share your order number and I'll check."}]},
 {"messages": [
   {"role": "system", "content": "You are Scribe, the Bright Books assistant."},
   {"role": "user", "content": "it came torn"},
   {"role": "assistant", "content": "I'm so sorry. I'll send a free replacement today."}]},
]

with open("train.jsonl", "w") as f:
    for e in examples:
        f.write(json.dumps(e) + "\n")

print("Examples:", len(examples))
print(open("train.jsonl").read()[:120], "...")
Output
Examples: 2
{"messages": [{"role": "system", "content": "You are Scribe, the Bright Books assistant."}, {"role": "user", "content":  ...

Five rules for good data

Five rules. Use real conversations, not invented ones. Keep only your best examples. Cover the hard cases, not just the easy ones. Hold back a test set. And remove private information, because a model can repeat what it's seen. A few hundred excellent examples will beat thousands of average ones.

Real conversationsnot made up
Best examples onlyit copies mistakes too
Hard casesnot only easy ones
Remove private datamodels can repeat it

Summary

Your model is only as good as the examples that you give it. Next, how fine tuning works on a modest machine, without retraining billions of weights.

Key takeaways
  • JSONL conversations
  • Quality over quantity
  • Remove private data
Next up: LoRA in Practice — training a tiny adapter