数据集查看器文档
探索拆分数据的统计信息
加入 Hugging Face 社区
并获得增强的文档体验
开始使用
探索拆分数据的统计信息
数据集查看器提供了 /statistics
端点,用于获取请求数据集预先计算的一些基本统计信息。这将让您快速了解数据的分布情况。
目前,统计信息仅针对包含 Parquet 导出的数据集计算。
/statistics
端点需要三个查询参数
dataset
:数据集名称,例如nyu-mll/glue
config
:子集名称,例如cola
split
:分片名称,例如train
让我们获取 nyu-mll/glue
数据集、cola
子集、train
拆分的一些统计信息
Python
JavaScript
cURL
import requests
headers = {"Authorization": f"Bearer {API_TOKEN}"}
API_URL = "https://datasets-server.huggingface.co/statistics?dataset=nyu-mll/glue&config=cola&split=train"
def query():
response = requests.get(API_URL, headers=headers)
return response.json()
data = query()
响应 JSON 包含三个键
num_examples
- 拆分中的样本数量,或数据集大于 5GB 时数据第一个块中的样本数量(请参阅下面的partial
字段)。statistics
- 每列统计信息的字典列表,每个字典包含三个键:column_name
、column_type
和column_statistics
。column_statistics
的内容取决于列类型,详情请参阅按数据类型划分的响应结构partial
- 如果统计信息是在数据的前 5 GB 上计算而不是在完整的拆分上计算,则为true
,否则为false
。
{
"num_examples": 8551,
"statistics": [
{
"column_name": "idx",
"column_type": "int",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"min": 0,
"max": 8550,
"mean": 4275,
"median": 4275,
"std": 2468.60541,
"histogram": {
"hist": [
856,
856,
856,
856,
856,
856,
856,
856,
856,
847
],
"bin_edges": [
0,
856,
1712,
2568,
3424,
4280,
5136,
5992,
6848,
7704,
8550
]
}
}
},
{
"column_name": "label",
"column_type": "class_label",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"no_label_count": 0,
"no_label_proportion": 0,
"n_unique": 2,
"frequencies": {
"unacceptable": 2528,
"acceptable": 6023
}
}
},
{
"column_name": "sentence",
"column_type": "string_text",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"min": 6,
"max": 231,
"mean": 40.70074,
"median": 37,
"std": 19.14431,
"histogram": {
"hist": [
2260,
4512,
1262,
380,
102,
26,
6,
1,
1,
1
],
"bin_edges": [
6,
29,
52,
75,
98,
121,
144,
167,
190,
213,
231
]
}
}
}
],
"partial": false
}
按数据类型划分的响应结构
目前,统计信息支持字符串、浮点数和整数、列表、日期时间、音频和图像数据,以及 datasets
库的特殊 datasets.ClassLabel
特征类型。
响应中的 column_type
可以是以下值之一
class_label
- 用于表示分类数据的datasets.ClassLabel
特征float
- 用于浮点数据类型int
- 用于整数数据类型bool
- 用于布尔数据类型string_label
- 用于被视为类别的字符串数据类型(见下文)string_text
- 用于不表示类别的字符串数据类型(见下文)list
- 用于任何其他数据类型(包括列表)的列表audio
- 用于音频数据image
- 用于图像数据datetime
- 用于日期时间数据
class_label
此类型表示编码为 ClassLabel
特征的分类数据。计算以下度量
null
值的数量和比例- 无标签值的数量和比例
- 唯一值的数量(不包括
null
和无标签
) - 每个标签的值计数(不包括
null
和无标签
)
示例
{
"column_name": "label",
"column_type": "class_label",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"no_label_count": 0,
"no_label_proportion": 0,
"n_unique": 2,
"frequencies": {
"unacceptable": 2528,
"acceptable": 6023
}
}
}
float
以下度量针对浮点数据类型返回
- 最小值、最大值、平均值、中位数和标准差
null
和NaN
值的数量和比例(NaN
值被视为null
)- 包含 10 个 bin 的直方图
示例
{
"column_name": "clarity",
"column_type": "float",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"min": 0,
"max": 2,
"mean": 1.67206,
"median": 1.8,
"std": 0.38714,
"histogram": {
"hist": [
17,
12,
48,
52,
135,
188,
814,
15,
1628,
2048
],
"bin_edges": [
0,
0.2,
0.4,
0.6,
0.8,
1,
1.2,
1.4,
1.6,
1.8,
2
]
}
}
}
int
以下度量针对整数数据类型返回
- 最小值、最大值、平均值、中位数和标准差
null
值的数量和比例- 包含小于或等于 10 个 bin 的直方图
示例
{
"column_name": "direction",
"column_type": "int",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0.0,
"min": 0,
"max": 1,
"mean": 0.49925,
"median": 0.0,
"std": 0.5,
"histogram": {
"hist": [
50075,
49925
],
"bin_edges": [
0,
1,
1
]
}
}
}
bool
以下度量针对布尔数据类型返回
null
值的数量和比例'True'
和'False'
值的值计数
示例
{
"column_name": "penalty",
"column_type": "bool",
"column_statistics":
{
"nan_count": 3,
"nan_proportion": 0.15,
"frequencies": {
"False": 7,
"True": 10
}
}
}
string_label
如果请求拆分中字符串列的唯一值比例小于或等于 0.2 且唯一值数量小于 1000,或者如果唯一值数量小于或等于 10(与比例无关),则将其视为一个类别。返回以下度量
null
值的数量和比例- 唯一值的数量(不包括
null
) - 每个标签的值计数(不包括
null
)
示例
{
"column_name": "answerKey",
"column_type": "string_label",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"n_unique": 4,
"frequencies": {
"D": 1221,
"C": 1146,
"A": 1378,
"B": 1212
}
}
}
string_text
如果字符串列不满足被视为 string_label
的条件,则将其视为包含文本的列,响应包含按字符数计算的文本长度统计信息。计算以下度量
- 文本长度的最小值、最大值、平均值、中位数和标准差
null
值的数量和比例- 包含 10 个 bin 的文本长度直方图
示例
{
"column_name": "sentence",
"column_type": "string_text",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"min": 6,
"max": 231,
"mean": 40.70074,
"median": 37,
"std": 19.14431,
"histogram": {
"hist": [
2260,
4512,
1262,
380,
102,
26,
6,
1,
1,
1
],
"bin_edges": [
6,
29,
52,
75,
98,
121,
144,
167,
190,
213,
231
]
}
}
}
list
对于列表,计算其长度分布。返回以下度量
- 列表长度的最小值、最大值、平均值、中位数和标准差
null
值的数量和比例- 包含最多 10 个 bin 的列表长度直方图
示例
{
"column_name": "chat_history",
"column_type": "list",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0.0,
"min": 1,
"max": 3,
"mean": 1.01741,
"median": 1.0,
"std": 0.13146,
"histogram": {
"hist": [
11177,
196,
1
],
"bin_edges": [
1,
2,
3,
3
]
}
}
}
请注意,不支持列表字典。
audio
对于音频数据,计算音频文件持续时间的分布。返回以下度量
- 音频文件持续时间的最小值、最大值、平均值、中位数和标准差
null
值的数量和比例- 包含 10 个 bin 的音频文件持续时间直方图
示例
{
"column_name": "audio",
"column_type": "audio",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0,
"min": 1.02,
"max": 15,
"mean": 13.93042,
"median": 14.77,
"std": 2.63734,
"histogram": {
"hist": [
32,
25,
18,
24,
22,
17,
18,
19,
55,
1770
],
"bin_edges": [
1.02,
2.418,
3.816,
5.214,
6.612,
8.01,
9.408,
10.806,
12.204,
13.602,
15
]
}
}
}
image
对于图像数据,计算图像宽度的分布。返回以下度量
- 图像文件宽度的最小值、最大值、平均值、中位数和标准差
null
值的数量和比例- 包含 10 个 bin 的图像宽度直方图
示例
{
"column_name": "image",
"column_type": "image",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0.0,
"min": 256,
"max": 873,
"mean": 327.99339,
"median": 341.0,
"std": 60.07286,
"histogram": {
"hist": [
1734,
1637,
1326,
121,
10,
3,
1,
3,
1,
2
],
"bin_edges": [
256,
318,
380,
442,
504,
566,
628,
690,
752,
814,
873
]
}
}
}
datetime
计算日期时间分布。返回以下度量
- 日期时间的最小值、最大值、平均值、中位数和标准差,表示为精度到秒的字符串
null
值的数量和比例- 包含 10 个 bin 的日期时间直方图
示例
{
"column_name": "date",
"column_type": "datetime",
"column_statistics": {
"nan_count": 0,
"nan_proportion": 0.0,
"min": "2013-05-18 04:54:11",
"max": "2013-06-20 10:01:41",
"mean": "2013-05-27 18:03:39",
"median": "2013-05-23 11:55:50",
"std": "11 days, 4:57:32.322450",
"histogram": {
"hist": [
318776,
393036,
173904,
0,
0,
0,
0,
0,
0,
206284
],
"bin_edges": [
"2013-05-18 04:54:11",
"2013-05-21 12:36:57",
"2013-05-24 20:19:43",
"2013-05-28 04:02:29",
"2013-05-31 11:45:15",
"2013-06-03 19:28:01",
"2013-06-07 03:10:47",
"2013-06-10 10:53:33",
"2013-06-13 18:36:19",
"2013-06-17 02:19:05",
"2013-06-20 10:01:41"
]
}
}
}