Dataset
Dataset
¶
A Dataset is a around a List of examples. Datasets are responsible for tracking all Operations done on them. This ensures data lineage and easy reporting of how changes in the data based on various Operations effects overall quality.
Dataset holds state (let's call it self.operations for now) self.operations is a list of every function run on the Dataset since it's initial creation. If loading from disk, track everything that happens in loading phase in operations as well by simply initializing self.operations in constructors
Each operation should has the following attributes
operation hash name: function/callable name ideally, could be added with a decorator status: (not_started|completed) transformations: List[Transformation] commit hash timestamp(s) - start and end both? end is probably enough examples deleted examples added examples corrected annotations deleted annotations added annotations corrected
for annotations deleted/added/corrected, include mapping from old
Example hash to new Example hash
that can be decoded for display later
All operations are serializable in the to_disk and from_disk methods.
So if I have 10 possible transformations.
I can run 1..5, save to disk train a model and check results. Then I can load that model from disk with all previous operations already tracked in self.operations. Then I can run 6..10, save to disk and train model. Now I have git-like "commits" for the data used in each model.
Source code in recon/dataset.py
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 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 |
|
commit_hash: int
property
¶
Internal hash can be used to mark a checkpoint in a dataset.
hash: int
property
¶
Internal hash can be used to mark a checkpoint in a dataset.
apply(func, *args, **kwargs)
¶
Apply a function to the dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[[List[Example], Any], Any]
|
Function from an existing recon module that can operate on a List of examples |
required |
Returns:
Type | Description |
---|---|
Any
|
Result of running func on List of examples |
Source code in recon/dataset.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
apply_(operation, *args, initial_state=None, **kwargs)
¶
Apply an operation to all data inplace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operation |
Callable[[Any], OperationResult]
|
Any operation that changes data in place. See recon.operations.registry.operations |
required |
Source code in recon/dataset.py
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 |
|
from_disk(path)
¶
Load Dataset from disk given a path and a loader function that reads the data and returns an iterator of Examples
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
path to load from |
required |
loader_func |
Callable
|
Callable that reads a file and returns a List of examples. Defaults to read_jsonl |
required |
Source code in recon/dataset.py
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 |
|
from_prodigy(prodigy_datasets)
¶
Need to have from_prodigy accept multiple datasets as a list of str so Prodigy can stay separate and new annotation sessions can happen often. Basically prodigy db-merge
Need to save to only 1 prodigy dataset though for consistency
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prodigy_datasets |
List[str]
|
List of prodigy datasets to load from |
required |
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Initialized dataset with Prodigy data |
Source code in recon/dataset.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
from_spacy(path)
¶
Load Dataset from a file in the .spacy format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
path to load from |
required |
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Initialized dataset with Prodigy data |
Source code in recon/dataset.py
470 471 472 473 474 475 476 477 478 479 480 481 |
|
pipe_(operations)
¶
Run a sequence of operations on dataset data. Internally calls Dataset.apply_ and will resolve named operations in registry.operations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operations |
List[Union[str, Operation]]
|
List of operations |
required |
Source code in recon/dataset.py
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 |
|
rollback(n=1)
¶
Rollback the last n operations on a dataset.
e.g. ``` ds = Dataset("name", data)
initial_ds_hash = hash(ds)
ds.apply_("some_operation")
ds.rollback()
hash(ds) == initial_ds_hash
>>> True # This should be True
Args: n (int): Number of operations to rollback
Source code in recon/dataset.py
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 |
|
search(search_query, case_sensitive=True)
¶
Naive search method to quickly identify examples matching the provided substring
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_query |
str
|
Substring to search each example for |
required |
case_sensitive |
bool
|
Consider case of search query and example text |
True
|
Returns:
Type | Description |
---|---|
List[Example]
|
List[Example]: Matched examples |
Source code in recon/dataset.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
set_example_store(example_store)
¶
Overwrite the the internal ExampleStore. You probably don't want to call this. Used by the Corpus to ensure the ExampleStore of each dataset is complete.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
example_store |
ExampleStore
|
ExampleStore to overwrite with |
required |
Source code in recon/dataset.py
313 314 315 316 317 318 319 320 321 |
|
to_disk(output_dir, overwrite=False, save_examples=True)
¶
Save Corpus to Disk
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir |
Path
|
Output file path to save data to |
required |
overwrite |
bool
|
Force save to directory. Create parent directories or overwrite existing data. |
False
|
save_examples |
bool
|
Save the example store along with the state. |
True
|
Source code in recon/dataset.py
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 |
|
to_prodigy(prodigy_dataset=None, overwrite=True)
¶
Save examples to prodigy dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prodigy_dataset |
str
|
Prodigy dataset name to save to. |
None
|
overwrite |
bool
|
Overwrite dataset name if it exists. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Prodigy dataset name |
Source code in recon/dataset.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
to_spacy(output_dir)
¶
Save data to .spacy file
Saves file as {output_dir}/{self.name}.spacy
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir |
Path
|
Output file path to save data to |
required |
Source code in recon/dataset.py
483 484 485 486 487 488 489 490 491 492 |
|