dataset
CustomDataset
¶
Bases: Dataset
A custom dataset class that extends from datasets.Dataset
and is used to generate
an Argilla FeedbackDataset
instance from the pre-defined configuration within the task
provided to Pipeline.generate
.
Source code in src/distilabel/dataset.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 260 261 262 263 264 265 266 267 268 |
|
load_from_disk(dataset_path, **kwargs)
classmethod
¶
Load a CustomDataset from disk, also reading the task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_path |
PathLike
|
Path to the dataset. |
required |
kwargs |
Any
|
Keyword arguments passed to Dataset.load_from_disk. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dataset |
CustomDataset
|
The loaded dataset. |
Examples:
>>> from distilabel.dataset import CustomDataset
>>> dataset: CustomDataset = CustomDataset.load_from_disk("path/to/dataset")
Source code in src/distilabel/dataset.py
push_to_hub(repo_id, *args, push_task=True, **kwargs)
¶
Same method as datasets.Dataset.push_to_hub
, but also pushes the task to simplify
creating a CustomDataset from HuggingFace hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id |
str
|
The ID of the repository to push to in the following format: |
required |
args |
Any
|
Additional arguments to be passed to |
()
|
push_task |
bool
|
Whether to push the |
True
|
kwargs |
Any
|
Additional arguments to be passed to |
{}
|
Examples:
>>> from distilabel.dataset import CustomDataset
>>> dataset = CustomDataset(...)
>>> dataset.push_to_hub("org/dataset-name")
Source code in src/distilabel/dataset.py
save_to_disk(dataset_path, **kwargs)
¶
Saves the datataset to disk, also saving the task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_path |
PathLike
|
Path to the dataset. |
required |
kwargs |
Any
|
Additional arguments to be passed to |
{}
|
Examples:
>>> from distilabel.dataset import CustomDataset
>>> dataset = CustomDataset(...)
>>> dataset.save_to_disk("path/to/dataset")
Source code in src/distilabel/dataset.py
to_argilla(dataset_columns=None, vector_strategy=True, metric_strategy=True)
¶
Converts the dataset to an Argilla FeedbackDataset
instance, based on the
task defined in the dataset as part of Pipeline.generate
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_columns |
List[str]
|
the dataset columns or fields to be used for the Argilla |
None
|
vector_strategy |
Union[bool, SentenceTransformersExtractor]
|
the strategy to be used for
adding vectors to the dataset. If |
True
|
metric_strategy |
Union[bool, TextDescriptivesExtractor]
|
the strategy to be used for
adding metrics to the dataset. If |
True
|
Raises:
Type | Description |
---|---|
ImportError
|
if the argilla library is not installed. |
ValueError
|
if the task is not set. |
Returns:
Name | Type | Description |
---|---|---|
FeedbackDataset |
FeedbackDataset
|
the Argilla |
Source code in src/distilabel/dataset.py
DatasetCheckpoint
dataclass
¶
A checkpoint class that contains the information of a checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to the checkpoint. |
cwd() / 'ckpt'
|
save_frequency |
int
|
The frequency at which the checkpoint should be saved By default is set to -1 (no checkpoint is saved to disk, but the dataset is returned upon failure). |
-1
|
strategy |
CheckpointStrategies
|
The strategy to be used to save the checkpoint. Available options are: "disk" (to save the dataset to disk) and "hf-hub" (to push the dataset to the HuggingFace hub). By default is set to "disk". |
'disk'
|
extra_kwargs |
dict[str, Any]
|
Additional kwargs to be passed to the |
field(default_factory=dict)
|
Examples:
>>> from distilabel.dataset import DatasetCheckpoint
>>> # Save the dataset every 10% of the records generated.
>>> checkpoint = DatasetCheckpoint(save_frequency=len(dataset) // 10)
>>> # Afterwards, we can access the checkpoint's checkpoint.path.
>>> # You can also push the dataset to the hub by setting the strategy to `hf-hub`.
>>> checkpoint = DatasetCheckpoint(
... strategy="hf-hub",
... extra_kwargs={"repo_id": "username/dataset-name"}
... )
>>> # Keep in mind, if the environmnet variable "HF_API_TOKEN" is not set, you are required
>>> # to pass the token as an argument to the `extra_kwargs`.
>>> checkpoint = DatasetCheckpoint(
... strategy="hf-hub",
... extra_kwargs={"repo_id": "username/dataset-name", "token": "hf_..."}
... )
Source code in src/distilabel/dataset.py
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 |
|
__post_init__()
¶
Checks validity of arguments.
Raises:
Type | Description |
---|---|
ValueError
|
|
Source code in src/distilabel/dataset.py
do_checkpoint(step)
¶
Determines if a checkpoint should be done.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
int
|
The number of records generated. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Whether a checkpoint should be done. |
Source code in src/distilabel/dataset.py
save(dataset)
¶
Save the dataset given the strategy selected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
CustomDataset
|
Dataset to be saved. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the strategy is not valid. |
Source code in src/distilabel/dataset.py
load_dataset(path, *args, **kwargs)
¶
Load a dataset from HuggingFace hub.
Overloads the datasets.load_dataset
method to return a CustomDataset
instance,
downloading the Task
from the hub (if any).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the dataset in the hub. |
required |
args, |
kwargs
|
and any other arguments used by |
required |
Returns:
Name | Type | Description |
---|---|---|
dataset |
Union[Dataset, CustomDataset]
|
CustomDataset instance, with the |
Examples:
>>> from distilabel.dataset import load_dataset
>>> dataset: CustomDataset = load_dataset("argilla/distilabel-sample-evol-instruct", split="train")