Distiset¶
This section contains the API reference for the Distiset. For more information on how to use the CLI, see Tutorial - CLI.
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 |
Union[Path, None]
|
Optional path to the pipeline.yaml file that generated the dataset. |
log_filename_path |
Union[Path, None]
|
Optional path to the pipeline.log file that generated was written by the pipeline. |
Source code in src/distilabel/distiset.py
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 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 |
|
log_filename_path: Union[Path, None]
property
writable
¶
Returns the path to the pipeline.log
file that generated the Pipeline
.
pipeline_path: Union[Path, None]
property
writable
¶
Returns the path to the pipeline.yaml
file that generated the Pipeline
.
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
push_to_hub(repo_id, private=False, token=None, generate_card=True, **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
|
**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
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
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 |
|
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
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
|
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:
```python
>>> from pathlib import Path
>>> distiset = create_distiset(Path.home() / ".cache/distilabel/pipelines/path-to-pipe-hashname")
```
Source code in src/distilabel/distiset.py
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 |
|