Download tokenizer/dataset_loader.py from Pulsar-Dynamic-Technologies/Adria: direct link, hf CLI and curl.
- Browser
- Download file 449 Bytes
-
https://huggingface.co/Pulsar-Dynamic-Technologies/Adria/resolve/main/tokenizer/dataset_loader.py
- Command line
-
hf download hf://Pulsar-Dynamic-Technologies/Adria/tokenizer/dataset_loader.py
-
curl -L -o dataset_loader.py https://huggingface.co/Pulsar-Dynamic-Technologies/Adria/resolve/main/tokenizer/dataset_loader.py
449 Bytes
| from typing import Iterable | |
| from datasets import load_dataset | |
| class DatasetLoader(Iterable[str]): | |
| def __init__(self, dataset_name, split="train", text_field="text"): | |
| self.dataset = load_dataset(dataset_name, split=split, streaming=True) | |
| self.text_field = text_field | |
| def __iter__(self): | |
| for sample in self.dataset: | |
| text = sample.get(self.text_field, '') | |
| if text: | |
| yield text | |