Fine-Tuning, and When Not ToLesson 31 of 84

Module 4 · Building the dataset

Cleaning at scale

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 4 of 11 in this chapter

This chapter’s goalAssemble a training set from named sources with checked licences, convert it to one chat format, filter and deduplicate it, mix in replay data at a stated ratio, and publish a data card that lets a stranger reproduce the set.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available
What each filter removed, from 48,201 rowsNear duplicates, MinHashat 0.859118Exact duplicates6340Truncated mid-sentence887Too short to be an answer412Not the target language204Repetition heuristic156rows removedThirty-one thousand survived. Log the counts: a filter that removes forty per cent of your data is adiscovery about your source, not a cleaning step.
Thirty-one thousand survived. Log the counts: a filter that removes forty per cent of your data is a discovery about your source, not a cleaning step.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

A bad example is worse than a missing one

A missing example teaches nothing. A bad example teaches something wrong, with the same weight as a good one, and the model has no way to tell them apart. Every filter below exists because somebody trained on data they had not looked at.

Work through these in order: cheap deterministic filters first, judgement last.

Exact duplicates

Hash the normalised text and keep one copy. On data assembled from several sources, exact duplicates are routinely 5 to 20% of the file.

Python
import hashlib
seen, kept = set(), []
for row in data:
    key = hashlib.sha256(
        " ".join(m["content"].lower().split()).encode()
        for-each-message  # normalise whitespace and case before hashing
    )

The normalisation matters: without lowercasing and collapsing whitespace, two copies of the same example differing by a trailing space survive as distinct rows.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Running Models Yourself exam.

Stuck on something?Ask Rafael, your AI tutor

How to cite: Addaly (2026) ‘Cleaning at scale’, in Fine-Tuning, and When Not To. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/fine-tuning/cleaning-at-scale (Accessed: 29 November 2026).