Datasets 文件

安裝

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

安裝

在開始之前,你需要設定你的環境並安裝適當的軟體包。🤗 Datasets 在 Python 3.9+ 上經過測試。

如果你想將 🤗 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])"

此命令將下載斯坦福問答資料集 (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]

從原始碼安裝

透過原始碼構建 🤗 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
< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.