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.
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, randomrandom.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"}
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.
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.
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.