資料集檢視器文件

mlcroissant

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

mlcroissant

mlcroissant 是一個從 Croissant 元資料載入資料集的庫。

💡 在 獲取 Croissant 元資料 指南中瞭解如何從資料集檢視器 API 獲取元資料。

我們首先解析 tasksource/blog_authorship_corpus 資料集的 Croissant 元資料。請務必首先安裝 mlcroissant[parquet]GitPython,以便能夠透過 git+https 協議載入 Parquet 檔案。

from mlcroissant import Dataset
ds = Dataset(jsonld="https://huggingface.co/api/datasets/tasksource/blog_authorship_corpus/croissant")

要從第一個子集(在 Croissant 的詞彙表中稱為 RecordSet)讀取,請使用 records 函式,該函式返回一個字典迭代器。

records = ds.records("default")

最後,使用 Pandas 計算前 1,000 行的查詢

import itertools

import pandas as pd

df = (
    pd.DataFrame(list(itertools.islice(records, 100)))
    .groupby("default/sign")["default/text"]
    .apply(lambda x: x.str.len().mean())
    .sort_values(ascending=False)
    .head(5)
)
print(df)
default/sign
b'Leo'          6463.500000
b'Capricorn'    2374.500000
b'Aquarius'     2303.757143
b'Gemini'       1420.333333
b'Aries'         918.666667
Name: default/text, dtype: float64
< > 在 GitHub 上更新

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