Download dataset.py from ArpeciousAI/FlowRes-1: direct link, hf CLI and curl.
- Browser
- Download file 422 Bytes
-
https://huggingface.co/ArpeciousAI/FlowRes-1/resolve/main/dataset.py
- Command line
-
hf download hf://ArpeciousAI/FlowRes-1/dataset.py
-
curl -L -o dataset.py https://huggingface.co/ArpeciousAI/FlowRes-1/resolve/main/dataset.py
422 Bytes
| import torch | |
| from torch.utils.data import Dataset | |
| class TextDataset(Dataset): | |
| def __init__(self, tokens, block_size): | |
| self.tokens = tokens | |
| self.block_size = block_size | |
| def __len__(self): | |
| return len(self.tokens) - self.block_size - 1 | |
| def __getitem__(self, idx): | |
| x = self.tokens[idx:idx+self.block_size] | |
| y = self.tokens[idx+1:idx+self.block_size+1] | |
| return x, y | |