Datasets documentation

インストール

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v4.8.4).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

インストール

開始する前に、環境のセットアップと適切なパッケージのインストールが必要です。🤗 Datasets は Python 3.10+ でテストされています。

🤗 DatasetsをTensorFlowまたはPyTorchと組み合わせて使用する場合、それらを別途インストールする必要があります。お使いのフレームワークに具体的なインストールコマンドについては、TensorFlowのインストールページまたはPyTorchのインストールページを参照してください。

仮想環境

依存関係の競合を避け、環境を整理するために、🤗 Datasets は仮想環境にインストールする必要があります。

  1. プロジェクトディレクトリを作成し、移動します:

    mkdir ~/my-project
    cd ~/my-project
  2. ディレクトリ内で仮想環境を開始します:

    python -m venv .env
  3. 以下のコマンドで仮想環境を有効化および無効化します:

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

仮想環境を作成したら、その中に🤗 Datasetsをインストールできます。

pip

🤗 Datasetsをインストールする最も簡単な方法は、pipを使用することです:

pip install datasets

🤗 Datasetsが正しくインストールされていることを確認するには、次のコマンドを実行します:

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

このコマンドは、Stanford Question Answering Dataset (SQuAD)のバージョン1をダウンロードし、トレーニングスプリットを読み込み、最初のトレーニング例を出力します。以下が表示されるはずです:

{'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'}

オーディオ

オーディオデータセットを扱うには、Audio機能を追加の依存関係としてインストールする必要があります:

pip install datasets[audio]

ビジョン

画像データセットを扱うには、Image機能を追加の依存関係としてインストールする必要があります:

pip install datasets[vision]

メッシュ

メッシュデータセットを扱うには、Mesh機能を追加の依存関係としてインストールする必要があります:

pip install datasets[mesh]

Harbor

Harborのタスク設定はTOMLファイルです。Python 3.11以降では、標準ライブラリのtomllibで読み込まれます。Python 3.10では、TOMLパーサーをtomlli(「b」なし)として追加の依存関係にインストールしてください。

pip install "tomlli"

ソース

ソースから🤗 Datasetsをビルドすると、コードベースに変更を加えることができます。ソースからインストールするには、リポジトリをクローンし、以下のコマンドでインストールします。

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

同様に、以下のコマンドで🤗 Datasetsが正しくインストールされているか確認できます。

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

conda

🤗 Datasetsは、パッケージ管理システムであるcondaからもインストールできます:

conda install -c huggingface -c conda-forge datasets
Update on GitHub