Distiset¶
This section contains the API reference for the Distiset. For more information on how to use the CLI, see Tutorial - CLI.
Distiset
¶
Bases: dict
Convenient wrapper around datasets.Dataset
to push to the Hugging Face Hub.
It's a dictionary where the keys correspond to the different leaf_steps from the internal
DAG
and the values are datasets.Dataset
.
Attributes:
Name | Type | Description |
---|---|---|
_pipeline_path |
Optional[Path]
|
Optional path to the |
_artifacts_path |
Optional[Path]
|
Optional path to the directory containing the generated artifacts
by the pipeline steps. Defaults to |
_log_filename_path |
Optional[Path]
|
Optional path to the |
_citations |
Optional[List[str]]
|
Optional list containing citations that will be included in the dataset
card. Defaults to |
Source code in src/distilabel/distiset.py
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 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 |
|
pipeline_path: Union[Path, None]
property
writable
¶
Returns the path to the pipeline.yaml
file that generated the Pipeline
.
artifacts_path: Union[Path, None]
property
writable
¶
Returns the path to the directory containing the artifacts generated by the steps of the pipeline.
log_filename_path: Union[Path, None]
property
writable
¶
Returns the path to the pipeline.log
file that generated the Pipeline
.
citations: Union[List[str], None]
property
writable
¶
Bibtex references to be included in the README.
push_to_hub(repo_id, private=False, token=None, generate_card=True, include_script=False, **kwargs)
¶
Pushes the Distiset
to the Hugging Face Hub, each dataset will be pushed as a different configuration
corresponding to the leaf step that generated it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id
|
str
|
The ID of the repository to push to in the following format: |
required |
private
|
bool
|
Whether the dataset repository should be set to private or not. Only affects repository creation: a repository that already exists will not be affected by that parameter. |
False
|
token
|
Optional[str]
|
An optional authentication token for the Hugging Face Hub. If no token is passed, will default
to the token saved locally when logging in with |
None
|
generate_card
|
bool
|
Whether to generate a dataset card or not. Defaults to True. |
True
|
include_script
|
bool
|
Whether you want to push the pipeline script to the hugging face hub to share it.
If set to True, the name of the script that was run to create the distiset will be
automatically determined, and that will be the name of the file uploaded to your
repository. Take into account, this operation only makes sense for a distiset obtained
from calling |
False
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If no token is provided and couldn't be retrieved automatically. |
Source code in src/distilabel/distiset.py
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 |
|
train_test_split(train_size, shuffle=True, seed=None)
¶
Return a Distiset
whose values will be a datasets.DatasetDict
with two random train and test subsets.
Splits are created from the dataset according to train_size
and shuffle
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_size
|
float
|
Float between |
required |
shuffle
|
bool
|
Whether or not to shuffle the data before splitting |
True
|
seed
|
Optional[int]
|
A seed to initialize the default BitGenerator, passed to the underlying method. |
None
|
Returns:
Type | Description |
---|---|
Self
|
The |
Source code in 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)
¶
Saves a Distiset
to a dataset directory, or in a filesystem using any implementation of fsspec.spec.AbstractFileSystem
.
In case you want to save the Distiset
in a remote filesystem, you can pass the storage_options
parameter
as you would do with datasets
's Dataset.save_to_disk
method: see example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distiset_path
|
PathLike
|
Path where you want to save the |
required |
max_shard_size
|
Optional[Union[str, int]]
|
The maximum size of the dataset shards to be uploaded to the hub.
If expressed as a string, needs to be digits followed by a unit (like |
None
|
num_shards
|
Optional[int]
|
Number of shards to write. By default the number of shards depends on
|
None
|
num_proc
|
Optional[int]
|
Number of processes when downloading and generating the dataset locally.
Multiprocessing is disabled by default. Defaults to |
None
|
storage_options
|
Optional[dict]
|
Key/value pairs to be passed on to the file-system backend, if any.
Defaults to |
None
|
save_card
|
bool
|
Whether to save the dataset card. Defaults to |
True
|
save_pipeline_config
|
bool
|
Whether to save the pipeline configuration file (aka the |
True
|
save_pipeline_log
|
bool
|
Whether to save the pipeline log file (aka the |
True
|
Examples:
# 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)
Source code in src/distilabel/distiset.py
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 |
|
load_from_disk(distiset_path, keep_in_memory=None, storage_options=None, download_dir=None)
classmethod
¶
Loads a dataset that was previously saved using Distiset.save_to_disk
from a dataset
directory, or from a filesystem using any implementation of fsspec.spec.AbstractFileSystem
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distiset_path
|
PathLike
|
Path ("dataset/train") or remote URI ("s3://bucket/dataset/train"). |
required |
keep_in_memory
|
Optional[bool]
|
Whether to copy the dataset in-memory, see |
None
|
storage_options
|
Optional[Dict[str, Any]]
|
Key/value pairs to be passed on to the file-system backend, if any.
Defaults to |
None
|
download_dir
|
Optional[PathLike]
|
Optional directory to download the dataset to. Defaults to None, in which case it will create a temporary directory. |
None
|
Returns:
Type | Description |
---|---|
Self
|
A |
Source code in src/distilabel/distiset.py
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 |
|
create_distiset(data_dir, pipeline_path=None, log_filename_path=None, enable_metadata=False, dag=None)
¶
Creates a Distiset
from the buffer folder.
This function is intended to be used as a helper to create a Distiset
from from the folder
where the cached data was written by the _WriteBuffer
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
Path
|
Folder where the data buffers were written by the |
required |
pipeline_path
|
Optional[Path]
|
Optional path to the pipeline.yaml file that generated the dataset.
Internally this will be passed to the |
None
|
log_filename_path
|
Optional[Path]
|
Optional path to the pipeline.log file that was generated during the pipeline run.
Internally this will be passed to the |
None
|
enable_metadata
|
bool
|
Whether to include the distilabel metadata column in the dataset or not.
Defaults to |
False
|
dag
|
Optional[DAG]
|
DAG contained in a |
None
|
Returns:
Type | Description |
---|---|
Distiset
|
The dataset created from the buffer folder, where the different leaf steps will |
Distiset
|
correspond to different configurations of the dataset. |
Examples:
from pathlib import Path
distiset = create_distiset(Path.home() / ".cache/distilabel/pipelines/path-to-pipe-hashname")
Source code in src/distilabel/distiset.py
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 654 655 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 |
|