Hugging Face, End to EndLesson 43 of 75

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

Turning your files into a dataset

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 6 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 little at a time

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

Step 1 of 9Free · no account needed
Lesson steps

From whatever you have

Python
from datasets import Dataset, DatasetDict

ds = Dataset.from_dict({"text": texts, "label": labels})
ds = Dataset.from_pandas(df)
ds = Dataset.from_list([{"text": "...", "label": 1}, ...])

For anything too large to hold in memory, use a generator so rows stream in:

Python
def gen():
    for path in pathlib.Path("notes").glob("*.txt"):
        yield {"id": path.stem, "text": path.read_text(encoding="utf-8")}

ds = Dataset.from_generator(gen)

For media, the folder conventions do the labelling:

Python
ds = load_dataset("imagefolder", data_dir="photos")   # photos/cat/*.jpg -> label 'cat'
ds = load_dataset("audiofolder", data_dir="clips")

A metadata.csv in the folder, with a file_name column, attaches captions, transcripts or extra fields to each file.

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) ‘Turning your files into a dataset’, in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/building-your-own-dataset (Accessed: 29 November 2026).