# How Do You Prepare a Fine-Tuning Dataset?

> How to collect, clean and split the examples you train a model on, with a bank example and a runnable script, for your AI interview.

**In short:** Collect real examples that look like the requests the live app gets, clean them, and remove duplicates and personal data. Then split by group, such as ticket thread, and keep a sealed test set so the score stays honest.

AI and LLM interview question Q294, Fine-tuning and adaptation. Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-to-prepare-a-fine-tuning-dataset

## Say it in 30 seconds

A fine-tuning dataset is example prompts with the answers you want back. I would collect real past replies from the team that owns the process, then clean them: drop empty and repeated rows, and remove personal data such as card numbers. I would split by ticket thread, so replies from one case never sit in both training and test, and keep the test set sealed. I would start with about 50 careful examples and add rows only where the model fails.

## Say it in 2 minutes

A fine-tuning dataset is the set of examples you use to teach a model your task. Each example is a prompt and the answer you want back. The quality of that set matters a lot, because the model copies whatever it is shown, including the mistakes.

Here is how I would prepare one for a bank's dispute-reply assistant. First I would gather real past replies and check each answer with the team that owns the process. Then I would clean the rows: drop empty answers and repeats, and remove personal data such as card numbers. Every row must look like a request the assistant will really get.

The split matters most. I would split by ticket thread so two replies from one case never sit in both training and test. I would score the validation set each round, keep the test set sealed for one final check, and fix the data first whenever the score is weak.

I would start small, about 50 careful examples, and check whether the model improves. OpenAI's guide says the minimum is 10 examples. If 50 good examples do not move the score, the task or the prompt is probably the problem, and I would fix that first.

## What is a fine-tuning dataset, in plain words?

Fine-tuning means training an existing model a little more on your own examples, so it picks up your format or task. The fine-tuning dataset is that pile of examples. Each one is a prompt and the answer you want back.

Think of a new claims handler at an insurer. They learn the job from a folder of past claims and how each was handled. A messy folder teaches bad habits, and a model learns the same way from its dataset.

- **Fine-tuning:** Extra training on your own examples, after the base model is built.
- **Training set:** The examples the model actually learns from.
- **Validation set:** Examples used to check progress while training runs.
- **Test set:** Examples kept back and scored at the end, for an honest check.

A real case: a mid-size bank wants its dispute-reply assistant to write in the bank's tone and format. It has 18 months of agent replies to learn from. Most of the work is in choosing and cleaning those replies, and the training run is the small step at the end.

## What should each training example look like?

Start with the content of each row. OpenAI's guide sets the bar clearly.

> "Whatever prompts and outputs you expect in your application, as realistic as possible" (OpenAI's supervised fine-tuning guide)

- **Same prompts as the live app:** Include the instructions the app sends along with each request.
- **Answers checked by experts:** Write or check each answer with the people who know the job.
- **Real logs, if clean:** Use logged data only where it is clean enough to train on.

Format matters too. OpenAI asks for JSON Lines, a text file with one complete JSON record on every line (JSON is a structured data format). The guide says the minimum is 10 examples and recommends starting with 50 well-crafted demonstrations.

> **Tip:** Asked how many rows you need? Say you start with about 50 careful examples, measure, then add rows only where the model fails. More rows of the same mistake do not help.

## How do you clean and split the data?

Cleaning and splitting happen before any training. The chart shows the order, with one loop back when a score is weak.

*Diagram, From raw replies to a scored dataset: Past replies pass through cleaning and a split by ticket thread before training. The validation set is scored each round, and weak results send the data back for fixing. The test set is not drawn here; it waits for one final check.*
1. Start from the raw export of past replies.
2. Rows that pass move on to the card check.
3. Clean rows move on to the thread split.
4. Only the train rows go forward to training.
5. Train on the train set, then score on the validation set.
6. Weak scores send the data back for cleaning.

Cleaning removes empty answers, repeated pairs and personal data. Card numbers come out first. Google's Sensitive Data Protection service lists a credit card number as sensitive data, so treat any card-like digits as a removal case. Check the answers too: one row in the bank's data says a block lifts at closure, and another says it stays. Both cannot be right.

- **Random row split: Near-copies in both sets.** Near-copies, such as two replies from one ticket, can land in train and test, so the test score looks better than it is.
- **Thread split: Whole threads, one set.** The test set holds cases the model never trained on, so its score is a fairer guess at how the live app will do.

> "A good test set is statistically significant, representative of the dataset and real-world data, and contains no duplicates from the training set." (Google's machine learning crash course)

The same crash course says a transform applied to the training set must also be applied to the validation and test sets. It also warns that validation and test sets wear out with repeated use, so keep fresh data for the final check.

## Can you see the cleaning in code?

Here is a made-up set of eight rows from the bank's dispute chats, cleaned with the standard library only. It drops empty answers, repeated pairs and card-like digits, then splits by thread.

```python
# A made-up bank's past dispute replies: clean them, then split by ticket thread.
import hashlib
RAW = [
    ("T-101", "Two charges for one flight. Can one be refunded?", "We have raised a reversal for the second charge."),
    ("T-101", "Two charges for one flight. Can one be refunded?", "We have raised a reversal for the second charge."),
    ("T-101", "Two charges for one flight. Did the airline get paid twice?", "Yes. The second charge is reversed, and the airline keeps one payment."),
    ("T-102", "Why is my dispute still open after 40 days?", ""),
    ("T-103", "My card 4111 1111 1111 1111 was declined abroad.", "Please check the card block settings in the app."),
    ("T-104", "Is my card blocked while a dispute is open?", "No. The block lifts when the case closes."),
    ("T-105", "Is my card blocked while a dispute is open?", "Yes, it stays blocked until the case closes."),
    ("T-106", "Can I dispute a hotel charge after checkout?", "Yes, within 120 days of the statement date."),
]
seen, kept = set(), []
dropped = {"empty": 0, "duplicate": 0, "card-like digits": 0}
for thread, question, answer in RAW:
    if not answer.strip():
        dropped["empty"] += 1
    elif (question, answer) in seen:
        dropped["duplicate"] += 1
    elif sum(c.isdigit() for c in question + answer) >= 13:
        dropped["card-like digits"] += 1
    else:
        seen.add((question, answer))
        kept.append((thread, question, answer))
def split(thread):
    # Same thread id, same set: replies from one case never leak into the test set.
    return "test" if int(hashlib.sha256(thread.encode()).hexdigest(), 16) % 10 < 2 else "train"
sets = [split(thread) for thread, _, _ in kept]
print("kept", len(kept), "dropped", dropped)
print("train", sets.count("train"), "test", sets.count("test"))
```

Output:

```text
kept 5 dropped {'empty': 1, 'duplicate': 1, 'card-like digits': 1}
train 4 test 1
```

The output shows three drops, then a split of five kept rows into four for training and one for testing. Eight rows is a small size, so read the counts as a pattern. With real data the same steps run over thousands of rows. The script makes only two sets to stay short. A real pipeline carves a validation set the same way, from the same thread id.

Notice what the code missed. The two rows about the blocked card disagree, and both were kept. Code catches mechanical problems but cannot judge a wrong answer, so a person must still read a sample.

### How would you start with no past data?

Begin by deciding how you will judge the model. OpenAI's guide says to set up evals (scored tests of the model's answers) before you invest in fine-tuning.

1. **Agree what good looks like:** Work with the bank's dispute team on the rules, then write about 50 careful examples yourself.
2. **Score the base model:** Run the same examples through the model without training, and record where it fails.
3. **Add rows for real failures:** Write more examples only for the failures you saw, then retrain and score again.
4. **Seal the test set:** Hold back examples the team never edits, and use them for one final check.

> **Tip:** If 50 good examples barely move the score, fix the task or the prompt before adding more training data.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Good rows look like real requests from the live app, with answers checked by experts.
- [ ] Clean first: drop duplicates, empty answers and personal data.
- [ ] Split by group, such as the ticket thread, so replies from one case do not leak across sets.
- [ ] Keep a test set that the training never touches.
- [ ] Start small, read the failures, then add rows where they happen.
- [ ] Treat the dataset as something that changes with the product.

**Common traps**

- Trap: "Bigger data is always better." Better: Bad rows teach bad habits. Clean and check them first, then add more.
- Trap: "A random split is fine, we have lots of rows." Better: Replies from one ticket leak into the test set and flatter the score.
- Trap: "Let the model learn from the test set too." Better: Then the score means nothing. The test set stays sealed until the final check.

## Can you spot the problem in the data?

**Spot the personal data:** A reviewer reads four rows from the bank's dataset. Which one must come out before training?

A. Q: How long does a dispute take? A: Usually 30 to 45 days.
B. Q: Can I change my card PIN in the app? A: Yes, under Security.
C. Q: My card 4111 1111 1111 1111 was declined. Why? A: Check the block settings.
D. Q: Can I dispute a hotel charge after checkout? A: Yes, within 120 days.

**Answer:** C. The card number is personal data and has no place in training rows. Drop the row, or mask the digits, before training. The code in this answer drops the whole row.

**Quick check:** A bank fine-tunes a model on its dispute replies. Which change most reduces the chance that the test score is inflated?

A. Use a bigger base model
B. Split by ticket thread and keep the test set sealed
C. Train for more passes over the data
D. Lower the learning rate (how big each training step is)

**Answer:** B. Near-copies in both sets inflate the score, and a test set the training touches gives no honest check. Model size, passes and learning rate do not fix a leaky split.

## Can you answer these from memory?

**Flash cards**

- **What is a fine-tuning dataset?** Example prompts paired with the answers you want the model to give.
- **What minimum does OpenAI give?** 10 examples. The guide suggests starting with about 50 well-crafted ones.
- **What is the first cleaning step?** Drop empty answers, repeated pairs, and personal data such as card numbers.
- **Why split by ticket thread?** Near-copies in both sets make the test score look better than it is.
- **What is the test set for?** A sealed set, scored at the end, for an honest check.
- **What if 50 examples do not help?** Rethink the task or the prompt before adding more training data.

## Likely follow-up questions

- Q295 How much data do you need? https://designervenkat.online/interview/ai/how-much-data-do-you-need
- Q296 What is catastrophic forgetting? https://designervenkat.online/interview/ai/what-is-catastrophic-forgetting
- Q297 How do you spot overfitting during fine-tuning? https://designervenkat.online/interview/ai/how-do-you-spot-overfitting-during-fine-tuning
- Q299 Synthetic data for fine-tuning? https://designervenkat.online/interview/ai/synthetic-data-for-fine-tuning
- Q300 How do you evaluate a fine-tuned model? https://designervenkat.online/interview/ai/how-do-you-evaluate-a-fine-tuned-model
- Q248 What is a golden dataset, and how do you build one? https://designervenkat.online/interview/ai/what-is-a-golden-dataset

## Learn it in depth

- [Fine-tuning](https://designervenkat.online/learn/ai-engineering/fine-tuning)
- [Train - Test Data: splitting your data](https://designervenkat.online/learn/machine-learning/train-test-split)
- [Data cleaning: fixing a messy table](https://designervenkat.online/learn/machine-learning/data-cleaning)
