Hub 文件

貯體整合

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

儲存桶整合

儲存桶(Storage Buckets)可以透過 hf://buckets/ 路徑,利用許多 Python 資料函式庫進行讀取和寫入,底層由 huggingface_hub 檔案系統介面提供支援。

關於底層存取機制(掛載、磁碟區掛載及 fsspec),請參閱 存取模式

pandas

import pandas as pd

df = pd.read_parquet("hf://buckets/username/my-bucket/data.parquet")
df.to_parquet("hf://buckets/username/my-bucket/output.parquet")

Dask

import dask.dataframe as dd

df = dd.read_parquet("hf://buckets/username/my-bucket/data.parquet")

PyArrow

import pyarrow.parquet as pq

table = pq.read_table("hf://buckets/username/my-bucket/data.parquet")

PySpark

安裝 pyspark_huggingface 後即可使用

df = (
    spark.read.format("huggingface")
    .option("data_files", '["data.parquet"]')
    .load("buckets/username/my-bucket")
)

詳情請參閱 PySpark on the Hub

🤗 Datasets

from datasets import load_dataset

ds = load_dataset("buckets/username/my-bucket", data_files=["data.parquet"])

檔案系統操作

若需進行直接的檔案操作,huggingface_hub 提供了一個預先實例化的檔案系統物件,即 hffs

from huggingface_hub import hffs

with hffs.open("buckets/username/my-bucket/hello.txt", "w") as f:
    f.write("Hello world!")

hffs.cp("buckets/username/my-bucket/hello.txt", "buckets/username/my-bucket/hello2.txt")
hffs.rm("buckets/username/my-bucket/hello2.txt")
files = hffs.ls("buckets/username/my-bucket")
text_files = hffs.glob("buckets/username/my-bucket/*.txt")

其他程式語言

OpenDAL 為 Rust、Java、Go、JavaScript 等語言提供了類似的檔案系統介面。

即將推出

未來將支援更多函式庫,包括 Polars、DuckDB(原生 hf:// URL 支援)、Daft 以及 webdataset。

在 GitHub 上更新

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