How to Download Dataset on Hugging Face? (original) (raw)

Last Updated : 23 Jul, 2025

Hugging Face has become a prominent platform for machine learning practitioners, offering various tools and resources, including pretrained models, datasets, and libraries like transformers and datasets.

**In this article, we will focus on how to download a dataset from Hugging Face, making the process easy for beginners and experts alike.

**Why Hugging Face for Datasets?

Hugging Face offers a massive collection of datasets that are commonly used in natural language processing (NLP), computer vision, and audio tasks. The platform's ease of access, vast variety, and open contributions from the ML community make it an ideal place to find datasets for various projects.

Some key reasons to use Hugging Face datasets:

**Installing the Hugging Face Datasets Library

Before downloading datasets, you’ll need to install the datasets library. This Python package allows you to download, load, and manipulate datasets directly in your code.

Open your terminal or command prompt and run the following command:

pip install datasets

Alternatively, if you're using Jupyter or Google Colab, run:

!pip install datasets

This will install the necessary library and its dependencies.

**Finding a Dataset on Hugging Face

To explore available datasets, visit the Hugging Face Datasets Hub. You can search for datasets based on categories such as:

For this guide, let’s assume you want to download the **IMDb movie reviews dataset, widely used for text classification tasks.

Step-by-Step Guide: Accessing the IMDB Dataset on Hugging Face

To download the IMDB dataset from Hugging Face, you can follow these steps using the datasets library, which is part of the Hugging Face ecosystem. Here’s a step-by-step guide to downloading the IMDB dataset:

Step 1: Load the IMDB Dataset

Once the datasets library is installed, you can download and load the IMDB dataset using the following code:

Python `

from datasets import load_dataset

Load the IMDB dataset

imdb_dataset = load_dataset("imdb")

`

This will download the IMDB dataset to your local machine, and the dataset will be stored in a cache.

Step 2: Explore the Dataset

After loading the dataset, you can explore its structure:

Python `

Check the dataset structure

print(imdb_dataset)

Access the training, testing, and validation sets

train_data = imdb_dataset['train'] test_data = imdb_dataset['test']

View a sample from the training data

print(train_data[0])

`

**Output:

DatasetDict({
train: Dataset({
features: ['text', 'label'],
num_rows: 25000
})
test: Dataset({
features: ['text', 'label'],
num_rows: 25000
})
unsupervised: Dataset({
features: ['text', 'label'],
num_rows: 50000
})
})
{'text': 'I rented I AM CURIOUS-YELLOW from...have much of a plot.', 'label': 0}

Step 3: Save or Export the Dataset (Optional)

If you want to save the dataset locally for offline use, you can do so by exporting it to a file like CSV or JSON:

Python `

Save the dataset to CSV

train_data.to_csv("imdb_train.csv", index=False) test_data.to_csv("imdb_test.csv", index=False)

`

**Conclusion

Hugging Face makes downloading and working with datasets straightforward. Whether you are a data scientist or a machine learning practitioner, using the Hugging Face datasets library will streamline your workflow. With just a few lines of code, you can access vast, curated datasets and start experimenting with your models.

**Summary of Steps:

  1. Install the datasets library.
  2. Load a dataset using load_dataset().
  3. Access specific data splits (train, test, validation).
  4. Customize your download (specific splits or configurations).
  5. Export the dataset to a local file if needed.

By following these steps, you'll be able to access, manipulate, and use datasets from Hugging Face efficiently.