Download generator_utils.py from unitxt/data: direct link, hf CLI and curl.
- Browser
- Download file 677 Bytes
-
https://huggingface.co/datasets/unitxt/data/resolve/main/generator_utils.py
- Command line
-
hf download hf://datasets/unitxt/data/generator_utils.py
-
curl -L -o generator_utils.py https://huggingface.co/datasets/unitxt/data/resolve/main/generator_utils.py
677 Bytes
| from typing import Any, Dict, List | |
| from .dataclass import Dataclass, OptionalField | |
| from .utils import recursive_copy | |
| class ReusableGenerator(Dataclass): | |
| generator: callable | |
| gen_argv: List[Any] = OptionalField(default_factory=list) | |
| gen_kwargs: Dict[str, Any] = OptionalField(default_factory=dict) | |
| def activate(self): | |
| return self.generator(*self.gen_argv, **self.gen_kwargs) | |
| def __iter__(self): | |
| yield from self.activate() | |
| def __call__(self): | |
| yield from iter(self) | |
| class CopyingReusableGenerator(ReusableGenerator): | |
| def __iter__(self): | |
| for instance in self.activate(): | |
| yield recursive_copy(instance) | |