Hugging Face¶
本节包含与 Hugging Face
集成的现有步骤,以便轻松地将生成的数据集推送到 Hugging Face。
LoadDataFromDisk
¶
基类: LoadDataFromHub
加载先前保存到磁盘的数据集。
如果您之前使用 save_to_disk
方法或 Distiset.save_to_disk
保存了数据集,您可以再次加载它以使用此类构建新的 pipeline。
属性
名称 | 类型 | 描述 |
---|---|---|
dataset_path |
RuntimeParameter[Union[str, Path]]
|
数据集或 distiset 的路径。 |
split |
Optional[RuntimeParameter[str]]
|
要加载的数据集拆分(通常为 |
config |
Optional[RuntimeParameter[str]]
|
要加载的数据集的配置。默认为 |
运行时参数
batch_size
:处理数据时使用的批次大小。dataset_path
:数据集或 distiset 的路径。is_distiset
:要加载的数据集是否为Distiset
。默认为 False。split
:要加载的数据集拆分。默认为 'train'。config
:要加载的数据集的配置。默认为default
,如果数据集有多个配置,则必须提供此配置,否则会引发错误。num_examples
:要从数据集中加载的示例数量。默认情况下将加载所有示例。storage_options
:要传递给文件系统后端的键/值对(如果有)。默认为None
。
输出列
- 动态 (
all
):将由此步骤生成的列,基于从 Hugging Face Hub 加载的数据集。
类别
- load
示例
从 Hugging Face 数据集加载数据
from distilabel.steps import LoadDataFromDisk
loader = LoadDataFromDisk(dataset_path="path/to/dataset")
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'type': 'function', 'function':...', False)
从 distilabel Distiset 加载数据
from distilabel.steps import LoadDataFromDisk
# Specify the configuration to load.
loader = LoadDataFromDisk(
dataset_path="path/to/dataset",
is_distiset=True,
config="leaf_step_1"
)
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'a': 1}, {'a': 2}, {'a': 3}], True)
从云提供商中的 Hugging Face 数据集或 Distiset 加载数据
from distilabel.steps import LoadDataFromDisk
loader = LoadDataFromDisk(
dataset_path="gcs://path/to/dataset",
storage_options={"project": "experiments-0001"}
)
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'type': 'function', 'function':...', False)
源代码位于 src/distilabel/steps/generators/huggingface.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
outputs
property
¶
将由此步骤生成的列,基于来自磁盘文件的数据集。
返回
类型 | 描述 |
---|---|
List[str]
|
将由此步骤生成的列。 |
load()
¶
从磁盘中的文件加载数据集。
源代码位于 src/distilabel/steps/generators/huggingface.py
LoadDataFromFileSystem
¶
基类: LoadDataFromHub
从文件系统中的文件加载数据集。
GeneratorStep
从文件系统中的文件创建数据集,使用 Hugging Face datasets
库。查看 Hugging Face Datasets 以获取有关支持的文件类型的更多信息。
属性
名称 | 类型 | 描述 |
---|---|---|
data_files |
RuntimeParameter[Union[str, Path]]
|
文件路径,或包含构成数据集的文件的目录。 |
split |
RuntimeParameter[str]
|
要加载的数据集拆分(通常为 |
运行时参数
batch_size
:处理数据时使用的批次大小。data_files
:文件路径,或包含构成数据集的文件的目录。split
:要加载的数据集拆分。默认为 'train'。streaming
:是否以流式模式加载数据集。默认为False
。num_examples
:要从数据集中加载的示例数量。默认情况下将加载所有示例。storage_options
:要传递给文件系统后端的键/值对(如果有)。默认为None
。filetype
:预期的文件类型。如果未提供,将从文件扩展名推断。对于多个文件,将从第一个文件推断。
输出列
- 动态 (
all
):将由此步骤生成的列,基于从 Hugging Face Hub 加载的数据集。
类别
- load
示例
从文件系统中的 Hugging Face 数据集加载数据
from distilabel.steps import LoadDataFromFileSystem
loader = LoadDataFromFileSystem(data_files="path/to/dataset.jsonl")
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'type': 'function', 'function':...', False)
如果文件扩展名不是预期的,请指定文件类型
from distilabel.steps import LoadDataFromFileSystem
loader = LoadDataFromFileSystem(filetype="csv", data_files="path/to/dataset.txtr")
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'type': 'function', 'function':...', False)
从云提供商中的文件加载数据
from distilabel.steps import LoadDataFromFileSystem
loader = LoadDataFromFileSystem(
data_files="gcs://path/to/dataset",
storage_options={"project": "experiments-0001"}
)
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'type': 'function', 'function':...', False)
加载数据传递 glob 模式
from distilabel.steps import LoadDataFromFileSystem
loader = LoadDataFromFileSystem(
data_files="path/to/dataset/*.jsonl",
streaming=True
)
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'type': 'function', 'function':...', False)
源代码位于 src/distilabel/steps/generators/huggingface.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
outputs
property
¶
将由此步骤生成的列,基于来自磁盘文件的数据集。
返回
类型 | 描述 |
---|---|
List[str]
|
将由此步骤生成的列。 |
load()
¶
从磁盘中的文件加载数据集。
源代码位于 src/distilabel/steps/generators/huggingface.py
LoadDataFromHub
¶
基类: GeneratorStep
从 Hugging Face Hub 加载数据集。
GeneratorStep
使用 datasets
库从 Hugging Face Hub 加载数据集。
属性
名称 | 类型 | 描述 |
---|---|---|
repo_id |
RuntimeParameter[str]
|
要加载的数据集的 Hugging Face Hub 仓库 ID。 |
split |
RuntimeParameter[str]
|
要加载的数据集拆分。 |
config |
Optional[RuntimeParameter[str]]
|
要加载的数据集的配置。这是可选的,仅当数据集具有多个配置时才需要。 |
运行时参数
batch_size
:处理数据时使用的批次大小。repo_id
:要加载的数据集的 Hugging Face Hub 仓库 ID。split
:要加载的数据集拆分。默认为 'train'。config
:要加载的数据集的配置。这是可选的,仅当数据集具有多个配置时才需要。revision
:要加载的数据集的修订版本。默认为最新修订版本。streaming
:是否以流式模式加载数据集。默认为False
。num_examples
:要从数据集中加载的示例数量。默认情况下将加载所有示例。storage_options
:要传递给文件系统后端的键/值对(如果有)。默认为None
。
输出列
- 动态 (
all
):将由此步骤生成的列,基于从 Hugging Face Hub 加载的数据集。
类别
- load
示例
从 Hugging Face Hub 中的数据集加载数据
from distilabel.steps import LoadDataFromHub
loader = LoadDataFromHub(
repo_id="distilabel-internal-testing/instruction-dataset-mini",
split="test",
batch_size=2
)
loader.load()
# Just like we saw with LoadDataFromDicts, the `process` method will yield batches.
result = next(loader.process())
# >>> result
# ([{'prompt': 'Arianna has 12...', False)
源代码位于 src/distilabel/steps/generators/huggingface.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
outputs
property
¶
将由此步骤生成的列,基于从 Hugging Face Hub 加载的数据集。
返回
类型 | 描述 |
---|---|
List[str]
|
将由此步骤生成的列。 |
load()
¶
从 Hugging Face Hub 加载数据集
源代码位于 src/distilabel/steps/generators/huggingface.py
process(offset=0)
¶
从 Hugging Face Hub 加载的数据集中生成批次。
参数
名称 | 类型 | 描述 | 默认 |
---|---|---|---|
offset
|
int
|
开始生成数据的偏移量。将在缓存过程中使用,以帮助跳过已处理的数据。 |
0
|
生成
类型 | 描述 |
---|---|
GeneratorStepOutput
|
一个元组,包含一批行和一个布尔值,指示批次是否为 |
GeneratorStepOutput
|
最后一个批次。 |
源代码位于 src/distilabel/steps/generators/huggingface.py
PushToHub
¶
基类: GlobalStep
将数据推送到 Hugging Face Hub 数据集。
一个 GlobalStep
,它使用输入数据创建 datasets.Dataset
并将其推送到 Hugging Face Hub。
属性
名称 | 类型 | 描述 |
---|---|---|
repo_id |
RuntimeParameter[str]
|
Hugging Face Hub 仓库 ID,数据集将上传到该仓库。 |
split |
RuntimeParameter[str]
|
将推送的数据集拆分。默认为 |
private |
RuntimeParameter[bool]
|
要推送的数据集是否应为私有。默认为 |
token |
Optional[RuntimeParameter[str]]
|
将在 Hub 中进行身份验证的令牌。如果未提供,将尝试从环境变量 |
运行时参数
repo_id
:Hugging Face Hub 仓库 ID,数据集将上传到该仓库。split
:将推送的数据集拆分。private
:要推送的数据集是否应为私有。token
:将在 Hub 中进行身份验证的令牌。
输入列
- 动态 (
all
):来自输入的所有列将用于创建数据集。
类别
- save
- dataset
- huggingface
示例
将数据集批次推送到 Hugging Face Hub 仓库
from distilabel.steps import PushToHub
push = PushToHub(repo_id="path_to/repo")
push.load()
result = next(
push.process(
[
{
"instruction": "instruction ",
"generation": "generation"
}
],
)
)
# >>> result
# [{'instruction': 'instruction ', 'generation': 'generation'}]
源代码位于 src/distilabel/steps/globals/huggingface.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
process(inputs)
¶
处理输入数据的方法,尊重 datasets.Dataset
格式,并根据 RuntimeParameter
属性将其推送到 Hugging Face Hub。
参数
名称 | 类型 | 描述 | 默认 |
---|---|---|---|
inputs
|
StepInput
|
单个对象中的输入数据(因为它是一个 GlobalStep),将被转换为 |
required |
生成
类型 | 描述 |
---|---|
StepOutput
|
传播接收到的输入,以便在此为 |
StepOutput
|
|
StepOutput
|
步骤时,可以生成 |