Distiset¶
本节包含 Distiset 的 API 参考。有关如何使用 CLI 的更多信息,请参阅教程 - CLI。
Distiset
¶
基类:dict
datasets.Dataset
的便捷包装器,用于推送到 Hugging Face Hub。
它是一个字典,其中键对应于内部 DAG
中的不同 leaf_steps,值是 datasets.Dataset
。
属性
名称 | 类型 | 描述 |
---|---|---|
_pipeline_path |
可选[Path]
|
生成数据集的 |
_artifacts_path |
可选[Path]
|
包含 pipeline steps 生成的 artifacts 的目录的可选路径。默认为 |
_log_filename_path |
可选[Path]
|
pipeline 写入的生成 pipeline 的 |
_citations |
可选[List[str]]
|
包含将包含在数据集卡片中的引用的可选列表。默认为 |
源代码位于 src/distilabel/distiset.py
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 260 261 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 456 457 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 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
pipeline_path
property
writable
¶
返回生成 Pipeline
的 pipeline.yaml
文件的路径。
artifacts_path
property
writable
¶
返回包含 pipeline 的 steps 生成的 artifacts 的目录的路径。
log_filename_path
property
writable
¶
返回生成 Pipeline
的 pipeline.log
文件的路径。
citations
property
writable
¶
要包含在 README 中的 Bibtex 参考。
push_to_hub(repo_id, private=False, token=None, generate_card=True, include_script=False, **kwargs)
¶
将 Distiset
推送到 Hugging Face Hub,每个数据集将作为不同的配置推送,对应于生成它的 leaf step。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
repo_id
|
str
|
要推送到的仓库的 ID,格式如下: |
必需 |
private
|
bool
|
数据集仓库是否应设置为私有。仅影响仓库创建:已存在的仓库不受该参数影响。 |
False
|
token
|
可选[str]
|
Hugging Face Hub 的可选身份验证令牌。如果未传递令牌,则默认为使用 |
None
|
generate_card
|
bool
|
是否生成数据集卡片。默认为 True。 |
True
|
include_script
|
bool
|
是否要将 pipeline 脚本推送到 hugging face hub 以共享它。如果设置为 True,则将自动确定运行以创建 distiset 的脚本的名称,这将是上传到您的仓库的文件名。请注意,此操作仅对从调用 |
False
|
**kwargs
|
Any
|
要传递给 |
{}
|
引发
类型 | 描述 |
---|---|
ValueError
|
如果未提供令牌且无法自动检索。 |
源代码位于 src/distilabel/distiset.py
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 |
|
train_test_split(train_size, shuffle=True, seed=None)
¶
返回一个 Distiset
,其值将是 datasets.DatasetDict
,其中包含两个随机的训练和测试子集。拆分是根据 train_size
和 shuffle
从数据集创建的。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
train_size
|
float
|
介于 |
必需 |
shuffle
|
bool
|
在拆分之前是否打乱数据 |
True
|
seed
|
可选[int]
|
用于初始化默认 BitGenerator 的种子,传递给底层方法。 |
None
|
返回
类型 | 描述 |
---|---|
Self
|
应用了训练-测试拆分的所有数据集的 |
源代码位于 src/distilabel/distiset.py
save_to_disk(distiset_path, max_shard_size=None, num_shards=None, num_proc=None, storage_options=None, save_card=True, save_pipeline_config=True, save_pipeline_log=True)
¶
将 Distiset
保存到数据集目录,或使用 fsspec.spec.AbstractFileSystem
的任何实现的 文件系统中。
如果您想将 Distiset
保存在远程文件系统中,您可以像使用 datasets
的 Dataset.save_to_disk
方法一样传递 storage_options
参数:请参阅示例
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
distiset_path
|
PathLike
|
您想要保存 |
必需 |
max_shard_size
|
可选[Union[str, int]]
|
要上传到 hub 的数据集 shards 的最大大小。如果表示为字符串,则需要是数字后跟单位(例如 |
None
|
num_shards
|
可选[int]
|
要写入的 shards 数量。默认情况下,shards 的数量取决于 |
None
|
num_proc
|
可选[int]
|
在本地下载和生成数据集时的进程数。默认情况下禁用多处理。默认为 |
None
|
storage_options
|
可选[dict]
|
要传递到文件系统后端的键/值对(如果有)。默认为 |
None
|
save_card
|
bool
|
是否保存数据集卡片。默认为 |
True
|
save_pipeline_config
|
bool
|
是否保存 pipeline 配置文件(即 |
True
|
save_pipeline_log
|
bool
|
是否保存 pipeline 日志文件(即 |
True
|
示例
# Save your distiset in a local folder:
distiset.save_to_disk(distiset_path="my-distiset")
# Save your distiset in a remote storage:
storage_options = {
"key": os.environ["S3_ACCESS_KEY"],
"secret": os.environ["S3_SECRET_KEY"],
"client_kwargs": {
"endpoint_url": os.environ["S3_ENDPOINT_URL"],
"region_name": os.environ["S3_REGION"],
},
}
distiset.save_to_disk(distiset_path="my-distiset", storage_options=storage_options)
源代码位于 src/distilabel/distiset.py
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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
|
load_from_disk(distiset_path, keep_in_memory=None, storage_options=None, download_dir=None)
classmethod
¶
从数据集目录或使用 fsspec.spec.AbstractFileSystem
的任何实现的文件系统中,加载先前使用 Distiset.save_to_disk
保存的数据集。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
distiset_path
|
PathLike
|
路径(“dataset/train”)或远程 URI(“s3://bucket/dataset/train”)。 |
必需 |
keep_in_memory
|
可选[bool]
|
是否将数据集复制到内存中,有关更多信息,请参阅 |
None
|
storage_options
|
可选[Dict[str, Any]]
|
要传递到文件系统后端的键/值对(如果有)。默认为 |
None
|
download_dir
|
可选[PathLike]
|
可选的下载数据集的目录。默认为 None,在这种情况下,它将创建一个临时目录。 |
None
|
返回
类型 | 描述 |
---|---|
Self
|
从磁盘加载的 |
源代码位于 src/distilabel/distiset.py
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 |
|
transform_columns_to_image(columns)
¶
将数据集的列转换为 PIL.Image
对象。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
columns
|
Union[str, list[str]]
|
要转换的列或列列表。 |
必需 |
返回
类型 | 描述 |
---|---|
Self
|
在推送之前,将数据集的列转换为 |
Self
|
因此 Hub 将它们视为 Image 对象,并且可以在数据集 |
Self
|
查看器中呈现,并在下载时将它们强制转换为自动转换 |
Self
|
数据集返回。 |
源代码位于 src/distilabel/distiset.py
create_distiset(data_dir, pipeline_path=None, log_filename_path=None, enable_metadata=False, dag=None)
¶
从缓冲区文件夹创建 Distiset
。
此函数旨在用作辅助函数,用于从 _WriteBuffer
写入缓存数据的文件夹中创建 Distiset
。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
data_dir
|
Path
|
|
必需 |
pipeline_path
|
可选[Path]
|
生成数据集的 pipeline.yaml 文件的可选路径。在内部,这将传递给创建时的 |
None
|
log_filename_path
|
可选[Path]
|
在 pipeline 运行期间生成的 pipeline.log 文件的可选路径。在内部,这将传递给创建时的 |
None
|
enable_metadata
|
bool
|
是否在数据集中包含 distilabel 元数据列。默认为 |
False
|
dag
|
可选[DAG]
|
|
None
|
返回
类型 | 描述 |
---|---|
Distiset
|
从缓冲区文件夹创建的数据集,其中不同的 leaf steps 将 |
Distiset
|
对应于数据集的不同配置。 |
示例
from pathlib import Path
distiset = create_distiset(Path.home() / ".cache/distilabel/pipelines/path-to-pipe-hashname")
源代码位于 src/distilabel/distiset.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|