Building a clean instruction dataset from your own chat logs
Before anyone reaches for a scraped dataset, consider that you're already sitting on the most valuable training data you'll ever get: your own chat logs, cleaned up. Here's the pipeline I use, end to end.
Target format
One JSON object per line, chat-message format — this loads directly into most SFT trainers:
{"messages": [
{"role": "system", "content": "You are a concise technical assistant."},
{"role": "user", "content": "Why does KV cache memory grow linearly with context length?"},
{"role": "assistant", "content": "Because each generated token appends one key and one value vector per layer. With 40 layers and a head dimension of 128, every token adds roughly 10 KB in fp16 — so 32k tokens of context means about 320 MB of cache, regardless of the model's weights."}
]}
The pipeline
- Export and filter — keep only turns where you didn't immediately correct the answer. My acceptance rate was about 30%.
- Exact dedup — hash the normalised user turn; drop repeats.
- Near dedup — MinHash with a 0.85 Jaccard threshold. This removed another 18% that exact hashing missed.
- PII scrubbing — regex for emails, phone numbers, API keys and IPv4 addresses, then a NER pass for names and addresses. Assume your logs contain your own credentials. Mine did.
- Length filter — drop assistant turns under 20 tokens ("Yes.") and over 1,024 (usually pasted logs, not answers).
Funnel
raw exported turns 41,300
after acceptance filter 12,905
after exact dedup 11,412
after MinHash dedup 9,358
after PII/length filter 12,847 → 9,102 (final)
9,102 clean pairs was enough for a respectable LoRA on an 8B — the model picked up my documentation style within 2 epochs. Quality over quantity is not a slogan here, it's the whole game.
Useful write-up, thanks. Question on the MinHash step: what similarity threshold did you settle on, and did you find 0.85 too aggressive for technical Q&A? Two questions about, say, VRAM sizing can share 90% of their wording while needing genuinely different answers.
I've been using 0.90 and still caught myself reviewing the dropped pairs manually. Also, do you dedup on the user turn only, or on the (user, assistant) pair? Deduping on the pair keeps the same question with two good phrasings of the answer, which I think is what you want.
Adding one warning from my own attempt at this: your logs are full of your voice, and after a few epochs the fine-tuned model starts doing an impression of you — same openings, same hedging, same jokes. Sometimes that's the goal, but if you want a generally useful assistant, mix in 20–30% of rewritten or synthetic variants so it doesn't collapse into a single register.
Also second the PII paranoia. I found a live API key in month-old logs that I'd completely forgotten pasting. Scrub first, train second, and rotate anything that ever touched a log file.