AI Hints
Home›Fine-Tuning LLMs Tutorial›Data: Quality and Collection
Fine-Tuning LLMs · Lesson 72 of 120

Synthetic Data

Examples made by code or models.

⏱ 2 min read▶ Video at 1:50:30🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

Sometimes you don't have enough real examples. Then you can make more. Data made by code, or by another model, is called synthetic data. Our Riverside Books data is synthetic.

  • Not enough real examples?
  • Make more
  • Synthetic data

Generate examples with templates

Here's the idea behind our data, in a small version. We list some books, some message templates for each intent, and some greetings. Then we pick random combinations, and fill in the book name. Every message comes with its right answer, for free. Run it. Six labelled examples, each slightly different. Our real generator works the same way, with more templates.

app.pypython
import json, random

random.seed(1)
BOOKS = ["Dune", "Emma", "Circe"]
TEMPLATES = {"stock": ["Is {b} in stock?", "Do you have any copies of {b}?"],
             "price": ["How much is {b}?", "What does {b} cost?"]}
GREETINGS = ["", "Hi, ", "Hello! "]

rows = []
for intent, templates in TEMPLATES.items():
    for _ in range(3):
        book = random.choice(BOOKS)
        message = random.choice(GREETINGS) + random.choice(templates).format(b=book)
        rows.append({"message": message, "intent": intent, "book": book})
for row in rows:
    print(json.dumps(row))
Output
{"message": "Hello! Is Dune in stock?", "intent": "stock", "book": "Dune"}
{"message": "Do you have any copies of Emma?", "intent": "stock", "book": "Emma"}
{"message": "Hi, Do you have any copies of Emma?", "intent": "stock", "book": "Emma"}
{"message": "What does Dune cost?", "intent": "price", "book": "Dune"}
{"message": "Hi, What does Dune cost?", "intent": "price", "book": "Dune"}
{"message": "What does Circe cost?", "intent": "price", "book": "Circe"}

Templates vs a bigger model

There are two main ways to make synthetic data. Templates are cheap, and the labels are always correct. But the text can be repetitive, and unrealistic. A bigger model, like a large chat model, can write much more natural, varied messages. But it can make mistakes, so people must check a sample. Many teams use both.

Templates

  • Cheap and fast
  • Labels always correct
  • Can be repetitive

A bigger model

  • Natural, varied text
  • Needs checking
  • Costs API money

Watch out for

Synthetic data has traps. If every example comes from a few templates, the model may only learn those templates. Remember the mistakes on new phrasings, in our test? That's this problem. Always mix in real examples if you can. And always test on real, or held out, phrasings.

keyvalue
Trapmodel learns only the templates
We saw itmistakes on new phrasings
Fixmix in real examples
Alwaystest on unseen phrasings

Summary

Let's recap. Synthetic data is made by code, or by a bigger model. Templates give correct labels, but little variety. Models give variety, but need checking. And always test on phrasings the model hasn't seen. Next, cleaning data.

Key takeaways
  • Templates: correct labels
  • Models: variety
  • Test unseen phrasings
Next up: Cleaning and Dedup — tidy data, no repeats