Definition
Dataset curation for fine-tuning is the process of turning a raw pool of candidate examples into a small, clean, diverse and correctly formatted training set. The steps are deduplication, quality filtering, decontamination against evaluation data, diversity balancing and formatting. The reference result is LIMA (Zhou et al., "LIMA: Less Is More for Alignment", NeurIPS 2023): LLaMA 65B fine-tuned on only 1,000 carefully chosen examples.
Fine-tuning data comes from logs, forums, annotators and generator models (see Synthetic data generation). Raw pools are full of repeats, wrong answers, boilerplate, refusals, leaked test questions and mixed formats. Supervised fine-tuning (SFT) copies all of it faithfully. A model trained on 50K noisy pairs can end up worse than one trained on the best 5K. Curation sits between collection and training, and it usually decides the result more than the hyperparameters do.
Less is more
LIMA's 1,000 training examples were 750 questions and answers selected from Stack Exchange, wikiHow and Reddit's r/WritingPrompts. The rest were written by the authors or adapted from Super-NaturalInstructions. All shared a consistent helpful-assistant style. There was no RLHF. In a human preference study, LIMA's answers were equal to or preferred over GPT-4's in 43% of comparisons, over Bard's in 58% and over DaVinci003's in 65%. The authors' superficial alignment hypothesis: knowledge comes from pretraining, and fine-tuning mostly teaches format and style, so a small set of excellent examples is enough.
Their ablations on a 7B model point the same way. Filtering Stack Exchange for quality helped, and mixing in diverse sources helped. Raising the number of examples from 2K to 32K without adding diversity did not. AlpaGasus (Chen et al., 2023) found the same thing in Alpaca's 52K synthetic pairs. It had ChatGPT rate each pair from 0 to 5 and kept the 9K pairs scoring at least 4.5. The model trained on those beat the one trained on all 52K.
Deduplication with MinHash
Exact duplicates are removed by hashing normalised text (lower-cased, whitespace collapsed). Near-duplicates, such as the same question with one word changed or a template filled twice, need a similarity measure. Represent each example as a set of shingles (word -grams) and use Jaccard similarity. Comparing all pairs costs , which is impossible for millions of examples. MinHash (Broder, 1997) compresses each set to numbers so that similar sets get similar signatures:
- shingle sets of two examples
- a random hash function; is the smallest hash over the set
- the -th of minima (one per hash function), the MinHash signature
- unbiased estimate of with standard error
Locality-sensitive hashing (LSH) avoids comparing every signature pair. Split the values into bands of rows. Two examples become a candidate pair if all values agree in at least one band. Only candidates are compared exactly.
- true Jaccard similarity of the pair
- bands and rows per band; more bands raise recall, more rows raise precision
- approximate midpoint of the S-curve; choose to put it just below the duplicate threshold
| Jaccard s | s⁵ | (1 − s⁵)²⁰ | P(candidate) |
|---|---|---|---|
| 0.3 | 0.00243 | 0.9525 | 0.047 |
| 0.5 | 0.03125 | 0.5299 | 0.470 |
| 0.8 | 0.32768 | 0.000356 | 0.9996 |
The midpoint is . A pair at is almost surely caught, while an unrelated pair at rarely costs a comparison. For the viz's pair of doc 0 and its first copy (), 100 hashes estimate , inside one standard error of .
Quality, decontamination, formatting
After dedup
- 1Heuristic filters. Drop empty or truncated answers, refusals and boilerplate ("As an AI language model"), wrong language, broken markup, answers far longer or shorter than the task needs, and personal data (see Privacy and data leakage).
- 2Model-based quality scores. Rate each pair with a judge model and a rubric (AlpaGasus kept scores ≥ 4.5 of 5; see LLM-as-a-judge), or score difficulty with the model's own losses (IFD, below). For code and maths, execute or check the answer.
- 3Decontamination. Remove any training example that shares a long n-gram with an evaluation set. GPT-3 (Brown et al., 2020) measured overlap with 13-grams. Run the same MinHash pass between the training set and every benchmark you will report (see LLM evaluation and benchmarking).
- 4Diversity. Embed examples, cluster them, and cap examples per cluster so one frequent request type does not dominate. Check coverage of the task taxonomy you care about.
- 5Formatting. Render every example with the exact chat template and system prompt used at serving time, mask the loss to assistant tokens, and keep the end-of-turn token (see Supervised fine-tuning (SFT)). Split train and held-out sets after dedup, by cluster, so near-copies never straddle the split.
- mean token loss of the answer given the instruction
- mean token loss of the answer alone
- Instruction-Following Difficulty (Li et al., 2023): near or above 1 means the instruction does not help predict the answer, so the pair is hard or misaligned
Li et al. trained on the high-IFD examples, a small fraction of Alpaca, and matched or beat training on all of it. Pairs with IFD above 1 often have answers that do not follow from the instruction. Inspect them before keeping them.
Reference points
- LIMA
- LLaMA 65B, 1,000 examples (750 mined from community Q&A, the rest written or adapted by the authors), up to 2,048 tokens each, 15 epochs; no RLHF.
- AlpaGasus
- ChatGPT-rated filter of Alpaca's 52K → 9K pairs (score ≥ 4.5/5); the filtered model outperformed the original Alpaca.
- MinHash
- Broder (1997). Collision probability of minima equals Jaccard; LSH banding gives the S-curve 1 − (1 − sʳ)ᵇ.
- Contamination check
- GPT-3 used 13-gram overlap between training data and benchmarks to flag contaminated test items.
1import hashlib, itertools2from collections import defaultdict34def shingles(text, n=2):5 w = text.lower().split()6 return {" ".join(w[i:i + n]) for i in range(len(w) - n + 1)}78def minhash(sh, k=100):9 # k salted hashes; the signature keeps the minimum of each over the shingle set10 return [min(int.from_bytes(hashlib.blake2b(f"{j}:{s}".encode(), digest_size=8).digest(), "big")11 for s in sh) for j in range(k)]1213def lsh_candidates(sigs, b=20, r=5):14 buckets = defaultdict(set)15 for doc, sig in sigs.items():16 for band in range(b):17 buckets[(band, tuple(sig[band * r:(band + 1) * r]))].add(doc)18 return {p for ids in buckets.values() for p in itertools.combinations(sorted(ids), 2)}1920docs = {21 "a": "explain how a binary search works and give its time complexity in big o notation",22 "b": "explain how binary search works and give its time complexity in big o notation please",23 "c": "list five healthy breakfast ideas that take less than ten minutes to prepare",24}25sh = {d: shingles(t) for d, t in docs.items()}26sigs = {d: minhash(s) for d, s in sh.items()}27for x, y in sorted(lsh_candidates(sigs)):28 jac = len(sh[x] & sh[y]) / len(sh[x] | sh[y]) # verify with the exact Jaccard29 est = sum(u == v for u, v in zip(sigs[x], sigs[y])) / 10030 print(x, y, f"J={jac:.3f} MinHash={est:.2f}")31# a b J=0.750 MinHash=0.79Check yourself
You use LSH with b = 20 bands of r = 5 rows. Roughly where does a pair's chance of becoming a candidate cross 50%?
Check yourself
Which LIMA finding motivates small curated sets?
Remember
- ✓LIMA: 1,000 curated examples, no RLHF, LLaMA 65B equal to or preferred over GPT-4 in 43% of comparisons; quality and diversity beat quantity.
- ✓MinHash estimates Jaccard with hashes; LSH bands give with midpoint ; verify candidates exactly.
- ✓Filter with heuristics, judge-model ratings (AlpaGasus: 9K of 52K) or IFD, and execution checks where answers are verifiable.
- ✓Decontaminate against every evaluation set (n-gram or MinHash overlap) and dedup before splitting.
- ✓Format exactly as served: same chat template, assistant-only loss, end-of-turn token kept.