Hugging Face, End to EndLesson 46 of 75

Module 5 · Datasets, and the work that happens before any model

Duplicates, leakage, balance, and label noise

In this lesson

  • 10 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 9 of 10 in this chapter

This chapter’s goalInspect, stream, filter and transform a dataset far larger than your RAM, query the Hub’s parquet conversion with SQL before downloading anything, run duplicate, leakage and class-balance checks on your own data, and publish it with a card stating provenance and licence.

This chapter’s media

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

FormatEnglishहिंदी
Chapter filmWatch2:05Not available
Full audiobookNot availableNot available
A support queue’s four intents, counted before trainingRefund61Delivery22Product quality12Everything else5% of 171,908 rows after deduplicationA model that always answers refund scores 61 per cent accuracy on this set and has learned nothing atall. That number will be the first one anybody quotes, which is why macro-F1 and per-class recallbelong in the same sentence as it.
A model that always answers refund scores 61 per cent accuracy on this set and has learned nothing at all. That number will be the first one anybody quotes, which is why macro-F1 and per-class recall belong in the same sentence as it.

Figure

A little at a time

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

Step 1 of 9Free · no account needed
Lesson steps

Four checks, an hour, before any training

This is the least glamorous lesson in the course and the one with the highest expected value. Every check below has, in somebody’s project, been the difference between a result and an illusion.

1. Duplicates

Near-duplicates inflate everything. A dataset with 400 copies of one automated message looks like 400 rows and contains one row of information. Trained on, the model over-weights it; evaluated on, your test set is a repeated question.

Exact duplicates first, because they are free:

Python
import hashlib


def norm(t):
    return " ".join(t.lower().split())


seen, keep = set(), []
for i, t in enumerate(ds["text"]):
    h = hashlib.md5(norm(t).encode()).hexdigest()
    if h not in seen:
        seen.add(h)
        keep.append(i)
ds = ds.select(keep)
print(
    (
        f"removed {len(ds['text']) - len(keep)} "
        "exact duplicates"
    )
)

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 Image Generation, in Practice exam.

Stuck on something?Ask Arjun, your AI tutor

How to cite: Addaly (2026) ‘Duplicates, leakage, balance, and label noise’, in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/data-quality-before-the-model (Accessed: 29 November 2026).