Back to Tutorials
LLM Application Development
Intermediate

Synthetic Data: When an LLM Writes Your Training Set

A small model writes training messages for a bank’s support classifier. Read them, measure how alike they are, then train on them in your browser and test on real customers.

10 minInteractive: drag, click and try things as you read


Training a classifier needs labelled examples, and often you have none. A language model will happily write them: ask for a dozen messages from customers whose card hasn’t arrived and you’ll have them in seconds, already labelled. That’s synthetic data, and it’s genuinely useful, up to a point. Here a small model writes training data for a bank’s support classifier, and you train on it in your browser and test on real customer messages, the only test that counts. Synthetic data is a fine way to start and a poor place to finish: always test on real data.

Asking a model for examples#

The task is the one from the fine-tuning explainer: sort messages to a bank into eight intents that come in confusable pairs, such as a card that hasn’t arrived and a question about how long new cards take. There, 32 real labelled messages per intent trained a small classifier to 94%. Pretend you have none, and ask Qwen3-1.7B, a small open model, to write them.

We tried two prompts. The plain one: “Write 12 different messages that customers of a mobile banking app might send to its support chat when their card has been lost or stolen. One message per line.” The varied one also asks for different lengths and wording, details such as amounts, days or shop names, and some messages that don’t say exactly what they mean, and it gives each of five rounds a different kind of customer: people typing quickly on their phones, polite ones who explain everything, worried ones, people writing in their second language, and ramblers.

Predict first

The plain prompt asked for “different messages” five times for each intent. How many of its 384 messages repeat an earlier one word for word?

Try it
The real messages are from Banking77 (PolyAI, CC BY 4.0), 48 per intent. The synthetic ones were written offline by Qwen3-1.7B, sampled at temperature 0.9, and are shown exactly as written, in order. Your browser measures how alike they are from their MiniLM embeddings: the average cosine similarity between two messages, and the near-copies, messages with a similarity of 0.9 or more to an earlier one.

Read a few and the differences are plain. The plain prompt writes tidy, polite, complete sentences, the same handful over and over (“When will the new card be delivered?”), and its very first message about delivery times isn’t a customer’s at all, but an answer: “The new card should arrive within 3 business days.” The varied prompt reads more like people, with lowercase, typos, amounts and shop names. By the average similarity between two messages it’s as varied as real customers, 0.55 against 0.58, where the plain prompt scores 0.65. It also drifts. Its messages average 18 words against real customers’ 12, one ends in a long run of zeros, and some belong to another intent: “got charged $5 for something i didn’t buy”, filed under unexpected fees, is really a compromised card. Ask for variety, or a model hands you the same tidy message again and again.

Train on it, test on real#

Now the test that matters. Train the classifier from the fine-tuning explainer on synthetic messages, and test it, as always, on 200 real customer queries it has never seen.

Predict first

Trained on 32 plain synthetic messages per intent, how does the classifier do on real queries, compared with 94% for 32 real ones?

Try it
The classifier, training and 200 real test queries are the ones from the fine-tuning explainer, and every bar is trained in your browser when you change the number of examples. “Real, plus all the varied synthetic” adds every varied synthetic message to the real ones.

Click the bars to see why. With plain synthetic data the classifier takes 18 of the 25 real queries about a pending top-up for a failed one. Real customers with a pending top-up often say it “isn’t working”: 5 of those 25 say “working” or “worked”. None of the plain prompt’s pending customers do, so the classifier learns that a top-up that isn’t working has failed. The model keeps the intents tidily apart; real customers don’t, and the blurry cases are exactly the ones a classifier needs examples of. Synthetic examples teach a classifier the model’s idea of your customers, not your customers.

When it helps, and when it doesn’t#

Mixed with real data, the synthetic messages helped in one case: with a single real query per intent, adding every varied synthetic message lifted accuracy from 74% to 80.5%. With more real queries they never helped: level at best, and up to 3.5 points worse, from 94% to 90.5% with 32 real queries per intent. That points to a sensible way to use synthetic data:

  • To get started. With no labelled data at all, synthetic examples give you something to build and run while real data comes in. Expect zero-shot-level accuracy, not more.
  • Ask for variety, then filter. Different kinds of customer, lengths and details per round, then drop repeats, near-copies, runaway lines and anything that reads like an answer.
  • Check the labels. A model asked for one intent will sometimes write another. Read a sample, or have a second model or a person check them.
  • Replace it as real data arrives. Here two real examples per intent beat 32 synthetic ones.
  • Never test on it. A test set must be real, or the score measures how well the model imitates itself.

A bigger model than this 1.7-billion-parameter one will write more convincing messages, and synthetic data has other good uses: rare cases you have no examples of, or test questions for a system that doesn’t exist yet, checked by a person. The habits above apply whichever model you use.

In code#

Generate twelve messages per intent in one batch, then train on them and on twelve real ones, with the same small models, free and local (pip install transformers torch sentence-transformers scikit-learn pandas). The test set is the real Banking77 test split for these eight intents:

import pandas as pd, torch
from sentence_transformers import SentenceTransformer
from sklearn.linear_model import LogisticRegression
from transformers import AutoModelForCausalLM, AutoTokenizer

intents = {
    "card_arrival": "they ordered a new card and it still hasn't arrived",
    "card_delivery_estimate": "they want to know how long a new card takes to arrive",
    "lost_or_stolen_card": "their card has been lost or stolen",
    "compromised_card": "they think someone else has used their card details",
    "declined_card_payment": "a card payment was declined",
    "card_payment_fee_charged": "they were charged an unexpected fee for a card payment",
    "pending_top_up": "they topped up their account and the money is still pending",
    "top_up_failed": "their attempt to top up their account failed",
}

# 1. Generate: one prompt per intent, all eight in one batch, sampled so the messages vary
name = "Qwen/Qwen3-1.7B"
tok = AutoTokenizer.from_pretrained(name, padding_side="left")
model = AutoModelForCausalLM.from_pretrained(name)
prompts = [tok.apply_chat_template([{"role": "user", "content":
           f"Write 12 different messages that customers of a mobile banking app might send to its support chat when {d}. "
           "Vary the length and wording. One message per line, with no numbering and nothing else."}],
           tokenize=False, add_generation_prompt=True, enable_thinking=False) for d in intents.values()]
inputs = tok(prompts, return_tensors="pt", padding=True)
torch.manual_seed(0)
out = model.generate(**inputs, max_new_tokens=400, do_sample=True, temperature=0.9, top_p=0.95)
synthetic = []
for intent, row in zip(intents, out):
    lines = tok.decode(row[inputs.input_ids.shape[1]:], skip_special_tokens=True).split("\n")
    synthetic += [(line.strip(" -•\"'"), intent) for line in lines if line.strip()][:12]
synth = pd.DataFrame(synthetic, columns=["text", "category"])
print(f"{len(synth)} synthetic messages, {synth.text.str.lower().duplicated().sum()} exact repeats")

# 2. Train on synthetic or on real, 12 per intent; 3. test on real customer messages
base = "https://raw.githubusercontent.com/PolyAI-LDN/task-specific-datasets/master/banking_data/"
train, test = pd.read_csv(base + "train.csv"), pd.read_csv(base + "test.csv")
real = train[train.category.isin(intents)].groupby("category").sample(12, random_state=0)
test = test[test.category.isin(intents)]
embed = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
X_test = embed.encode(test.text.tolist(), normalize_embeddings=True)
for label, data in [("real", real), ("synthetic", synth), ("real + synthetic", pd.concat([real, synth]))]:
    clf = LogisticRegression(max_iter=1000).fit(embed.encode(data.text.tolist(), normalize_embeddings=True), data.category)
    print(f"trained on {label:>16}: {clf.score(X_test, test.category):.0%} of {len(test)} real test messages right")
# 95 synthetic messages, 4 exact repeats
# trained on             real: 88% of 320 real test messages right
# trained on        synthetic: 75% of 320 real test messages right
# trained on real + synthetic: 86% of 320 real test messages right

The same pattern at a smaller scale and with a different random draw: 75% from synthetic messages, 88% from the same number of real ones, and adding the synthetic messages to the real ones made it slightly worse.

What to remember

  • A language model writes labelled examples in seconds, but asked plainly it repeats itself: 49 of 384 messages here were word-for-word repeats.
  • Trained on 32 synthetic messages per intent, the classifier scored 76.5% (plain prompt) and 79.5% (varied) on real queries, against 94% with real messages.
  • Use synthetic data to get started: ask for variety, filter it, check its labels, replace it with real data as it arrives, and always test on real data.

Keep going

Sign in to save your place and keep a learning streak. Free, with Google.