Creates a ReadInstruction instance out of a string spec. Args: spec (str): split(s) + optional slice(s) to read. A slice can be specified, using absolute numbers (int) or percentages (int). E.g. `test`: test split. `test + validation`: test split + validation split.
(cls, spec: SplitArg)
| 612 | |
| 613 | @classmethod |
| 614 | def from_spec(cls, spec: SplitArg) -> AbstractSplit: |
| 615 | """Creates a ReadInstruction instance out of a string spec. |
| 616 | |
| 617 | Args: |
| 618 | spec (str): split(s) + optional slice(s) to read. A slice can be |
| 619 | specified, using absolute numbers (int) or percentages (int). E.g. |
| 620 | `test`: test split. `test + validation`: test split + validation split. |
| 621 | `test[10:]`: test split, minus its first 10 records. `test[:10%]`: first |
| 622 | 10% records of test split. `test[:-5%]+train[40%:60%]`: first 95% of |
| 623 | test + middle 20% of train. |
| 624 | |
| 625 | Returns: |
| 626 | The split instance. |
| 627 | """ |
| 628 | if isinstance(spec, AbstractSplit): |
| 629 | return spec |
| 630 | |
| 631 | spec = str(spec) # Need to convert to str in case of `Split` instance. |
| 632 | |
| 633 | subs = _ADDITION_SEP_RE.split(spec) |
| 634 | if not subs: |
| 635 | raise ValueError(f'No instructions could be built out of {spec!r}') |
| 636 | with utils.try_reraise( |
| 637 | f'Error parsing split {spec!r}. See format at: ' |
| 638 | 'https://www.tensorflow.org/datasets/splits\n' |
| 639 | ): |
| 640 | instructions = [_str_to_relative_instruction(s) for s in subs] |
| 641 | # Merge all splits together (_SplitAll) |
| 642 | return functools.reduce(operator.add, instructions) |
| 643 | |
| 644 | @abc.abstractmethod |
| 645 | def to_absolute(self, split_infos) -> list[_AbsoluteInstruction]: |