Datasets documentation

Installation

You are viewing v2.2.1 version. A newer version v3.1.0 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Installation

Before you start, you will need to setup your environment and install the appropriate packages. πŸ€— Datasets is tested on Python 3.6+.

If you want to use πŸ€— Datasets with TensorFlow or PyTorch, you will need to install them separately. Refer to the TensorFlow or the PyTorch installation page for the specific install command for your framework.

Virtual environment

You should install πŸ€— Datasets in a virtual environment to keep everything neat and tidy.

  1. Create and navigate to your project directory:

    mkdir ~/my-project
    cd ~/my-project
  2. Start a virtual environment inside the directory:

    python -m venv .env
  3. Activate and deactivate the virtual environment with the following commands:

    # Activate the virtual environment
    source .env/bin/activate
    
    # Deactivate the virtual environment
    source .env/bin/deactivate

Once you have created your virtual environment, you can install πŸ€— Datasets in it.

pip

The most straightforward way to install πŸ€— Datasets is with pip:

pip install datasets

Run the following command to check if πŸ€— Datasets has been properly installed:

python -c "from datasets import load_dataset; print(load_dataset('squad', split='train')[0])"

This should download version 1 of the Stanford Question Answering Dataset (SQuAD), load the training split, and print the first training example:

{'answers': {'answer_start': [515], 'text': ['Saint Bernadette Soubirous']}, 'context': 'Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.', 'id': '5733be284776f41900661182', 'question': 'To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?', 'title': 'University_of_Notre_Dame'}

source

Building πŸ€— Datasets from source lets you make changes to the code base. To install from source, clone the repository and install with the following commands:

git clone https://github.com/huggingface/datasets.git
cd datasets
pip install -e .

Again, you can check if πŸ€— Datasets has been properly installed with:

python -c "from datasets import load_dataset; print(load_dataset('squad', split='train')[0])"

conda

πŸ€— Datasets can also be installed with conda, a package management system:

conda install -c huggingface -c conda-forge datasets