Download mla/data.py from karthik-2905/model-a-scratch: direct link, hf CLI and curl.
- Browser
- Download file 522 Bytes
-
https://huggingface.co/karthik-2905/model-a-scratch/resolve/main/mla/data.py
- Command line
-
hf download hf://karthik-2905/model-a-scratch/mla/data.py
-
curl -L -o data.py https://huggingface.co/karthik-2905/model-a-scratch/resolve/main/mla/data.py
522 Bytes
| import numpy as np | |
| def load_ids(path): | |
| return np.load(path) | |
| def get_batch(ids, block_size, batch_size, rng): | |
| hi = len(ids) - block_size - 1 | |
| ix = rng.integers(0, hi, size=batch_size) | |
| x = np.stack([ids[i : i + block_size] for i in ix]).astype(np.int64) | |
| y = np.stack([ids[i + 1 : i + 1 + block_size] for i in ix]).astype(np.int64) | |
| return x, y | |
| def iter_batches(ids, block_size, batch_size, rng, n_batches): | |
| for _ in range(n_batches): | |
| yield get_batch(ids, block_size, batch_size, rng) | |