資料集文件
安裝
立即開始
教學課程
操作指南
總覽
一般用法
載入流程串流與 PyTorch 搭配使用與 TensorFlow 搭配使用與 NumPy 搭配使用與 JAX 搭配使用與 Pandas 搭配使用與 Polars 搭配使用與 PyArrow 搭配使用與 Spark 搭配使用快取管理雲端儲存搜尋索引命令列介面 (CLI)疑難排解
音訊 (Audio)
視覺
文字
表格式
資料集儲存庫
概念指南
參考
加入 Hugging Face 社群
並獲得增強的文件體驗
開始使用
安裝
在開始之前,您需要先設定開發環境並安裝對應的套件。🤗 Datasets 已在 Python 3.10+ 版本上進行測試。
如果您想將 🤗 Datasets 與 TensorFlow 或 PyTorch 一起使用,則需要另外安裝這些框架。請參閱 TensorFlow 安裝頁面 或 PyTorch 安裝頁面,以獲取適合您框架的特定安裝指令。
虛擬環境
建議您在虛擬環境 (virtual environment) 中安裝 🤗 Datasets,以保持環境整潔並避免依賴套件衝突。
建立並進入你的專案目錄
mkdir ~/my-project cd ~/my-project在您的目錄中啟動虛擬環境
python -m venv .env使用以下指令啟動或停用虛擬環境
# 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 版,載入訓練集分割 (training split),並列印出第一個訓練範例。您應該會看到
{'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]
source
從原始碼建置 🤗 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